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

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

Issue 1298743004: Abstract BrowserProcess dependency from VariationsService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@variations_service_client
Patch Set: Rebase Created 5 years, 4 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
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 "base/build_time.h" 7 #include "base/build_time.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/sparse_histogram.h" 10 #include "base/metrics/sparse_histogram.h"
11 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/sys_info.h" 13 #include "base/sys_info.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "base/timer/elapsed_timer.h" 15 #include "base/timer/elapsed_timer.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "base/version.h" 17 #include "base/version.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/metrics/variations/generated_resources_map.h" 18 #include "chrome/browser/metrics/variations/generated_resources_map.h"
20 #include "chrome/common/channel_info.h" 19 #include "chrome/common/channel_info.h"
21 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
22 #include "components/metrics/metrics_state_manager.h" 21 #include "components/metrics/metrics_state_manager.h"
23 #include "components/network_time/network_time_tracker.h" 22 #include "components/network_time/network_time_tracker.h"
24 #include "components/pref_registry/pref_registry_syncable.h" 23 #include "components/pref_registry/pref_registry_syncable.h"
25 #include "components/variations/pref_names.h" 24 #include "components/variations/pref_names.h"
26 #include "components/variations/proto/variations_seed.pb.h" 25 #include "components/variations/proto/variations_seed.pb.h"
27 #include "components/variations/variations_seed_processor.h" 26 #include "components/variations/variations_seed_processor.h"
28 #include "components/variations/variations_seed_simulator.h" 27 #include "components/variations/variations_seed_simulator.h"
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 } 471 }
473 472
474 void VariationsService::DoActualFetch() { 473 void VariationsService::DoActualFetch() {
475 DCHECK(thread_checker_.CalledOnValidThread()); 474 DCHECK(thread_checker_.CalledOnValidThread());
476 DCHECK(!pending_seed_request_); 475 DCHECK(!pending_seed_request_);
477 476
478 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, 477 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_,
479 net::URLFetcher::GET, this); 478 net::URLFetcher::GET, this);
480 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 479 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
481 net::LOAD_DO_NOT_SAVE_COOKIES); 480 net::LOAD_DO_NOT_SAVE_COOKIES);
482 pending_seed_request_->SetRequestContext( 481 pending_seed_request_->SetRequestContext(client_->GetURLRequestContext());
483 g_browser_process->system_request_context());
484 pending_seed_request_->SetMaxRetriesOn5xx(kMaxRetrySeedFetch); 482 pending_seed_request_->SetMaxRetriesOn5xx(kMaxRetrySeedFetch);
485 if (!seed_store_.variations_serial_number().empty() && 483 if (!seed_store_.variations_serial_number().empty() &&
486 !disable_deltas_for_next_request_) { 484 !disable_deltas_for_next_request_) {
487 // If the current seed includes a country code, deltas are not supported (as 485 // If the current seed includes a country code, deltas are not supported (as
488 // the serial number doesn't take into account the country code). The server 486 // the serial number doesn't take into account the country code). The server
489 // will update us with a seed that doesn't include a country code which will 487 // will update us with a seed that doesn't include a country code which will
490 // enable deltas to work. 488 // enable deltas to work.
491 // TODO(asvitkine): Remove the check in M50+ when the percentage of clients 489 // TODO(asvitkine): Remove the check in M50+ when the percentage of clients
492 // that have an old seed with a country code becomes miniscule. 490 // that have an old seed with a country code becomes miniscule.
493 if (!seed_store_.seed_has_country_code()) { 491 if (!seed_store_.seed_has_country_code()) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 const base::TimeDelta latency = 600 const base::TimeDelta latency =
603 base::TimeTicks::Now() - last_request_started_time_; 601 base::TimeTicks::Now() - last_request_started_time_;
604 602
605 base::Time response_date; 603 base::Time response_date;
606 if (response_code == net::HTTP_OK || 604 if (response_code == net::HTTP_OK ||
607 response_code == net::HTTP_NOT_MODIFIED) { 605 response_code == net::HTTP_NOT_MODIFIED) {
608 bool success = request->GetResponseHeaders()->GetDateValue(&response_date); 606 bool success = request->GetResponseHeaders()->GetDateValue(&response_date);
609 DCHECK(success || response_date.is_null()); 607 DCHECK(success || response_date.is_null());
610 608
611 if (!response_date.is_null()) { 609 if (!response_date.is_null()) {
612 g_browser_process->network_time_tracker()->UpdateNetworkTime( 610 client_->GetNetworkTimeTracker()->UpdateNetworkTime(
613 response_date, 611 response_date,
614 base::TimeDelta::FromMilliseconds(kServerTimeResolutionMs), 612 base::TimeDelta::FromMilliseconds(kServerTimeResolutionMs), latency,
615 latency,
616 base::TimeTicks::Now()); 613 base::TimeTicks::Now());
617 } 614 }
618 } 615 }
619 616
620 if (response_code != net::HTTP_OK) { 617 if (response_code != net::HTTP_OK) {
621 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " 618 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: "
622 << response_code; 619 << response_code;
623 if (response_code == net::HTTP_NOT_MODIFIED) { 620 if (response_code == net::HTTP_NOT_MODIFIED) {
624 RecordLastFetchTime(); 621 RecordLastFetchTime();
625 // Update the seed date value in local state (used for expiry check on 622 // Update the seed date value in local state (used for expiry check on
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 // Otherwise, update the pref with the current Chrome version and country. 777 // Otherwise, update the pref with the current Chrome version and country.
781 base::ListValue new_list_value; 778 base::ListValue new_list_value;
782 new_list_value.AppendString(version.GetString()); 779 new_list_value.AppendString(version.GetString());
783 new_list_value.AppendString(latest_country); 780 new_list_value.AppendString(latest_country);
784 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, 781 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry,
785 new_list_value); 782 new_list_value);
786 return latest_country; 783 return latest_country;
787 } 784 }
788 785
789 } // namespace chrome_variations 786 } // namespace chrome_variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698