| 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 "chrome/browser/predictors/resource_prefetch_common.h" | 5 #include "chrome/browser/predictors/resource_prefetch_common.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 const char kSpeculativePrefetchingTrialName[] = | 27 const char kSpeculativePrefetchingTrialName[] = |
| 28 "SpeculativeResourcePrefetching"; | 28 "SpeculativeResourcePrefetching"; |
| 29 | 29 |
| 30 /* | 30 /* |
| 31 * SpeculativeResourcePrefetching is a field trial, and its value must have the | 31 * SpeculativeResourcePrefetching is a field trial, and its value must have the |
| 32 * following format: key1=value1:key2=value2:key3=value3 | 32 * following format: key1=value1:key2=value2:key3=value3 |
| 33 * e.g. "Prefetching=Enabled:Predictor=Url:Confidence=High" | 33 * e.g. "Prefetching=Enabled:Predictor=Url:Confidence=High" |
| 34 * The function below extracts the value corresponding to a key provided from | 34 * The function below extracts the value corresponding to a key provided from |
| 35 * the SpeculativeResourcePrefetching field trial. | 35 * the SpeculativeResourcePrefetching field trial. |
| 36 */ | 36 */ |
| 37 string GetFiledTrialSpecValue(string key) { | 37 std::string GetFiledTrialSpecValue(string key) { |
| 38 vector<string> elements; | 38 std::string trial_name = |
| 39 base::SplitString( | 39 FieldTrialList::FindFullName(kSpeculativePrefetchingTrialName); |
| 40 FieldTrialList::FindFullName(kSpeculativePrefetchingTrialName), | 40 for (const base::StringPiece& element : base::SplitStringPiece( |
| 41 ':', | 41 trial_name, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 42 &elements); | 42 std::vector<base::StringPiece> key_value = base::SplitStringPiece( |
| 43 for (int i = 0; i < static_cast<int>(elements.size()); i++) { | 43 element, "=", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 44 vector<string> key_value; | |
| 45 base::SplitString(elements[i], '=', &key_value); | |
| 46 if (key_value.size() == 2 && key_value[0] == key) | 44 if (key_value.size() == 2 && key_value[0] == key) |
| 47 return key_value[1]; | 45 return key_value[1].as_string(); |
| 48 } | 46 } |
| 49 return string(); | 47 return string(); |
| 50 } | 48 } |
| 51 | 49 |
| 52 bool IsSpeculativeResourcePrefetchingEnabled( | 50 bool IsSpeculativeResourcePrefetchingEnabled( |
| 53 Profile* profile, | 51 Profile* profile, |
| 54 ResourcePrefetchPredictorConfig* config) { | 52 ResourcePrefetchPredictorConfig* config) { |
| 55 DCHECK(config); | 53 DCHECK(config); |
| 56 | 54 |
| 57 // Off the record - disabled. | 55 // Off the record - disabled. |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 260 |
| 263 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { | 261 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { |
| 264 return max_resources_per_entry == 100; | 262 return max_resources_per_entry == 100; |
| 265 } | 263 } |
| 266 | 264 |
| 267 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { | 265 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { |
| 268 return max_urls_to_track == 200 && max_hosts_to_track == 100; | 266 return max_urls_to_track == 200 && max_hosts_to_track == 100; |
| 269 } | 267 } |
| 270 | 268 |
| 271 } // namespace predictors | 269 } // namespace predictors |
| OLD | NEW |