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/browser/metrics/variations/variations_service.h" | 5 #include "chrome/browser/metrics/variations/variations_service.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/build_time.h" | 9 #include "base/build_time.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "base/timer/elapsed_timer.h" | 16 #include "base/timer/elapsed_timer.h" |
17 #include "base/version.h" | 17 #include "base/version.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/metrics/metrics_state_manager.h" | 19 #include "chrome/browser/metrics/metrics_state_manager.h" |
20 #include "chrome/browser/metrics/variations/generated_resources_map.h" | |
20 #include "chrome/browser/network_time/network_time_tracker.h" | 21 #include "chrome/browser/network_time/network_time_tracker.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "components/pref_registry/pref_registry_syncable.h" | 24 #include "components/pref_registry/pref_registry_syncable.h" |
24 #include "components/variations/proto/variations_seed.pb.h" | 25 #include "components/variations/proto/variations_seed.pb.h" |
25 #include "components/variations/variations_seed_processor.h" | 26 #include "components/variations/variations_seed_processor.h" |
26 #include "components/variations/variations_seed_simulator.h" | 27 #include "components/variations/variations_seed_simulator.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
29 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
30 #include "net/base/network_change_notifier.h" | 31 #include "net/base/network_change_notifier.h" |
31 #include "net/base/url_util.h" | 32 #include "net/base/url_util.h" |
32 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
33 #include "net/http/http_status_code.h" | 34 #include "net/http/http_status_code.h" |
34 #include "net/http/http_util.h" | 35 #include "net/http/http_util.h" |
35 #include "net/url_request/url_fetcher.h" | 36 #include "net/url_request/url_fetcher.h" |
36 #include "net/url_request/url_request_status.h" | 37 #include "net/url_request/url_request_status.h" |
37 #include "ui/base/device_form_factor.h" | 38 #include "ui/base/device_form_factor.h" |
39 #include "ui/base/resource/resource_bundle.h" | |
38 #include "url/gurl.h" | 40 #include "url/gurl.h" |
39 | 41 |
40 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
41 #include "chrome/browser/chromeos/settings/cros_settings.h" | 43 #include "chrome/browser/chromeos/settings/cros_settings.h" |
42 #endif | 44 #endif |
43 | 45 |
44 namespace chrome_variations { | 46 namespace chrome_variations { |
45 | 47 |
46 namespace { | 48 namespace { |
47 | 49 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 const base::Time seed_date = base::Time::FromInternalValue(date_value); | 193 const base::Time seed_date = base::Time::FromInternalValue(date_value); |
192 const base::Time build_time = base::GetBuildTime(); | 194 const base::Time build_time = base::GetBuildTime(); |
193 // Use the build time for date checks if either the seed date is invalid or | 195 // Use the build time for date checks if either the seed date is invalid or |
194 // the build time is newer than the seed date. | 196 // the build time is newer than the seed date. |
195 base::Time reference_date = seed_date; | 197 base::Time reference_date = seed_date; |
196 if (seed_date.is_null() || seed_date < build_time) | 198 if (seed_date.is_null() || seed_date < build_time) |
197 reference_date = build_time; | 199 reference_date = build_time; |
198 return reference_date; | 200 return reference_date; |
199 } | 201 } |
200 | 202 |
203 // Overrides the string resource sepecified by |hash| with |string| in the | |
204 // resource bundle. Used as a callback passed to the variations seed processor. | |
205 void OverrideUIString(uint32_t hash, const base::string16& string) { | |
206 int index = GetResourceIndex(hash); | |
Alexei Svitkine (slow)
2014/07/15 16:44:52
Nit: It might be clearer to use |resource_id| term
jwd
2014/07/16 21:33:05
Done.
| |
207 if (index == -1) | |
208 return; | |
209 | |
210 ui::ResourceBundle::GetSharedInstance().OverrideStringResource(index, string); | |
Alexei Svitkine (slow)
2014/07/15 16:44:52
Has the method been renamed to OverrideLocaleStrin
jwd
2014/07/16 21:33:05
Yup, rebased now.
| |
211 } | |
212 | |
201 } // namespace | 213 } // namespace |
202 | 214 |
203 VariationsService::VariationsService( | 215 VariationsService::VariationsService( |
204 PrefService* local_state, | 216 PrefService* local_state, |
205 metrics::MetricsStateManager* state_manager) | 217 metrics::MetricsStateManager* state_manager) |
206 : local_state_(local_state), | 218 : local_state_(local_state), |
207 state_manager_(state_manager), | 219 state_manager_(state_manager), |
208 policy_pref_service_(local_state), | 220 policy_pref_service_(local_state), |
209 seed_store_(local_state), | 221 seed_store_(local_state), |
210 create_trials_from_seed_called_(false), | 222 create_trials_from_seed_called_(false), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 if (!current_version_info.is_valid()) | 254 if (!current_version_info.is_valid()) |
243 return false; | 255 return false; |
244 | 256 |
245 const base::Version current_version(current_version_info.Version()); | 257 const base::Version current_version(current_version_info.Version()); |
246 if (!current_version.IsValid()) | 258 if (!current_version.IsValid()) |
247 return false; | 259 return false; |
248 | 260 |
249 VariationsSeedProcessor().CreateTrialsFromSeed( | 261 VariationsSeedProcessor().CreateTrialsFromSeed( |
250 seed, g_browser_process->GetApplicationLocale(), | 262 seed, g_browser_process->GetApplicationLocale(), |
251 GetReferenceDateForExpiryChecks(local_state_), current_version, | 263 GetReferenceDateForExpiryChecks(local_state_), current_version, |
252 GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass()); | 264 GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass(), |
265 base::Bind(&OverrideUIString)); | |
253 | 266 |
254 // Log the "freshness" of the seed that was just used. The freshness is the | 267 // Log the "freshness" of the seed that was just used. The freshness is the |
255 // time between the last successful seed download and now. | 268 // time between the last successful seed download and now. |
256 const int64 last_fetch_time_internal = | 269 const int64 last_fetch_time_internal = |
257 local_state_->GetInt64(prefs::kVariationsLastFetchTime); | 270 local_state_->GetInt64(prefs::kVariationsLastFetchTime); |
258 if (last_fetch_time_internal) { | 271 if (last_fetch_time_internal) { |
259 const base::Time now = base::Time::Now(); | 272 const base::Time now = base::Time::Now(); |
260 const base::TimeDelta delta = | 273 const base::TimeDelta delta = |
261 now - base::Time::FromInternalValue(last_fetch_time_internal); | 274 now - base::Time::FromInternalValue(last_fetch_time_internal); |
262 // Log the value in number of minutes. | 275 // Log the value in number of minutes. |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 | 560 |
548 void VariationsService::RecordLastFetchTime() { | 561 void VariationsService::RecordLastFetchTime() { |
549 // local_state_ is NULL in tests, so check it first. | 562 // local_state_ is NULL in tests, so check it first. |
550 if (local_state_) { | 563 if (local_state_) { |
551 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 564 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
552 base::Time::Now().ToInternalValue()); | 565 base::Time::Now().ToInternalValue()); |
553 } | 566 } |
554 } | 567 } |
555 | 568 |
556 } // namespace chrome_variations | 569 } // namespace chrome_variations |
OLD | NEW |