| 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/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/build_time.h" | 10 #include "base/build_time.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
| 27 #include "net/base/network_change_notifier.h" | 27 #include "net/base/network_change_notifier.h" |
| 28 #include "net/base/url_util.h" | 28 #include "net/base/url_util.h" |
| 29 #include "net/http/http_response_headers.h" | 29 #include "net/http/http_response_headers.h" |
| 30 #include "net/http/http_status_code.h" | 30 #include "net/http/http_status_code.h" |
| 31 #include "net/http/http_util.h" | 31 #include "net/http/http_util.h" |
| 32 #include "net/url_request/url_fetcher.h" | 32 #include "net/url_request/url_fetcher.h" |
| 33 #include "net/url_request/url_request_status.h" | 33 #include "net/url_request/url_request_status.h" |
| 34 | 34 |
| 35 #if defined(OS_CHROMEOS) |
| 36 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 37 #endif |
| 38 |
| 35 namespace chrome_variations { | 39 namespace chrome_variations { |
| 36 | 40 |
| 37 namespace { | 41 namespace { |
| 38 | 42 |
| 39 // Default server of Variations seed info. | 43 // Default server of Variations seed info. |
| 40 const char kDefaultVariationsServerURL[] = | 44 const char kDefaultVariationsServerURL[] = |
| 41 "https://clients4.google.com/chrome-variations/seed"; | 45 "https://clients4.google.com/chrome-variations/seed"; |
| 42 const int kMaxRetrySeedFetch = 5; | 46 const int kMaxRetrySeedFetch = 5; |
| 43 | 47 |
| 44 // TODO(mad): To be removed when we stop updating the NetworkTimeTracker. | 48 // TODO(mad): To be removed when we stop updating the NetworkTimeTracker. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 #else | 111 #else |
| 108 #error Unknown platform | 112 #error Unknown platform |
| 109 #endif | 113 #endif |
| 110 } | 114 } |
| 111 | 115 |
| 112 // Converts |date_time| in Study date format to base::Time. | 116 // Converts |date_time| in Study date format to base::Time. |
| 113 base::Time ConvertStudyDateToBaseTime(int64 date_time) { | 117 base::Time ConvertStudyDateToBaseTime(int64 date_time) { |
| 114 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(date_time); | 118 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(date_time); |
| 115 } | 119 } |
| 116 | 120 |
| 121 // Gets the restrict parameter from |local_state| or from Chrome OS settings in |
| 122 // the case of that platform. |
| 123 std::string GetRestrictParameterPref(PrefService* local_state) { |
| 124 std::string parameter; |
| 125 #if defined(OS_CHROMEOS) |
| 126 chromeos::CrosSettings::Get()->GetString( |
| 127 chromeos::kVariationsRestrictParameter, ¶meter); |
| 128 #else |
| 129 parameter = local_state->GetString(prefs::kVariationsRestrictParameter); |
| 130 #endif |
| 131 return parameter; |
| 132 } |
| 133 |
| 117 } // namespace | 134 } // namespace |
| 118 | 135 |
| 119 VariationsService::VariationsService(PrefService* local_state) | 136 VariationsService::VariationsService(PrefService* local_state) |
| 120 : local_state_(local_state), | 137 : local_state_(local_state), |
| 121 variations_server_url_(GetVariationsServerURL(local_state)), | 138 variations_server_url_(GetVariationsServerURL(local_state)), |
| 122 create_trials_from_seed_called_(false), | 139 create_trials_from_seed_called_(false), |
| 123 resource_request_allowed_notifier_( | 140 resource_request_allowed_notifier_( |
| 124 new ResourceRequestAllowedNotifier) { | 141 new ResourceRequestAllowedNotifier) { |
| 125 resource_request_allowed_notifier_->Init(this); | 142 resource_request_allowed_notifier_->Init(this); |
| 126 } | 143 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return network_time_tracker_.GetNetworkTime(network_time, uncertainty); | 221 return network_time_tracker_.GetNetworkTime(network_time, uncertainty); |
| 205 } | 222 } |
| 206 | 223 |
| 207 // static | 224 // static |
| 208 GURL VariationsService::GetVariationsServerURL(PrefService* local_state) { | 225 GURL VariationsService::GetVariationsServerURL(PrefService* local_state) { |
| 209 std::string server_url_string(CommandLine::ForCurrentProcess()-> | 226 std::string server_url_string(CommandLine::ForCurrentProcess()-> |
| 210 GetSwitchValueASCII(switches::kVariationsServerURL)); | 227 GetSwitchValueASCII(switches::kVariationsServerURL)); |
| 211 if (server_url_string.empty()) | 228 if (server_url_string.empty()) |
| 212 server_url_string = kDefaultVariationsServerURL; | 229 server_url_string = kDefaultVariationsServerURL; |
| 213 GURL server_url = GURL(server_url_string); | 230 GURL server_url = GURL(server_url_string); |
| 214 if (local_state) { | 231 const std::string restrict_param = GetRestrictParameterPref(local_state); |
| 215 // Append the "restrict" parameter if it is found in prefs. | 232 if (!restrict_param.empty()) { |
| 216 const std::string restrict_param = | 233 server_url = net::AppendOrReplaceQueryParameter(server_url, |
| 217 local_state->GetString(prefs::kVariationsRestrictParameter); | 234 "restrict", |
| 218 if (!restrict_param.empty()) | 235 restrict_param); |
| 219 server_url = net::AppendOrReplaceQueryParameter(server_url, | |
| 220 "restrict", | |
| 221 restrict_param); | |
| 222 } | 236 } |
| 223 DCHECK(server_url.is_valid()); | 237 DCHECK(server_url.is_valid()); |
| 224 return server_url; | 238 return server_url; |
| 225 } | 239 } |
| 226 | 240 |
| 227 #if defined(OS_WIN) | 241 #if defined(OS_WIN) |
| 228 void VariationsService::StartGoogleUpdateRegistrySync() { | 242 void VariationsService::StartGoogleUpdateRegistrySync() { |
| 229 registry_syncer_.RequestRegistrySync(); | 243 registry_syncer_.RequestRegistrySync(); |
| 230 } | 244 } |
| 231 #endif | 245 #endif |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 | 662 |
| 649 void VariationsService::RecordLastFetchTime() { | 663 void VariationsService::RecordLastFetchTime() { |
| 650 // local_state_ is NULL in tests, so check it first. | 664 // local_state_ is NULL in tests, so check it first. |
| 651 if (local_state_) { | 665 if (local_state_) { |
| 652 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 666 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
| 653 base::Time::Now().ToInternalValue()); | 667 base::Time::Now().ToInternalValue()); |
| 654 } | 668 } |
| 655 } | 669 } |
| 656 | 670 |
| 657 } // namespace chrome_variations | 671 } // namespace chrome_variations |
| OLD | NEW |