Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_http_header_provider.h" | 5 #include "components/variations/variations_http_header_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "components/variations/entropy_provider.h" | 13 #include "components/variations/entropy_provider.h" |
| 14 #include "components/variations/proto/chrome_experiments.pb.h" | 14 #include "components/variations/proto/client_experiments.pb.h" |
| 15 #include "components/variations/variations_associated_data.h" | 15 #include "components/variations/variations_associated_data.h" |
| 16 #include "net/http/http_request_headers.h" | 16 #include "net/http/http_request_headers.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 // TODO(mathp): Remove once everything is under namespace 'variations'. | 20 // TODO(mathp): Remove once everything is under namespace 'variations'. |
| 21 using chrome_variations::GOOGLE_WEB_PROPERTIES; | 21 using chrome_variations::GOOGLE_WEB_PROPERTIES; |
| 22 using chrome_variations::GOOGLE_WEB_PROPERTIES_TRIGGER; | 22 using chrome_variations::GOOGLE_WEB_PROPERTIES_TRIGGER; |
| 23 using chrome_variations::IDCollectionKey; | 23 using chrome_variations::IDCollectionKey; |
| 24 using chrome_variations::VariationID; | 24 using chrome_variations::VariationID; |
| 25 | 25 |
| 26 namespace variations { | 26 namespace variations { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Decodes the variations header and extracts the variation ids. | 30 // Decodes the variations header and extracts the variation ids. |
| 31 bool ExtractVariationIds(const std::string& variations, | 31 bool ExtractVariationIds(const std::string& variations, |
| 32 std::set<VariationID>* variation_ids, | 32 std::set<VariationID>* variation_ids, |
| 33 std::set<VariationID>* trigger_ids) { | 33 std::set<VariationID>* trigger_ids) { |
| 34 std::string serialized_proto; | 34 std::string serialized_proto; |
| 35 if (!base::Base64Decode(variations, &serialized_proto)) return false; | 35 if (!base::Base64Decode(variations, &serialized_proto)) return false; |
| 36 metrics::ChromeVariations proto; | 36 metrics::ClientVariations proto; |
|
Alexei Svitkine (slow)
2014/07/14 16:38:01
Can the proto be moved to variations namespace?
Mathieu
2014/07/14 19:39:55
Done.
| |
| 37 if (!proto.ParseFromString(serialized_proto)) return false; | 37 if (!proto.ParseFromString(serialized_proto)) return false; |
| 38 for (int i = 0; i < proto.variation_id_size(); ++i) | 38 for (int i = 0; i < proto.variation_id_size(); ++i) |
| 39 variation_ids->insert(proto.variation_id(i)); | 39 variation_ids->insert(proto.variation_id(i)); |
| 40 for (int i = 0; i < proto.trigger_variation_id_size(); ++i) | 40 for (int i = 0; i < proto.trigger_variation_id_size(); ++i) |
| 41 trigger_ids->insert(proto.trigger_variation_id(i)); | 41 trigger_ids->insert(proto.trigger_variation_id(i)); |
| 42 return true; | 42 return true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 scoped_refptr<base::FieldTrial> CreateTrialAndAssociateId( | 45 scoped_refptr<base::FieldTrial> CreateTrialAndAssociateId( |
| 46 const std::string& trial_name, const std::string& default_group_name, | 46 const std::string& trial_name, const std::string& default_group_name, |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 headers.GetHeader("X-Client-Data", &variations); | 236 headers.GetHeader("X-Client-Data", &variations); |
| 237 | 237 |
| 238 std::set<VariationID> variation_ids; | 238 std::set<VariationID> variation_ids; |
| 239 std::set<VariationID> trigger_ids; | 239 std::set<VariationID> trigger_ids; |
| 240 ASSERT_TRUE(ExtractVariationIds(variations, &variation_ids, &trigger_ids)); | 240 ASSERT_TRUE(ExtractVariationIds(variations, &variation_ids, &trigger_ids)); |
| 241 EXPECT_TRUE(variation_ids.find(123) != variation_ids.end()); | 241 EXPECT_TRUE(variation_ids.find(123) != variation_ids.end()); |
| 242 EXPECT_TRUE(trigger_ids.find(456) != trigger_ids.end()); | 242 EXPECT_TRUE(trigger_ids.find(456) != trigger_ids.end()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 } // namespace variations | 245 } // namespace variations |
| OLD | NEW |