| 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 resource_id = GetResourceIndex(hash); |
| 207 if (resource_id == -1) |
| 208 return; |
| 209 |
| 210 ui::ResourceBundle::GetSharedInstance().OverrideLocaleStringResource( |
| 211 resource_id, string); |
| 212 } |
| 213 |
| 201 } // namespace | 214 } // namespace |
| 202 | 215 |
| 203 VariationsService::VariationsService( | 216 VariationsService::VariationsService( |
| 204 PrefService* local_state, | 217 PrefService* local_state, |
| 205 metrics::MetricsStateManager* state_manager) | 218 metrics::MetricsStateManager* state_manager) |
| 206 : local_state_(local_state), | 219 : local_state_(local_state), |
| 207 state_manager_(state_manager), | 220 state_manager_(state_manager), |
| 208 policy_pref_service_(local_state), | 221 policy_pref_service_(local_state), |
| 209 seed_store_(local_state), | 222 seed_store_(local_state), |
| 210 create_trials_from_seed_called_(false), | 223 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()) | 255 if (!current_version_info.is_valid()) |
| 243 return false; | 256 return false; |
| 244 | 257 |
| 245 const base::Version current_version(current_version_info.Version()); | 258 const base::Version current_version(current_version_info.Version()); |
| 246 if (!current_version.IsValid()) | 259 if (!current_version.IsValid()) |
| 247 return false; | 260 return false; |
| 248 | 261 |
| 249 VariationsSeedProcessor().CreateTrialsFromSeed( | 262 VariationsSeedProcessor().CreateTrialsFromSeed( |
| 250 seed, g_browser_process->GetApplicationLocale(), | 263 seed, g_browser_process->GetApplicationLocale(), |
| 251 GetReferenceDateForExpiryChecks(local_state_), current_version, | 264 GetReferenceDateForExpiryChecks(local_state_), current_version, |
| 252 GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass()); | 265 GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass(), |
| 266 base::Bind(&OverrideUIString)); |
| 253 | 267 |
| 254 // Log the "freshness" of the seed that was just used. The freshness is the | 268 // Log the "freshness" of the seed that was just used. The freshness is the |
| 255 // time between the last successful seed download and now. | 269 // time between the last successful seed download and now. |
| 256 const int64 last_fetch_time_internal = | 270 const int64 last_fetch_time_internal = |
| 257 local_state_->GetInt64(prefs::kVariationsLastFetchTime); | 271 local_state_->GetInt64(prefs::kVariationsLastFetchTime); |
| 258 if (last_fetch_time_internal) { | 272 if (last_fetch_time_internal) { |
| 259 const base::Time now = base::Time::Now(); | 273 const base::Time now = base::Time::Now(); |
| 260 const base::TimeDelta delta = | 274 const base::TimeDelta delta = |
| 261 now - base::Time::FromInternalValue(last_fetch_time_internal); | 275 now - base::Time::FromInternalValue(last_fetch_time_internal); |
| 262 // Log the value in number of minutes. | 276 // Log the value in number of minutes. |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 561 |
| 548 void VariationsService::RecordLastFetchTime() { | 562 void VariationsService::RecordLastFetchTime() { |
| 549 // local_state_ is NULL in tests, so check it first. | 563 // local_state_ is NULL in tests, so check it first. |
| 550 if (local_state_) { | 564 if (local_state_) { |
| 551 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 565 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
| 552 base::Time::Now().ToInternalValue()); | 566 base::Time::Now().ToInternalValue()); |
| 553 } | 567 } |
| 554 } | 568 } |
| 555 | 569 |
| 556 } // namespace chrome_variations | 570 } // namespace chrome_variations |
| OLD | NEW |