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

Unified Diff: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc

Issue 11522009: X-Chrome-Variations logic refactoring (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Addressed comments. Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
index fb6e707047efaab34e74c40a4005edac0bfc58d2..c953a16a09148c0c3763afff5dca63ad0247f619 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -9,6 +9,7 @@
#include "base/base64.h"
#include "base/logging.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_metrics_helper.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/download/download_request_limiter.h"
#include "chrome/browser/download/download_resource_throttle.h"
@@ -87,8 +88,7 @@ ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate(
: download_request_limiter_(g_browser_process->download_request_limiter()),
safe_browsing_(g_browser_process->safe_browsing_service()),
user_script_listener_(new extensions::UserScriptListener()),
- prerender_tracker_(prerender_tracker),
- variation_ids_cache_initialized_(false) {
+ prerender_tracker_(prerender_tracker) {
}
ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() {
@@ -164,7 +164,8 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning(
}
#endif
- AppendChromeMetricsHeaders(request, resource_context, resource_type);
+ ChromeMetricsHelper::GetInstance()->AppendHeadersToRequest(request,
+ resource_context);
#if defined(ENABLE_ONE_CLICK_SIGNIN)
AppendChromeSyncGaiaHeader(request, resource_context);
@@ -312,45 +313,6 @@ void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles(
throttles->push_back(throttle);
}
-void ChromeResourceDispatcherHostDelegate::AppendChromeMetricsHeaders(
- net::URLRequest* request,
- content::ResourceContext* resource_context,
- ResourceType::Type resource_type) {
- // Don't attempt to append headers to requests that have already started.
- // TODO(stevet): Remove this once the request ordering issues are resolved
- // in crbug.com/128048.
- if (request->is_pending())
- return;
-
- // Note the criteria for attaching Chrome experiment headers:
- // 1. We only transmit to *.google.<TLD> domains. NOTE that this use of
- // google_util helpers to check this does not guarantee that the URL is
- // Google-owned, only that it is of the form *.google.<TLD>. In the future
- // we may choose to reinforce this check.
- // 2. Only transmit for non-Incognito profiles.
- // 3. For the X-Chrome-UMA-Enabled bit, only set it if UMA is in fact enabled
- // for this install of Chrome.
- // 4. For the X-Chrome-Variations, only include non-empty variation IDs.
- ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
- if (io_data->is_incognito() ||
- !google_util::IsGoogleDomainUrl(request->url().spec(),
- google_util::ALLOW_SUBDOMAIN,
- google_util::ALLOW_NON_STANDARD_PORTS))
- return;
-
- if (io_data->GetMetricsEnabledStateOnIOThread())
- request->SetExtraRequestHeaderByName("X-Chrome-UMA-Enabled", "1", false);
-
- // Lazily initialize the header, if not already done, before attempting to
- // transmit it.
- InitVariationIDsCacheIfNeeded();
- if (!variation_ids_header_.empty()) {
- request->SetExtraRequestHeaderByName("X-Chrome-Variations",
- variation_ids_header_,
- false);
- }
-}
-
#if defined(ENABLE_ONE_CLICK_SIGNIN)
void ChromeResourceDispatcherHostDelegate::AppendChromeSyncGaiaHeader(
net::URLRequest* request,
@@ -458,76 +420,3 @@ void ChromeResourceDispatcherHostDelegate::OnRequestRedirected(
redirect_url, request);
}
}
-
-void ChromeResourceDispatcherHostDelegate::OnFieldTrialGroupFinalized(
- const std::string& trial_name,
- const std::string& group_name) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- chrome_variations::VariationID new_id =
- chrome_variations::GetGoogleVariationID(
- chrome_variations::GOOGLE_WEB_PROPERTIES, trial_name, group_name);
- if (new_id == chrome_variations::kEmptyID)
- return;
- variation_ids_set_.insert(new_id);
- UpdateVariationIDsHeaderValue();
-}
-
-void ChromeResourceDispatcherHostDelegate::InitVariationIDsCacheIfNeeded() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (variation_ids_cache_initialized_)
- return;
-
- // Register for additional cache updates. This is done first to avoid a race
- // that could cause registered FieldTrials to be missed.
- base::FieldTrialList::AddObserver(this);
-
- base::FieldTrial::ActiveGroups initial_groups;
- base::FieldTrialList::GetActiveFieldTrialGroups(&initial_groups);
- for (base::FieldTrial::ActiveGroups::const_iterator it =
- initial_groups.begin(); it != initial_groups.end(); ++it) {
- const chrome_variations::VariationID id =
- chrome_variations::GetGoogleVariationID(
- chrome_variations::GOOGLE_WEB_PROPERTIES, it->trial_name,
- it->group_name);
- if (id != chrome_variations::kEmptyID)
- variation_ids_set_.insert(id);
- }
- UpdateVariationIDsHeaderValue();
-
- variation_ids_cache_initialized_ = true;
-}
-
-void ChromeResourceDispatcherHostDelegate::UpdateVariationIDsHeaderValue() {
- // The header value is a serialized protobuffer of Variation IDs which is
- // base64 encoded before transmitting as a string.
- if (variation_ids_set_.empty())
- return;
-
- // This is the bottleneck for the creation of the header, so validate the size
- // here. Force a hard maximum on the ID count in case the Variations server
- // returns too many IDs and DOSs receiving servers with large requests.
- DCHECK_LE(variation_ids_set_.size(), 10U);
- if (variation_ids_set_.size() > 20) {
- variation_ids_header_.clear();
- return;
- }
-
- metrics::ChromeVariations proto;
- for (std::set<chrome_variations::VariationID>::const_iterator it =
- variation_ids_set_.begin(); it != variation_ids_set_.end(); ++it)
- proto.add_variation_id(*it);
-
- std::string serialized;
- proto.SerializeToString(&serialized);
-
- std::string hashed;
- if (base::Base64Encode(serialized, &hashed)) {
- // If successful, swap the header value with the new one.
- // Note that the list of IDs and the header could be temporarily out of sync
- // if IDs are added as the header is recreated. The receiving servers are OK
- // with such descrepancies.
- variation_ids_header_ = hashed;
- } else {
- DVLOG(1) << "Failed to base64 encode Variation IDs value: " << serialized;
- }
-}

Powered by Google App Engine
This is Rietveld 408576698