| 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/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 17 #include "base/timer/elapsed_timer.h" | 17 #include "base/timer/elapsed_timer.h" |
| 18 #include "base/version.h" | 18 #include "base/version.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/metrics/variations/generated_resources_map.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "components/metrics/metrics_state_manager.h" | 23 #include "components/metrics/metrics_state_manager.h" |
| 23 #include "components/network_time/network_time_tracker.h" | 24 #include "components/network_time/network_time_tracker.h" |
| 24 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
| 25 #include "components/variations/proto/variations_seed.pb.h" | 26 #include "components/variations/proto/variations_seed.pb.h" |
| 26 #include "components/variations/variations_seed_processor.h" | 27 #include "components/variations/variations_seed_processor.h" |
| 27 #include "components/variations/variations_seed_simulator.h" | 28 #include "components/variations/variations_seed_simulator.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
| 30 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| 31 #include "net/base/network_change_notifier.h" | 32 #include "net/base/network_change_notifier.h" |
| 32 #include "net/base/url_util.h" | 33 #include "net/base/url_util.h" |
| 33 #include "net/http/http_response_headers.h" | 34 #include "net/http/http_response_headers.h" |
| 34 #include "net/http/http_status_code.h" | 35 #include "net/http/http_status_code.h" |
| 35 #include "net/http/http_util.h" | 36 #include "net/http/http_util.h" |
| 36 #include "net/url_request/url_fetcher.h" | 37 #include "net/url_request/url_fetcher.h" |
| 37 #include "net/url_request/url_request_status.h" | 38 #include "net/url_request/url_request_status.h" |
| 38 #include "ui/base/device_form_factor.h" | 39 #include "ui/base/device_form_factor.h" |
| 40 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 40 | 42 |
| 41 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) | 43 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) |
| 42 #include "chrome/browser/upgrade_detector_impl.h" | 44 #include "chrome/browser/upgrade_detector_impl.h" |
| 43 #endif | 45 #endif |
| 44 | 46 |
| 45 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
| 46 #include "chrome/browser/chromeos/settings/cros_settings.h" | 48 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 47 #endif | 49 #endif |
| 48 | 50 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 const base::Time seed_date = base::Time::FromInternalValue(date_value); | 213 const base::Time seed_date = base::Time::FromInternalValue(date_value); |
| 212 const base::Time build_time = base::GetBuildTime(); | 214 const base::Time build_time = base::GetBuildTime(); |
| 213 // Use the build time for date checks if either the seed date is invalid or | 215 // Use the build time for date checks if either the seed date is invalid or |
| 214 // the build time is newer than the seed date. | 216 // the build time is newer than the seed date. |
| 215 base::Time reference_date = seed_date; | 217 base::Time reference_date = seed_date; |
| 216 if (seed_date.is_null() || seed_date < build_time) | 218 if (seed_date.is_null() || seed_date < build_time) |
| 217 reference_date = build_time; | 219 reference_date = build_time; |
| 218 return reference_date; | 220 return reference_date; |
| 219 } | 221 } |
| 220 | 222 |
| 223 // Overrides the string resource sepecified by |hash| with |string| in the |
| 224 // resource bundle. Used as a callback passed to the variations seed processor. |
| 225 void OverrideUIString(uint32_t hash, const base::string16& string) { |
| 226 int resource_id = GetResourceIndex(hash); |
| 227 if (resource_id == -1) |
| 228 return; |
| 229 |
| 230 ui::ResourceBundle::GetSharedInstance().OverrideLocaleStringResource( |
| 231 resource_id, string); |
| 232 } |
| 233 |
| 221 } // namespace | 234 } // namespace |
| 222 | 235 |
| 223 VariationsService::VariationsService( | 236 VariationsService::VariationsService( |
| 224 ResourceRequestAllowedNotifier* notifier, | 237 ResourceRequestAllowedNotifier* notifier, |
| 225 PrefService* local_state, | 238 PrefService* local_state, |
| 226 metrics::MetricsStateManager* state_manager) | 239 metrics::MetricsStateManager* state_manager) |
| 227 : local_state_(local_state), | 240 : local_state_(local_state), |
| 228 state_manager_(state_manager), | 241 state_manager_(state_manager), |
| 229 policy_pref_service_(local_state), | 242 policy_pref_service_(local_state), |
| 230 seed_store_(local_state), | 243 seed_store_(local_state), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 247 | 260 |
| 248 const chrome::VersionInfo current_version_info; | 261 const chrome::VersionInfo current_version_info; |
| 249 if (!current_version_info.is_valid()) | 262 if (!current_version_info.is_valid()) |
| 250 return false; | 263 return false; |
| 251 | 264 |
| 252 const base::Version current_version(current_version_info.Version()); | 265 const base::Version current_version(current_version_info.Version()); |
| 253 if (!current_version.IsValid()) | 266 if (!current_version.IsValid()) |
| 254 return false; | 267 return false; |
| 255 | 268 |
| 256 VariationsSeedProcessor().CreateTrialsFromSeed( | 269 VariationsSeedProcessor().CreateTrialsFromSeed( |
| 257 seed, g_browser_process->GetApplicationLocale(), | 270 seed, |
| 258 GetReferenceDateForExpiryChecks(local_state_), current_version, | 271 g_browser_process->GetApplicationLocale(), |
| 259 GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass()); | 272 GetReferenceDateForExpiryChecks(local_state_), |
| 273 current_version, |
| 274 GetChannelForVariations(), |
| 275 GetCurrentFormFactor(), |
| 276 GetHardwareClass(), |
| 277 base::Bind(&OverrideUIString)); |
| 260 | 278 |
| 261 // Log the "freshness" of the seed that was just used. The freshness is the | 279 // Log the "freshness" of the seed that was just used. The freshness is the |
| 262 // time between the last successful seed download and now. | 280 // time between the last successful seed download and now. |
| 263 const int64 last_fetch_time_internal = | 281 const int64 last_fetch_time_internal = |
| 264 local_state_->GetInt64(prefs::kVariationsLastFetchTime); | 282 local_state_->GetInt64(prefs::kVariationsLastFetchTime); |
| 265 if (last_fetch_time_internal) { | 283 if (last_fetch_time_internal) { |
| 266 const base::Time now = base::Time::Now(); | 284 const base::Time now = base::Time::Now(); |
| 267 const base::TimeDelta delta = | 285 const base::TimeDelta delta = |
| 268 now - base::Time::FromInternalValue(last_fetch_time_internal); | 286 now - base::Time::FromInternalValue(last_fetch_time_internal); |
| 269 // Log the value in number of minutes. | 287 // Log the value in number of minutes. |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 | 599 |
| 582 void VariationsService::RecordLastFetchTime() { | 600 void VariationsService::RecordLastFetchTime() { |
| 583 // local_state_ is NULL in tests, so check it first. | 601 // local_state_ is NULL in tests, so check it first. |
| 584 if (local_state_) { | 602 if (local_state_) { |
| 585 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 603 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
| 586 base::Time::Now().ToInternalValue()); | 604 base::Time::Now().ToInternalValue()); |
| 587 } | 605 } |
| 588 } | 606 } |
| 589 | 607 |
| 590 } // namespace chrome_variations | 608 } // namespace chrome_variations |
| OLD | NEW |