OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/variations/variations_associated_data.h" | 5 #include "components/variations/variations_associated_data.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "components/variations/metrics_util.h" | |
13 | 12 |
14 namespace chrome_variations { | 13 namespace chrome_variations { |
15 | 14 |
| 15 // TODO(asvitkine): Delete these when this file moves to variations namespace. |
| 16 using variations::ActiveGroupId; |
| 17 using variations::ActiveGroupIdCompare; |
| 18 using variations::MakeActiveGroupId; |
| 19 |
16 namespace { | 20 namespace { |
17 | 21 |
18 // The internal singleton accessor for the map, used to keep it thread-safe. | 22 // The internal singleton accessor for the map, used to keep it thread-safe. |
19 class GroupMapAccessor { | 23 class GroupMapAccessor { |
20 public: | 24 public: |
21 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare> | 25 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare> |
22 GroupToIDMap; | 26 GroupToIDMap; |
23 | 27 |
24 // Retrieve the singleton. | 28 // Retrieve the singleton. |
25 static GroupMapAccessor* GetInstance() { | 29 static GroupMapAccessor* GetInstance() { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 170 } |
167 | 171 |
168 base::Lock lock_; | 172 base::Lock lock_; |
169 std::map<VariationKey, VariationParams> variation_params_; | 173 std::map<VariationKey, VariationParams> variation_params_; |
170 | 174 |
171 DISALLOW_COPY_AND_ASSIGN(VariationsParamAssociator); | 175 DISALLOW_COPY_AND_ASSIGN(VariationsParamAssociator); |
172 }; | 176 }; |
173 | 177 |
174 } // namespace | 178 } // namespace |
175 | 179 |
176 ActiveGroupId MakeActiveGroupId(const std::string& trial_name, | |
177 const std::string& group_name) { | |
178 ActiveGroupId id; | |
179 id.name = metrics::HashName(trial_name); | |
180 id.group = metrics::HashName(group_name); | |
181 return id; | |
182 } | |
183 | |
184 void AssociateGoogleVariationID(IDCollectionKey key, | 180 void AssociateGoogleVariationID(IDCollectionKey key, |
185 const std::string& trial_name, | 181 const std::string& trial_name, |
186 const std::string& group_name, | 182 const std::string& group_name, |
187 VariationID id) { | 183 VariationID id) { |
188 GroupMapAccessor::GetInstance()->AssociateID( | 184 GroupMapAccessor::GetInstance()->AssociateID( |
189 key, MakeActiveGroupId(trial_name, group_name), id, false); | 185 key, MakeActiveGroupId(trial_name, group_name), id, false); |
190 } | 186 } |
191 | 187 |
192 void AssociateGoogleVariationIDForce(IDCollectionKey key, | 188 void AssociateGoogleVariationIDForce(IDCollectionKey key, |
193 const std::string& trial_name, | 189 const std::string& trial_name, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); | 233 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); |
238 } | 234 } |
239 | 235 |
240 void ClearAllVariationParams() { | 236 void ClearAllVariationParams() { |
241 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); | 237 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); |
242 } | 238 } |
243 | 239 |
244 } // namespace testing | 240 } // namespace testing |
245 | 241 |
246 } // namespace chrome_variations | 242 } // namespace chrome_variations |
OLD | NEW |