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 void OverrideUIString(uint32_t hash, const base::string16& string) { | |
Alexei Svitkine (slow)
2014/07/03 17:54:40
Add a comment.
jwd
2014/07/07 15:52:20
Done.
| |
204 int index = GetResourceIndex(hash); | |
Alexei Svitkine (slow)
2014/07/03 17:54:40
Check for -1.
jwd
2014/07/07 15:52:20
Done.
| |
205 ui::ResourceBundle::GetSharedInstance().OverrideStringResource(index, string); | |
206 } | |
207 | |
201 } // namespace | 208 } // namespace |
202 | 209 |
203 VariationsService::VariationsService( | 210 VariationsService::VariationsService( |
204 PrefService* local_state, | 211 PrefService* local_state, |
205 metrics::MetricsStateManager* state_manager) | 212 metrics::MetricsStateManager* state_manager) |
206 : local_state_(local_state), | 213 : local_state_(local_state), |
207 state_manager_(state_manager), | 214 state_manager_(state_manager), |
208 policy_pref_service_(local_state), | 215 policy_pref_service_(local_state), |
209 seed_store_(local_state), | 216 seed_store_(local_state), |
210 create_trials_from_seed_called_(false), | 217 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()) | 249 if (!current_version_info.is_valid()) |
243 return false; | 250 return false; |
244 | 251 |
245 const base::Version current_version(current_version_info.Version()); | 252 const base::Version current_version(current_version_info.Version()); |
246 if (!current_version.IsValid()) | 253 if (!current_version.IsValid()) |
247 return false; | 254 return false; |
248 | 255 |
249 VariationsSeedProcessor().CreateTrialsFromSeed( | 256 VariationsSeedProcessor().CreateTrialsFromSeed( |
250 seed, g_browser_process->GetApplicationLocale(), | 257 seed, g_browser_process->GetApplicationLocale(), |
251 GetReferenceDateForExpiryChecks(local_state_), current_version, | 258 GetReferenceDateForExpiryChecks(local_state_), current_version, |
252 GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass()); | 259 GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass(), |
260 base::Bind(&OverrideUIString)); | |
253 | 261 |
254 // Log the "freshness" of the seed that was just used. The freshness is the | 262 // Log the "freshness" of the seed that was just used. The freshness is the |
255 // time between the last successful seed download and now. | 263 // time between the last successful seed download and now. |
256 const int64 last_fetch_time_internal = | 264 const int64 last_fetch_time_internal = |
257 local_state_->GetInt64(prefs::kVariationsLastFetchTime); | 265 local_state_->GetInt64(prefs::kVariationsLastFetchTime); |
258 if (last_fetch_time_internal) { | 266 if (last_fetch_time_internal) { |
259 const base::Time now = base::Time::Now(); | 267 const base::Time now = base::Time::Now(); |
260 const base::TimeDelta delta = | 268 const base::TimeDelta delta = |
261 now - base::Time::FromInternalValue(last_fetch_time_internal); | 269 now - base::Time::FromInternalValue(last_fetch_time_internal); |
262 // Log the value in number of minutes. | 270 // Log the value in number of minutes. |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 | 555 |
548 void VariationsService::RecordLastFetchTime() { | 556 void VariationsService::RecordLastFetchTime() { |
549 // local_state_ is NULL in tests, so check it first. | 557 // local_state_ is NULL in tests, so check it first. |
550 if (local_state_) { | 558 if (local_state_) { |
551 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 559 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
552 base::Time::Now().ToInternalValue()); | 560 base::Time::Now().ToInternalValue()); |
553 } | 561 } |
554 } | 562 } |
555 | 563 |
556 } // namespace chrome_variations | 564 } // namespace chrome_variations |
OLD | NEW |