diff --git a/chrome/app/breakpad_field_trial_win.cc b/chrome/app/breakpad_field_trial_win.cc deleted file mode 100644 index 5293879afed752..00000000000000 --- a/chrome/app/breakpad_field_trial_win.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/app/breakpad_field_trial_win.h" - -#include "base/lazy_instance.h" -#include "base/strings/string16.h" -#include "base/strings/string_util.h" -#include "base/strings/stringprintf.h" -#include "breakpad/src/client/windows/common/ipc_protocol.h" -#include "chrome/app/breakpad_win.h" -#include "chrome/common/child_process_logging.h" - -// Sets the breakpad experiment chunks for crash reporting. |chunks| is an -// array of C strings of size |chunk_size| containing the values to set, where -// each entry may contain multiple experiment tuples, with the total number of -// experiments indicated by |experiments_chunks|. -// Note that this is suffixed with "3" due to parameter changes that were made -// to the predecessor functions. If the signature changes again, use a new name. -extern "C" void __declspec(dllexport) __cdecl SetExperimentList3( - const wchar_t** chunks, - size_t chunks_size, - size_t experiments_count) { - // Make sure the offset was initialized before storing the data. - if (breakpad_win::g_experiment_chunks_offset == 0) - return; - - // Store up to |kMaxReportedVariationChunks| chunks. - const size_t number_of_chunks_to_report = - std::min(chunks_size, kMaxReportedVariationChunks); - for (size_t i = 0; i < number_of_chunks_to_report; ++i) { - const size_t entry_index = breakpad_win::g_experiment_chunks_offset + i; - (*breakpad_win::g_custom_entries)[entry_index].set_value(chunks[i]); - } - - // Make note of the total number of experiments, which may be greater than - // what was able to fit in |kMaxReportedVariationChunks|. This is useful when - // correlating stability with the number of experiments running - // simultaneously. - base::wcslcpy( - (*breakpad_win::g_custom_entries)[ - breakpad_win::g_num_of_experiments_offset].value, - base::StringPrintf( - L"%d", static_cast(experiments_count)).c_str(), - google_breakpad::CustomInfoEntry::kValueMaxLength); -} - -namespace testing { - -void SetExperimentChunks(const std::vector& chunks, - size_t experiments_count) { - std::vector cstrings; - StringVectorToCStringVector(chunks, &cstrings); - ::SetExperimentList3(&cstrings[0], cstrings.size(), experiments_count); -} - -} // namespace testing diff --git a/chrome/app/breakpad_field_trial_win.h b/chrome/app/breakpad_field_trial_win.h deleted file mode 100644 index e74ab86e429acc..00000000000000 --- a/chrome/app/breakpad_field_trial_win.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_APP_BREAKPAD_FIELD_TRIAL_WIN_H_ -#define CHROME_APP_BREAKPAD_FIELD_TRIAL_WIN_H_ - -#include - -#include "base/strings/string16.h" - -namespace testing { - -// Sets the breakpad experiment chunks for testing. |chunks| is the list of -// values to set, where each entry may contain multiple experiment tuples, with -// the total number of experiments indicated by |experiments_chunks|. -void SetExperimentChunks(const std::vector& chunks, - size_t experiments_count); - -} // namespace testing - -#endif // CHROME_APP_BREAKPAD_FIELD_TRIAL_WIN_H_ diff --git a/chrome/app/breakpad_linux.cc b/chrome/app/breakpad_linux.cc index 198b23748176e8..a4ebd28d78edb1 100644 --- a/chrome/app/breakpad_linux.cc +++ b/chrome/app/breakpad_linux.cc @@ -1264,26 +1264,6 @@ void HandleCrashDump(const BreakpadInfo& info) { writer.Flush(); } - if (*child_process_logging::g_num_variations) { - writer.AddPairString("num-experiments", - child_process_logging::g_num_variations); - writer.AddBoundary(); - writer.Flush(); - } - - unsigned variation_chunks_len = - my_strlen(child_process_logging::g_variation_chunks); - if (variation_chunks_len) { - static const char variation_msg[] = "experiment-chunk-"; - static const unsigned kMaxVariationsLen = - kMaxReportedVariationChunks * kMaxVariationChunkSize; - writer.AddPairDataInChunks(variation_msg, sizeof(variation_msg) - 1, - child_process_logging::g_variation_chunks, - std::min(variation_chunks_len, kMaxVariationsLen), - kMaxVariationChunkSize, - true /* Strip whitespace since variation chunks are padded. */); - } - if (info.oom_size) { char oom_size_str[kUint64StringSize]; const unsigned oom_size_len = my_uint64_len(info.oom_size); diff --git a/chrome/app/breakpad_unittest_win.cc b/chrome/app/breakpad_unittest_win.cc deleted file mode 100644 index 3dca06096bfb4e..00000000000000 --- a/chrome/app/breakpad_unittest_win.cc +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include - -#include "base/strings/stringprintf.h" -#include "breakpad/src/client/windows/common/ipc_protocol.h" -#include "chrome/app/breakpad_field_trial_win.h" -#include "chrome/app/breakpad_win.h" -#include "chrome/common/child_process_logging.h" -#include "chrome/common/metrics/variations/variations_util.h" -#include "testing/gtest/include/gtest/gtest.h" - -using breakpad_win::g_custom_entries; -using breakpad_win::g_experiment_chunks_offset; -using breakpad_win::g_num_of_experiments_offset; - -class ChromeAppBreakpadTest : public testing::Test { - public: - ChromeAppBreakpadTest() { - testing::InitCustomInfoEntries(); - } - - protected: - typedef std::vector Experiments; - void ValidateExperimentChunks(const Experiments& experiments) { - std::vector chunks; - chrome_variations::GenerateVariationChunks(experiments, &chunks); - testing::SetExperimentChunks(chunks, experiments.size()); - EXPECT_STREQ(base::StringPrintf(L"%d", experiments.size()).c_str(), - (*g_custom_entries)[g_num_of_experiments_offset].value); - // We make a copy of the array that we empty as we find the experiments. - Experiments experiments_left(experiments); - for (int i = 0; i < kMaxReportedVariationChunks; ++i) { - const google_breakpad::CustomInfoEntry& entry = - (*g_custom_entries)[g_experiment_chunks_offset + i]; - EXPECT_STREQ(base::StringPrintf(L"experiment-chunk-%i", i + 1).c_str(), - entry.name); - // An empty value should only appear when |experiments_left| is empty. - if (wcslen(entry.value) == 0) - EXPECT_TRUE(experiments_left.empty()); - if (experiments_left.empty()) { - // All other slots should be empty. - EXPECT_STREQ(L"", entry.value); - } else { - // We can't guarantee the order, so we must search for them all. - Experiments::const_iterator experiment = experiments_left.begin(); - while (experiment != experiments_left.end()) { - if (wcsstr(entry.value, experiment->c_str())) { - experiment = experiments_left.erase(experiment); - } else { - ++experiment; - } - } - } - } - EXPECT_TRUE(experiments_left.empty()); - } - - private: - static const wchar_t* kNumExperiments; - static const size_t kNumExperimentsSize; -}; - -const wchar_t* ChromeAppBreakpadTest::kNumExperiments = L"num-experiments"; -const size_t ChromeAppBreakpadTest::kNumExperimentsSize = - wcslen(ChromeAppBreakpadTest::kNumExperiments); - -TEST_F(ChromeAppBreakpadTest, ExperimentList) { - Experiments experiments; - experiments.push_back(L"ABCDE-12345"); - ValidateExperimentChunks(experiments); - - experiments.push_back(L"There-You Are"); - ValidateExperimentChunks(experiments); - - experiments.push_back(L"Peter-Sellers"); - ValidateExperimentChunks(experiments); - - experiments.push_back(L"Eat me-Drink me"); - ValidateExperimentChunks(experiments); -} diff --git a/chrome/app/breakpad_win.cc b/chrome/app/breakpad_win.cc index 80ccd0167e1e68..6f83defd7c386a 100644 --- a/chrome/app/breakpad_win.cc +++ b/chrome/app/breakpad_win.cc @@ -31,7 +31,6 @@ #include "base/win/registry.h" #include "base/win/win_util.h" #include "breakpad/src/client/windows/handler/exception_handler.h" -#include "chrome/app/breakpad_field_trial_win.h" #include "chrome/app/hard_error_handler_win.h" #include "chrome/common/child_process_logging.h" #include "chrome/common/chrome_constants.h" @@ -54,16 +53,12 @@ namespace breakpad_win { // is way too too fragile. See // https://code.google.com/p/chromium/issues/detail?id=137062. std::vector* g_custom_entries = NULL; -size_t g_num_of_experiments_offset = 0; -size_t g_experiment_chunks_offset = 0; bool g_deferred_crash_uploads = false; } // namespace breakpad_win using breakpad_win::g_custom_entries; using breakpad_win::g_deferred_crash_uploads; -using breakpad_win::g_experiment_chunks_offset; -using breakpad_win::g_num_of_experiments_offset; namespace { @@ -426,21 +421,6 @@ google_breakpad::CustomClientInfo* GetCustomInfo(const std::wstring& exe_path, if (use_crash_service) SetBreakpadDumpPath(); - g_num_of_experiments_offset = g_custom_entries->size(); - g_custom_entries->push_back( - google_breakpad::CustomInfoEntry(L"num-experiments", L"N/A")); - - g_experiment_chunks_offset = g_custom_entries->size(); - // We depend on this in UpdateExperiments... - DCHECK_NE(0UL, g_experiment_chunks_offset); - // And the test code depends on this. - DCHECK_EQ(g_num_of_experiments_offset + 1, g_experiment_chunks_offset); - // one-based index for the name suffix. - for (int i = 1; i <= kMaxReportedVariationChunks; ++i) { - g_custom_entries->push_back(google_breakpad::CustomInfoEntry( - base::StringPrintf(L"experiment-chunk-%i", i).c_str(), L"")); - } - // Create space for dynamic ad-hoc keys. The names and values are set using // the API defined in base/debug/crash_logging.h. g_dynamic_keys_offset = g_custom_entries->size(); @@ -925,11 +905,3 @@ void InitCrashReporter() { void InitDefaultCrashCallback(LPTOP_LEVEL_EXCEPTION_FILTER filter) { previous_filter = SetUnhandledExceptionFilter(filter); } - -void StringVectorToCStringVector(const std::vector& wstrings, - std::vector* cstrings) { - cstrings->clear(); - cstrings->reserve(wstrings.size()); - for (size_t i = 0; i < wstrings.size(); ++i) - cstrings->push_back(wstrings[i].c_str()); -} diff --git a/chrome/browser/ui/webui/version_handler.cc b/chrome/browser/ui/webui/version_handler.cc index 8c540371e532c3..638ff0b7cb3796 100644 --- a/chrome/browser/ui/webui/version_handler.cc +++ b/chrome/browser/ui/webui/version_handler.cc @@ -101,10 +101,7 @@ void VersionHandler::HandleRequestVersionInfo(const ListValue* args) { } #else // In release mode, display the hashes only. - std::vector active_groups; - chrome_variations::GetFieldTrialActiveGroupIdsAsStrings(&active_groups); - for (size_t i = 0; i < active_groups.size(); ++i) - variations.push_back(UTF16ToASCII(active_groups[i])); + chrome_variations::GetFieldTrialActiveGroupIdsAsStrings(&variations); #endif ListValue variations_list; diff --git a/chrome/chrome_exe.gypi b/chrome/chrome_exe.gypi index 67b0efa448bd3e..ae000d7dc7f159 100644 --- a/chrome/chrome_exe.gypi +++ b/chrome/chrome_exe.gypi @@ -13,8 +13,6 @@ 'enable_wexit_time_destructors': 1, }, 'sources': [ - 'app/breakpad_field_trial_win.cc', - 'app/breakpad_field_trial_win.h', 'app/breakpad_win.cc', 'app/breakpad_win.h', 'app/chrome_exe_main_aura.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 77c720ce760ef7..cb166211ba72a9 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -2715,9 +2715,7 @@ '..', ], 'sources': [ - 'app/breakpad_field_trial_win.cc', 'app/breakpad_win.cc', - 'app/breakpad_unittest_win.cc', 'app/delay_load_hook_win.cc', 'app/delay_load_hook_win.h', 'app/delay_load_hook_unittest_win.cc', diff --git a/chrome/common/child_process_logging.h b/chrome/common/child_process_logging.h index 6132061d27fc39..f437828e565d4a 100644 --- a/chrome/common/child_process_logging.h +++ b/chrome/common/child_process_logging.h @@ -5,23 +5,10 @@ #ifndef CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ #define CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ -#include #include -#include #include "base/basictypes.h" #include "base/debug/crash_logging.h" -#include "base/strings/string16.h" - -// The maximum number of variation chunks we will report. -// Also used in chrome/app, but we define it here to avoid a common->app -// dependency. -static const size_t kMaxReportedVariationChunks = 15; - -// The maximum size of a variation chunk. This size was picked to be -// consistent between platforms and the value was chosen from the Windows -// limit of google_breakpad::CustomInfoEntry::kValueMaxLength. -static const size_t kMaxVariationChunkSize = 64; namespace child_process_logging { @@ -29,8 +16,6 @@ namespace child_process_logging { // These are declared here so the crash reporter can access them directly in // compromised context without going through the standard library. extern char g_client_id[]; -extern char g_num_variations[]; -extern char g_variation_chunks[]; // Assume command line switches are less than 64 chars. static const size_t kSwitchLen = 64; @@ -43,18 +28,11 @@ void SetClientId(const std::string& client_id); // id in |client_id| if it's known, an empty string otherwise. std::string GetClientId(); -// Initialize the list of experiment info to send along with crash reports. -void SetExperimentList(const std::vector& state); - -} // namespace child_process_logging - #if defined(OS_WIN) -namespace child_process_logging { - // Sets up the base/debug/crash_logging.h mechanism. void Init(); +#endif // defined(OS_WIN) } // namespace child_process_logging -#endif // defined(OS_WIN) #endif // CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ diff --git a/chrome/common/child_process_logging_mac.mm b/chrome/common/child_process_logging_mac.mm index 572fd52c7e7e18..5747945a5944be 100644 --- a/chrome/common/child_process_logging_mac.mm +++ b/chrome/common/child_process_logging_mac.mm @@ -7,9 +7,7 @@ #import #include "base/strings/string_util.h" -#include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/common/metrics/variations/variations_util.h" #include "chrome/installer/util/google_update_settings.h" namespace child_process_logging { @@ -45,31 +43,4 @@ void SetClientId(const std::string& client_id) { return std::string(g_client_id); } -void SetExperimentList(const std::vector& experiments) { - // These should match the corresponding strings in breakpad_win.cc. - const char* kNumExperimentsKey = "num-experiments"; - const char* kExperimentChunkFormat = "experiment-chunk-%zu"; // 1-based - - std::vector chunks; - chrome_variations::GenerateVariationChunks(experiments, &chunks); - - // Store up to |kMaxReportedVariationChunks| chunks. - for (size_t i = 0; i < kMaxReportedVariationChunks; ++i) { - std::string key = base::StringPrintf(kExperimentChunkFormat, i + 1); - if (i < chunks.size()) { - std::string value = UTF16ToUTF8(chunks[i]); - SetCrashKeyValue(key, value); - } else { - ClearCrashKey(key); - } - } - - // Make note of the total number of experiments, which may be greater than - // what was able to fit in |kMaxReportedVariationChunks|. This is useful when - // correlating stability with the number of experiments running - // simultaneously. - SetCrashKeyValue(kNumExperimentsKey, - base::StringPrintf("%zu", experiments.size())); -} - } // namespace child_process_logging diff --git a/chrome/common/child_process_logging_posix.cc b/chrome/common/child_process_logging_posix.cc index 68f72d29e59fe7..0ff249a67f9fb8 100644 --- a/chrome/common/child_process_logging_posix.cc +++ b/chrome/common/child_process_logging_posix.cc @@ -4,12 +4,8 @@ #include "chrome/common/child_process_logging.h" -#include "base/format_macros.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/common/metrics/variations/variations_util.h" #include "chrome/installer/util/google_update_settings.h" namespace child_process_logging { @@ -22,13 +18,6 @@ static const size_t kClientIdSize = 32 + 1; // these strings to the browser. char g_client_id[kClientIdSize]; -static const size_t kNumSize = 32; -char g_num_variations[kNumSize] = ""; - -static const size_t kMaxVariationChunksSize = - kMaxVariationChunkSize * kMaxReportedVariationChunks + 1; -char g_variation_chunks[kMaxVariationChunksSize] = ""; - void SetClientId(const std::string& client_id) { std::string str(client_id); ReplaceSubstringsAfterOffset(&str, 0, "-", std::string()); @@ -45,28 +34,4 @@ std::string GetClientId() { return std::string(g_client_id); } -void SetExperimentList(const std::vector& experiments) { - std::vector chunks; - chrome_variations::GenerateVariationChunks(experiments, &chunks); - - // Store up to |kMaxReportedVariationChunks| chunks. - std::string chunks_str; - const size_t number_of_chunks_to_report = - std::min(chunks.size(), kMaxReportedVariationChunks); - for (size_t i = 0; i < number_of_chunks_to_report; ++i) { - chunks_str += UTF16ToUTF8(chunks[i]); - // Align short chunks with spaces to be trimmed later. - chunks_str.resize(i * kMaxVariationChunkSize, ' '); - } - base::strlcpy(g_variation_chunks, chunks_str.c_str(), - arraysize(g_variation_chunks)); - - // Make note of the total number of experiments, which may be greater than - // what was able to fit in |kMaxReportedVariationChunks|. This is useful when - // correlating stability with the number of experiments running - // simultaneously. - snprintf(g_num_variations, arraysize(g_num_variations), "%" PRIuS, - experiments.size()); -} - } // namespace child_process_logging diff --git a/chrome/common/child_process_logging_win.cc b/chrome/common/child_process_logging_win.cc index 659096cfd49873..11a293e72e6a39 100644 --- a/chrome/common/child_process_logging_win.cc +++ b/chrome/common/child_process_logging_win.cc @@ -6,12 +6,10 @@ #include -#include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/crash_keys.h" -#include "chrome/common/metrics/variations/variations_util.h" #include "chrome/installer/util/google_update_settings.h" namespace child_process_logging { @@ -21,10 +19,6 @@ namespace { // exported in breakpad_win.cc: void __declspec(dllexport) __cdecl SetClientId. typedef void (__cdecl *MainSetClientId)(const wchar_t*); -// exported in breakpad_field_trial_win.cc: -// void __declspec(dllexport) __cdecl SetExperimentList3 -typedef void (__cdecl *MainSetExperimentList)(const wchar_t**, size_t, size_t); - // exported in breakpad_win.cc: // void __declspec(dllexport) __cdecl SetCrashKeyValueImpl. typedef void (__cdecl *SetCrashKeyValue)(const wchar_t*, const wchar_t*); @@ -33,16 +27,6 @@ typedef void (__cdecl *SetCrashKeyValue)(const wchar_t*, const wchar_t*); // void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl. typedef void (__cdecl *ClearCrashKeyValue)(const wchar_t*); - -// Copied from breakpad_win.cc. -void StringVectorToCStringVector(const std::vector& wstrings, - std::vector* cstrings) { - cstrings->clear(); - cstrings->reserve(wstrings.size()); - for (size_t i = 0; i < wstrings.size(); ++i) - cstrings->push_back(wstrings[i].c_str()); -} - } // namespace void SetClientId(const std::string& client_id) { @@ -81,34 +65,6 @@ std::string GetClientId() { return std::string(); } -void SetExperimentList(const std::vector& experiments) { - static MainSetExperimentList set_experiment_list = NULL; - // note: benign race condition on set_experiment_list. - if (!set_experiment_list) { - HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName); - if (!exe_module) - return; - set_experiment_list = reinterpret_cast( - GetProcAddress(exe_module, "SetExperimentList3")); - if (!set_experiment_list) - return; - } - - std::vector chunks; - chrome_variations::GenerateVariationChunks(experiments, &chunks); - - // If the list is empty, notify the child process of the number of experiments - // and exit early. - if (chunks.empty()) { - (set_experiment_list)(NULL, 0, 0); - return; - } - - std::vector cstrings; - StringVectorToCStringVector(chunks, &cstrings); - (set_experiment_list)(&cstrings[0], cstrings.size(), experiments.size()); -} - namespace { void SetCrashKeyValueTrampoline(const base::StringPiece& key, diff --git a/chrome/common/crash_keys.cc b/chrome/common/crash_keys.cc index 583d5330f97bf9..65b1b901cecf39 100644 --- a/chrome/common/crash_keys.cc +++ b/chrome/common/crash_keys.cc @@ -58,6 +58,9 @@ const char kActiveURL[] = "url-chunk"; const char kSwitch[] = "switch-%" PRIuS; const char kNumSwitches[] = "num-switches"; +const char kNumVariations[] = "num-experiments"; +const char kVariations[] = "variations"; + const char kExtensionID[] = "extension-%" PRIuS; const char kNumExtensionsCount[] = "num-extensions"; @@ -108,6 +111,8 @@ size_t RegisterChromeCrashKeys() { { kChannel, kSmallSize }, { kActiveURL, kLargeSize }, { kNumSwitches, kSmallSize }, + { kNumVariations, kSmallSize }, + { kVariations, kLargeSize }, { kNumExtensionsCount, kSmallSize }, { kNumberOfViews, kSmallSize }, #if !defined(OS_ANDROID) @@ -270,6 +275,25 @@ void SetSwitchesFromCommandLine(const CommandLine* command_line) { } } +void SetVariationsList(const std::vector& variations) { + base::debug::SetCrashKeyValue(kNumVariations, + base::StringPrintf("%" PRIuS, variations.size())); + + std::string variations_string; + variations_string.reserve(kLargeSize); + + for (size_t i = 0; i < variations.size(); ++i) { + const std::string& variation = variations[i]; + // Do not truncate an individual experiment. + if (variations_string.size() + variation.size() >= kLargeSize) + break; + variations_string += variation; + variations_string += ","; + } + + base::debug::SetCrashKeyValue(kVariations, variations_string); +} + void SetActiveExtensions(const std::set& extensions) { base::debug::SetCrashKeyValue(kNumExtensionsCount, base::StringPrintf("%" PRIuS, extensions.size())); diff --git a/chrome/common/crash_keys.h b/chrome/common/crash_keys.h index 23fda46072149c..cc57868b4461d5 100644 --- a/chrome/common/crash_keys.h +++ b/chrome/common/crash_keys.h @@ -7,6 +7,7 @@ #include #include +#include #include "base/debug/crash_logging.h" @@ -21,6 +22,9 @@ size_t RegisterChromeCrashKeys(); // Sets the kSwitch and kNumSwitches keys based on the given |command_line|. void SetSwitchesFromCommandLine(const CommandLine* command_line); +// Sets the list of active experiment/variations info. +void SetVariationsList(const std::vector& variations); + // Sets the list of "active" extensions in this process. We overload "active" to // mean different things depending on the process type: // - browser: all enabled extensions @@ -56,6 +60,12 @@ extern const char kSwitch[]; // |kSwitchesMaxCount| are present. extern const char kNumSwitches[]; +// The total number of experiments the instance has. +extern const char kNumVariations[]; +// The experiments chunk. Hashed experiment names separated by |,|. This is +// typically set by SetExperimentList. +extern const char kVariations[]; + // Installed extensions. |kExtensionID| should be formatted with an integer, // in the range [0, kExtensionIDMaxCount). const size_t kExtensionIDMaxCount = 10; diff --git a/chrome/common/metrics/variations/variations_util.cc b/chrome/common/metrics/variations/variations_util.cc index 5ef0bf89d3ef83..0ae01e168ae6a3 100644 --- a/chrome/common/metrics/variations/variations_util.cc +++ b/chrome/common/metrics/variations/variations_util.cc @@ -13,6 +13,7 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "chrome/common/child_process_logging.h" +#include "chrome/common/crash_keys.h" #include "chrome/installer/util/google_update_experiment_util.h" namespace chrome_variations { @@ -68,39 +69,20 @@ void GetFieldTrialActiveGroupIds( } void GetFieldTrialActiveGroupIdsAsStrings( - std::vector* output) { + std::vector* output) { DCHECK(output->empty()); std::vector name_group_ids; GetFieldTrialActiveGroupIds(&name_group_ids); for (size_t i = 0; i < name_group_ids.size(); ++i) { - output->push_back(UTF8ToUTF16(base::StringPrintf( - "%x-%x", name_group_ids[i].name, name_group_ids[i].group))); + output->push_back(base::StringPrintf( + "%x-%x", name_group_ids[i].name, name_group_ids[i].group)); } } -void GenerateVariationChunks(const std::vector& experiments, - std::vector* chunks) { - string16 current_chunk; - for (size_t i = 0; i < experiments.size(); ++i) { - const size_t needed_length = - (current_chunk.empty() ? 1 : 0) + experiments[i].length(); - if (current_chunk.length() + needed_length > kMaxVariationChunkSize) { - chunks->push_back(current_chunk); - current_chunk = experiments[i]; - } else { - if (!current_chunk.empty()) - current_chunk.push_back(','); - current_chunk += experiments[i]; - } - } - if (!current_chunk.empty()) - chunks->push_back(current_chunk); -} - void SetChildProcessLoggingVariationList() { - std::vector experiment_strings; + std::vector experiment_strings; GetFieldTrialActiveGroupIdsAsStrings(&experiment_strings); - child_process_logging::SetExperimentList(experiment_strings); + crash_keys::SetVariationsList(experiment_strings); } string16 BuildGoogleUpdateExperimentLabel( diff --git a/chrome/common/metrics/variations/variations_util.h b/chrome/common/metrics/variations/variations_util.h index cd0c7874d838a5..d32cae7a823f0e 100644 --- a/chrome/common/metrics/variations/variations_util.h +++ b/chrome/common/metrics/variations/variations_util.h @@ -5,6 +5,7 @@ #ifndef CHROME_COMMON_METRICS_VARIATIONS_VARIATIONS_UTIL_H_ #define CHROME_COMMON_METRICS_VARIATIONS_VARIATIONS_UTIL_H_ +#include #include #include "base/metrics/field_trial.h" @@ -24,12 +25,7 @@ void GetFieldTrialActiveGroupIds(std::vector* name_group_ids); // has a chosen group. The strings are formatted as "-", // with the names as hex strings. Field Trials for which a group has not been // chosen yet are NOT returned in this list. -void GetFieldTrialActiveGroupIdsAsStrings(std::vector* output); - -// Generates variation chunks from |variation_strings| that are suitable for -// crash reporting. -void GenerateVariationChunks(const std::vector& variation_strings, - std::vector* chunks); +void GetFieldTrialActiveGroupIdsAsStrings(std::vector* output); // Get the current set of chosen FieldTrial groups (aka variations) and send // them to the child process logging module so it can save it for crash dumps. diff --git a/chrome/common/metrics/variations/variations_util_unittest.cc b/chrome/common/metrics/variations/variations_util_unittest.cc index 1f9e140851e397..e14d53a3252f69 100644 --- a/chrome/common/metrics/variations/variations_util_unittest.cc +++ b/chrome/common/metrics/variations/variations_util_unittest.cc @@ -104,60 +104,6 @@ TEST_F(VariationsUtilTest, GetFieldTrialActiveGroups) { EXPECT_EQ(0U, expected_groups.size()); } -TEST_F(VariationsUtilTest, GenerateExperimentChunks) { - const char* kExperimentStrings[] = { - "1d3048f1-9de009d0", - "cd73da34-cf196cb", - "6214fa18-9e6dc24d", - "4dcb0cd6-d31c4ca1", - "9d5bce6-30d7d8ac", - }; - const char* kExpectedChunks1[] = { - "1d3048f1-9de009d0", - }; - const char* kExpectedChunks2[] = { - "1d3048f1-9de009d0,cd73da34-cf196cb", - }; - const char* kExpectedChunks3[] = { - "1d3048f1-9de009d0,cd73da34-cf196cb,6214fa18-9e6dc24d", - }; - const char* kExpectedChunks4[] = { - "1d3048f1-9de009d0,cd73da34-cf196cb,6214fa18-9e6dc24d", - "4dcb0cd6-d31c4ca1", - }; - const char* kExpectedChunks5[] = { - "1d3048f1-9de009d0,cd73da34-cf196cb,6214fa18-9e6dc24d", - "4dcb0cd6-d31c4ca1,9d5bce6-30d7d8ac", - }; - - struct { - size_t strings_length; - size_t expected_chunks_length; - const char** expected_chunks; - } cases[] = { - { 0, 0, NULL }, - { 1, arraysize(kExpectedChunks1), kExpectedChunks1 }, - { 2, arraysize(kExpectedChunks2), kExpectedChunks2 }, - { 3, arraysize(kExpectedChunks3), kExpectedChunks3 }, - { 4, arraysize(kExpectedChunks4), kExpectedChunks4 }, - { 5, arraysize(kExpectedChunks5), kExpectedChunks5 }, - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { - ASSERT_LE(cases[i].strings_length, arraysize(kExperimentStrings)); - - std::vector experiments; - for (size_t j = 0; j < cases[i].strings_length; ++j) - experiments.push_back(UTF8ToUTF16(kExperimentStrings[j])); - - std::vector chunks; - GenerateVariationChunks(experiments, &chunks); - ASSERT_EQ(cases[i].expected_chunks_length, chunks.size()); - for (size_t j = 0; j < chunks.size(); ++j) - EXPECT_EQ(UTF8ToUTF16(cases[i].expected_chunks[j]), chunks[j]); - } -} - TEST_F(VariationsUtilTest, BuildGoogleUpdateExperimentLabel) { struct { const char* active_group_pairs;