| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/metrics/experiments_helper.h" | 5 #include "chrome/common/metrics/experiments_helper.h" |
| 6 | 6 |
| 7 #include <map> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 10 #include "base/sha1.h" | 11 #include "base/sha1.h" |
| 11 #include "base/string16.h" | 12 #include "base/string16.h" |
| 12 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 13 #include "base/sys_byteorder.h" | 14 #include "base/sys_byteorder.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/common/child_process_logging.h" | 16 #include "chrome/common/child_process_logging.h" |
| 16 #include "chrome/common/metrics/variation_ids.h" | 17 #include "chrome/common/metrics/variation_ids.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 GroupMapAccessor::GetInstance()->AssociateID( | 124 GroupMapAccessor::GetInstance()->AssociateID( |
| 124 MakeSelectedGroupId(trial_name, group_name), id, true); | 125 MakeSelectedGroupId(trial_name, group_name), id, true); |
| 125 } | 126 } |
| 126 | 127 |
| 127 chrome_variations::ID GetGoogleVariationID(const std::string& trial_name, | 128 chrome_variations::ID GetGoogleVariationID(const std::string& trial_name, |
| 128 const std::string& group_name) { | 129 const std::string& group_name) { |
| 129 return GroupMapAccessor::GetInstance()->GetID( | 130 return GroupMapAccessor::GetInstance()->GetID( |
| 130 MakeSelectedGroupId(trial_name, group_name)); | 131 MakeSelectedGroupId(trial_name, group_name)); |
| 131 } | 132 } |
| 132 | 133 |
| 134 void GenerateExperimentChunks(const std::vector<string16>& experiments, |
| 135 std::vector<string16>* chunks) { |
| 136 string16 current_chunk; |
| 137 for (size_t i = 0; i < experiments.size(); ++i) { |
| 138 const size_t needed_length = |
| 139 (current_chunk.empty() ? 1 : 0) + experiments[i].length(); |
| 140 if (current_chunk.length() + needed_length > kMaxExperimentChunkSize) { |
| 141 chunks->push_back(current_chunk); |
| 142 current_chunk = experiments[i]; |
| 143 } else { |
| 144 if (!current_chunk.empty()) |
| 145 current_chunk.push_back(','); |
| 146 current_chunk += experiments[i]; |
| 147 } |
| 148 } |
| 149 if (!current_chunk.empty()) |
| 150 chunks->push_back(current_chunk); |
| 151 } |
| 152 |
| 133 void SetChildProcessLoggingExperimentList() { | 153 void SetChildProcessLoggingExperimentList() { |
| 134 std::vector<SelectedGroupId> name_group_ids; | 154 std::vector<SelectedGroupId> name_group_ids; |
| 135 GetFieldTrialSelectedGroupIds(&name_group_ids); | 155 GetFieldTrialSelectedGroupIds(&name_group_ids); |
| 136 std::vector<string16> experiment_strings(name_group_ids.size()); | 156 std::vector<string16> experiment_strings(name_group_ids.size()); |
| 137 for (size_t i = 0; i < name_group_ids.size(); ++i) { | 157 for (size_t i = 0; i < name_group_ids.size(); ++i) { |
| 138 // Wish there was a StringPrintf for string16... :-( | 158 // Wish there was a StringPrintf for string16... :-( |
| 139 experiment_strings[i] = WideToUTF16(base::StringPrintf( | 159 experiment_strings[i] = WideToUTF16(base::StringPrintf( |
| 140 L"%x-%x", name_group_ids[i].name, name_group_ids[i].group)); | 160 L"%x-%x", name_group_ids[i].name, name_group_ids[i].group)); |
| 141 } | 161 } |
| 142 child_process_logging::SetExperimentList(experiment_strings); | 162 child_process_logging::SetExperimentList(experiment_strings); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 153 std::vector<experiments_helper::SelectedGroupId>* name_group_ids) { | 173 std::vector<experiments_helper::SelectedGroupId>* name_group_ids) { |
| 154 ::GetFieldTrialSelectedGroupIdsForSelectedGroups(selected_groups, | 174 ::GetFieldTrialSelectedGroupIdsForSelectedGroups(selected_groups, |
| 155 name_group_ids); | 175 name_group_ids); |
| 156 } | 176 } |
| 157 | 177 |
| 158 uint32 TestHashName(const std::string& name) { | 178 uint32 TestHashName(const std::string& name) { |
| 159 return ::HashName(name); | 179 return ::HashName(name); |
| 160 } | 180 } |
| 161 | 181 |
| 162 } // namespace testing | 182 } // namespace testing |
| OLD | NEW |