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" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 return true; | 322 return true; |
323 } | 323 } |
324 | 324 |
325 void VariationsService::StartRepeatedVariationsSeedFetch() { | 325 void VariationsService::StartRepeatedVariationsSeedFetch() { |
326 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 326 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
327 | 327 |
328 // Initialize the Variations server URL. | 328 // Initialize the Variations server URL. |
329 variations_server_url_ = GetVariationsServerURL(policy_pref_service_); | 329 variations_server_url_ = |
| 330 GetVariationsServerURL(policy_pref_service_, restrict_mode_); |
330 | 331 |
331 // Check that |CreateTrialsFromSeed| was called, which is necessary to | 332 // Check that |CreateTrialsFromSeed| was called, which is necessary to |
332 // retrieve the serial number that will be sent to the server. | 333 // retrieve the serial number that will be sent to the server. |
333 DCHECK(create_trials_from_seed_called_); | 334 DCHECK(create_trials_from_seed_called_); |
334 | 335 |
335 DCHECK(!request_scheduler_.get()); | 336 DCHECK(!request_scheduler_.get()); |
336 // Note that the act of instantiating the scheduler will start the fetch, if | 337 // Note that the act of instantiating the scheduler will start the fetch, if |
337 // the scheduler deems appropriate. Using Unretained is fine here since the | 338 // the scheduler deems appropriate. |
338 // lifespan of request_scheduler_ is guaranteed to be shorter than that of | |
339 // this service. | |
340 request_scheduler_.reset(VariationsRequestScheduler::Create( | 339 request_scheduler_.reset(VariationsRequestScheduler::Create( |
341 base::Bind(&VariationsService::FetchVariationsSeed, | 340 base::Bind(&VariationsService::FetchVariationsSeed, |
342 base::Unretained(this)), local_state_)); | 341 weak_ptr_factory_.GetWeakPtr()), |
| 342 local_state_)); |
343 request_scheduler_->Start(); | 343 request_scheduler_->Start(); |
344 } | 344 } |
345 | 345 |
346 void VariationsService::AddObserver(Observer* observer) { | 346 void VariationsService::AddObserver(Observer* observer) { |
347 observer_list_.AddObserver(observer); | 347 observer_list_.AddObserver(observer); |
348 } | 348 } |
349 | 349 |
350 void VariationsService::RemoveObserver(Observer* observer) { | 350 void VariationsService::RemoveObserver(Observer* observer) { |
351 observer_list_.RemoveObserver(observer); | 351 observer_list_.RemoveObserver(observer); |
352 } | 352 } |
353 | 353 |
354 // TODO(rkaplow): Handle this and the similar event in metrics_service by | 354 // TODO(rkaplow): Handle this and the similar event in metrics_service by |
355 // observing an 'OnAppEnterForeground' event in RequestScheduler instead of | 355 // observing an 'OnAppEnterForeground' event in RequestScheduler instead of |
356 // requiring the frontend code to notify each service individually. Since the | 356 // requiring the frontend code to notify each service individually. Since the |
357 // scheduler will handle it directly the VariationService shouldn't need to | 357 // scheduler will handle it directly the VariationService shouldn't need to |
358 // know details of this anymore. | 358 // know details of this anymore. |
359 void VariationsService::OnAppEnterForeground() { | 359 void VariationsService::OnAppEnterForeground() { |
360 request_scheduler_->OnAppEnterForeground(); | 360 request_scheduler_->OnAppEnterForeground(); |
361 } | 361 } |
362 | 362 |
363 #if defined(OS_WIN) | 363 #if defined(OS_WIN) |
364 void VariationsService::StartGoogleUpdateRegistrySync() { | 364 void VariationsService::StartGoogleUpdateRegistrySync() { |
365 registry_syncer_.RequestRegistrySync(); | 365 registry_syncer_.RequestRegistrySync(); |
366 } | 366 } |
367 #endif | 367 #endif |
368 | 368 |
| 369 void VariationsService::SetRestrictMode(const std::string& restrict_mode) { |
| 370 // This should be called before the server URL has been computed. |
| 371 DCHECK(variations_server_url_.is_empty()); |
| 372 restrict_mode_ = restrict_mode; |
| 373 } |
| 374 |
369 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { | 375 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { |
370 create_trials_from_seed_called_ = called; | 376 create_trials_from_seed_called_ = called; |
371 } | 377 } |
372 | 378 |
373 // static | 379 // static |
374 GURL VariationsService::GetVariationsServerURL( | 380 GURL VariationsService::GetVariationsServerURL( |
375 PrefService* policy_pref_service) { | 381 PrefService* policy_pref_service, |
| 382 const std::string& restrict_mode_override) { |
376 std::string server_url_string( | 383 std::string server_url_string( |
377 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 384 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
378 switches::kVariationsServerURL)); | 385 switches::kVariationsServerURL)); |
379 if (server_url_string.empty()) | 386 if (server_url_string.empty()) |
380 server_url_string = kDefaultVariationsServerURL; | 387 server_url_string = kDefaultVariationsServerURL; |
381 GURL server_url = GURL(server_url_string); | 388 GURL server_url = GURL(server_url_string); |
382 | 389 |
383 const std::string restrict_param = | 390 const std::string restrict_param = !restrict_mode_override.empty() ? |
384 GetRestrictParameterPref(policy_pref_service); | 391 restrict_mode_override : GetRestrictParameterPref(policy_pref_service); |
385 if (!restrict_param.empty()) { | 392 if (!restrict_param.empty()) { |
386 server_url = net::AppendOrReplaceQueryParameter(server_url, | 393 server_url = net::AppendOrReplaceQueryParameter(server_url, |
387 "restrict", | 394 "restrict", |
388 restrict_param); | 395 restrict_param); |
389 } | 396 } |
390 | 397 |
391 server_url = net::AppendOrReplaceQueryParameter(server_url, "osname", | 398 server_url = net::AppendOrReplaceQueryParameter(server_url, "osname", |
392 GetPlatformString()); | 399 GetPlatformString()); |
393 | 400 |
394 DCHECK(server_url.is_valid()); | 401 DCHECK(server_url.is_valid()); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 645 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
639 base::Time::Now().ToInternalValue()); | 646 base::Time::Now().ToInternalValue()); |
640 } | 647 } |
641 } | 648 } |
642 | 649 |
643 std::string VariationsService::GetInvalidVariationsSeedSignature() const { | 650 std::string VariationsService::GetInvalidVariationsSeedSignature() const { |
644 return seed_store_.GetInvalidSignature(); | 651 return seed_store_.GetInvalidSignature(); |
645 } | 652 } |
646 | 653 |
647 } // namespace chrome_variations | 654 } // namespace chrome_variations |
OLD | NEW |