| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 { | 49 { |
| 50 base::AutoLock scoped_lock(lock_); | 50 base::AutoLock scoped_lock(lock_); |
| 51 for (VariationID id : GetAllVariationIds()) { | 51 for (VariationID id : GetAllVariationIds()) { |
| 52 ids_string.append(base::IntToString(id)); | 52 ids_string.append(base::IntToString(id)); |
| 53 ids_string.push_back(' '); | 53 ids_string.push_back(' '); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 return ids_string; | 56 return ids_string; |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool VariationsHttpHeaderProvider::ForceVariationIds( |
| 60 const std::string& command_line_variation_ids, |
| 61 std::vector<std::string>* variation_ids) { |
| 62 if (!command_line_variation_ids.empty()) { |
| 63 // Combine |variation_ids| with |command_line_variation_ids|. |
| 64 std::vector<std::string> variation_ids_flags = |
| 65 base::SplitString(command_line_variation_ids, ",", |
| 66 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 67 variation_ids->insert(variation_ids->end(), variation_ids_flags.begin(), |
| 68 variation_ids_flags.end()); |
| 69 } |
| 70 |
| 71 if (!variation_ids->empty()) { |
| 72 // Create default variation ids which will always be included in the |
| 73 // X-Client-Data request header. |
| 74 return SetDefaultVariationIds(*variation_ids); |
| 75 } |
| 76 return true; |
| 77 } |
| 78 |
| 79 |
| 59 bool VariationsHttpHeaderProvider::SetDefaultVariationIds( | 80 bool VariationsHttpHeaderProvider::SetDefaultVariationIds( |
| 60 const std::string& variation_ids) { | 81 const std::vector<std::string>& variation_ids) { |
| 61 default_variation_ids_set_.clear(); | 82 default_variation_ids_set_.clear(); |
| 62 default_trigger_id_set_.clear(); | 83 default_trigger_id_set_.clear(); |
| 63 for (const base::StringPiece& entry : base::SplitStringPiece( | 84 for (const std::string& entry : variation_ids) { |
| 64 variation_ids, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | |
| 65 if (entry.empty()) { | 85 if (entry.empty()) { |
| 66 default_variation_ids_set_.clear(); | 86 default_variation_ids_set_.clear(); |
| 67 default_trigger_id_set_.clear(); | 87 default_trigger_id_set_.clear(); |
| 68 return false; | 88 return false; |
| 69 } | 89 } |
| 70 bool trigger_id = | 90 bool trigger_id = |
| 71 base::StartsWith(entry, "t", base::CompareCase::SENSITIVE); | 91 base::StartsWith(entry, "t", base::CompareCase::SENSITIVE); |
| 72 // Remove the "t" prefix if it's there. | 92 // Remove the "t" prefix if it's there. |
| 73 base::StringPiece trimmed_entry = trigger_id ? entry.substr(1) : entry; | 93 std::string trimmed_entry = trigger_id ? entry.substr(1) : entry; |
| 74 | 94 |
| 75 int variation_id = 0; | 95 int variation_id = 0; |
| 76 if (!base::StringToInt(trimmed_entry, &variation_id)) { | 96 if (!base::StringToInt(trimmed_entry, &variation_id)) { |
| 77 default_variation_ids_set_.clear(); | 97 default_variation_ids_set_.clear(); |
| 78 default_trigger_id_set_.clear(); | 98 default_trigger_id_set_.clear(); |
| 79 return false; | 99 return false; |
| 80 } | 100 } |
| 81 if (trigger_id) | 101 if (trigger_id) |
| 82 default_trigger_id_set_.insert(variation_id); | 102 default_trigger_id_set_.insert(variation_id); |
| 83 else | 103 else |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 244 |
| 225 std::set<VariationID> all_variation_ids_set = default_variation_ids_set_; | 245 std::set<VariationID> all_variation_ids_set = default_variation_ids_set_; |
| 226 for (VariationID id : variation_ids_set_) | 246 for (VariationID id : variation_ids_set_) |
| 227 all_variation_ids_set.insert(id); | 247 all_variation_ids_set.insert(id); |
| 228 for (VariationID id : synthetic_variation_ids_set_) | 248 for (VariationID id : synthetic_variation_ids_set_) |
| 229 all_variation_ids_set.insert(id); | 249 all_variation_ids_set.insert(id); |
| 230 return all_variation_ids_set; | 250 return all_variation_ids_set; |
| 231 } | 251 } |
| 232 | 252 |
| 233 } // namespace variations | 253 } // namespace variations |
| OLD | NEW |