Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: chrome/browser/metrics/variations/variations_service.cc

Issue 14268009: Support VariationsRestrictParameter in VariationsService for Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed a test Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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, &parameter);
128 #else
129 if (local_state)
130 parameter = local_state->GetString(prefs::kVariationsRestrictParameter);
131 #endif
132 return parameter;
133 }
134
117 } // namespace 135 } // namespace
118 136
119 VariationsService::VariationsService(PrefService* local_state) 137 VariationsService::VariationsService(PrefService* local_state)
120 : local_state_(local_state), 138 : local_state_(local_state),
121 variations_server_url_(GetVariationsServerURL(local_state)), 139 variations_server_url_(GetVariationsServerURL(local_state)),
122 create_trials_from_seed_called_(false), 140 create_trials_from_seed_called_(false),
123 resource_request_allowed_notifier_( 141 resource_request_allowed_notifier_(
124 new ResourceRequestAllowedNotifier) { 142 new ResourceRequestAllowedNotifier) {
125 resource_request_allowed_notifier_->Init(this); 143 resource_request_allowed_notifier_->Init(this);
126 } 144 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return network_time_tracker_.GetNetworkTime(network_time, uncertainty); 222 return network_time_tracker_.GetNetworkTime(network_time, uncertainty);
205 } 223 }
206 224
207 // static 225 // static
208 GURL VariationsService::GetVariationsServerURL(PrefService* local_state) { 226 GURL VariationsService::GetVariationsServerURL(PrefService* local_state) {
209 std::string server_url_string(CommandLine::ForCurrentProcess()-> 227 std::string server_url_string(CommandLine::ForCurrentProcess()->
210 GetSwitchValueASCII(switches::kVariationsServerURL)); 228 GetSwitchValueASCII(switches::kVariationsServerURL));
211 if (server_url_string.empty()) 229 if (server_url_string.empty())
212 server_url_string = kDefaultVariationsServerURL; 230 server_url_string = kDefaultVariationsServerURL;
213 GURL server_url = GURL(server_url_string); 231 GURL server_url = GURL(server_url_string);
214 if (local_state) { 232 const std::string restrict_param = GetRestrictParameterPref(local_state);
215 // Append the "restrict" parameter if it is found in prefs. 233 if (!restrict_param.empty()) {
216 const std::string restrict_param = 234 server_url = net::AppendOrReplaceQueryParameter(server_url,
217 local_state->GetString(prefs::kVariationsRestrictParameter); 235 "restrict",
218 if (!restrict_param.empty()) 236 restrict_param);
219 server_url = net::AppendOrReplaceQueryParameter(server_url,
220 "restrict",
221 restrict_param);
222 } 237 }
223 DCHECK(server_url.is_valid()); 238 DCHECK(server_url.is_valid());
224 return server_url; 239 return server_url;
225 } 240 }
226 241
227 #if defined(OS_WIN) 242 #if defined(OS_WIN)
228 void VariationsService::StartGoogleUpdateRegistrySync() { 243 void VariationsService::StartGoogleUpdateRegistrySync() {
229 registry_syncer_.RequestRegistrySync(); 244 registry_syncer_.RequestRegistrySync();
230 } 245 }
231 #endif 246 #endif
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 662
648 void VariationsService::RecordLastFetchTime() { 663 void VariationsService::RecordLastFetchTime() {
649 // local_state_ is NULL in tests, so check it first. 664 // local_state_ is NULL in tests, so check it first.
650 if (local_state_) { 665 if (local_state_) {
651 local_state_->SetInt64(prefs::kVariationsLastFetchTime, 666 local_state_->SetInt64(prefs::kVariationsLastFetchTime,
652 base::Time::Now().ToInternalValue()); 667 base::Time::Now().ToInternalValue());
653 } 668 }
654 } 669 }
655 670
656 } // namespace chrome_variations 671 } // namespace chrome_variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698