Skip to content

Commit

Permalink
Report data usage UMA for Chrome services
Browse files Browse the repository at this point in the history
data_use_measurement is a component which records the data use of the
services, if a DataUseUserData is attached to their request. Hence to
measure and compare data use of different services, a small change is
needed in the services' code where they create a URLFetcher. After
creating a URLFetcher by a service, a proper tag for that service should
be attached to the request.
Besides the necessary changes in the service, the enum in DataUseUserData
and the function returning the names based on this enum should be updated
for different services too. Also the name of target services should be
added to proper enum and histograms in histograms.xml file.
Lastly the dependency files should be updated accordingly too.

TBR=bartfab@chromium.org, andrewhayden@chromium.org, rogerta@chromium.org, isherman@chromium.org, rouslan@chromium.org, estade@chromium.org, nyquist@chromium.org, pkasting@chromium.org, zea@chromium.org, mmenke@chromium.org, bengr@chromium.org, timvolodine@chromium.org

BUG=527304

Review URL: https://codereview.chromium.org/1330443002

Cr-Commit-Position: refs/heads/master@{#348561}
  • Loading branch information
amohammadkhan authored and Commit bot committed Sep 14, 2015
1 parent 95b75ed commit aa789c8
Show file tree
Hide file tree
Showing 66 changed files with 236 additions and 25 deletions.
1 change: 1 addition & 0 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ source_set("browser") {
"//components/content_settings/core/common",
"//components/crx_file",
"//components/data_reduction_proxy/core/browser",
"//components/data_use_measurement/core",
"//components/device_event_log",
"//components/domain_reliability",
"//components/enhanced_bookmarks",
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ include_rules = [
"+components/crash",
"+components/crx_file",
"+components/data_reduction_proxy",
"+components/data_use_measurement/core",
"+components/device_event_log",
"+components/dom_distiller",
"+components/domain_reliability",
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/profiles/profile_downloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/signin/core/browser/account_fetcher_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_client.h"
Expand Down Expand Up @@ -285,6 +286,9 @@ void ProfileDownloader::FetchImageData() {
VLOG(1) << "Fetching profile image from " << image_url_with_size;
profile_image_fetcher_ = net::URLFetcher::Create(
GURL(image_url_with_size), net::URLFetcher::GET, this);
data_use_measurement::DataUseUserData::AttachToFetcher(
profile_image_fetcher_.get(),
data_use_measurement::DataUseUserData::PROFILE_DOWNLOADER);
profile_image_fetcher_->SetRequestContext(
delegate_->GetBrowserProfile()->GetRequestContext());
profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/spellchecker/feedback_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "chrome/common/spellcheck_common.h"
#include "chrome/common/spellcheck_marker.h"
#include "chrome/common/spellcheck_messages.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "content/public/browser/render_process_host.h"
#include "google_apis/google_api_keys.h"
#include "net/base/load_flags.h"
Expand Down Expand Up @@ -410,6 +411,8 @@ void FeedbackSender::SendFeedback(const std::vector<Misspelling>& feedback_data,
net::URLFetcher* sender =
net::URLFetcher::Create(kUrlFetcherId, feedback_service_url_,
net::URLFetcher::POST, this).release();
data_use_measurement::DataUseUserData::AttachToFetcher(
sender, data_use_measurement::DataUseUserData::SPELL_CHECKER);
sender->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES);
sender->SetUploadData("application/json", feedback);
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/spellcheck_common.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "net/base/load_flags.h"
Expand Down Expand Up @@ -244,6 +245,8 @@ void SpellcheckHunspellDictionary::DownloadDictionary(GURL url) {
OnHunspellDictionaryDownloadBegin(language_));

fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this);
data_use_measurement::DataUseUserData::AttachToFetcher(
fetcher_.get(), data_use_measurement::DataUseUserData::SPELL_CHECKER);
fetcher_->SetRequestContext(request_context_getter_);
fetcher_->SetLoadFlags(
net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES);
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/spellchecker/spelling_service_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/spellcheck_common.h"
#include "chrome/common/spellcheck_result.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "google_apis/google_api_keys.h"
Expand Down Expand Up @@ -105,6 +106,8 @@ bool SpellingServiceClient::RequestTextCheck(

GURL url = GURL(kSpellingServiceURL);
net::URLFetcher* fetcher = CreateURLFetcher(url).release();
data_use_measurement::DataUseUserData::AttachToFetcher(
fetcher, data_use_measurement::DataUseUserData::SPELL_CHECKER);
fetcher->SetRequestContext(context->GetRequestContext());
fetcher->SetUploadData("application/json", request);
fetcher->SetLoadFlags(
Expand Down
14 changes: 13 additions & 1 deletion chrome/browser/sync/glue/sync_backend_host_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

#include "chrome/browser/sync/glue/sync_backend_host_core.h"

#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/metrics/histogram.h"
#include "base/single_thread_task_runner.h"
#include "chrome/browser/sync/glue/local_device_info_provider_impl.h"
#include "chrome/browser/sync/glue/sync_backend_registrar.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/invalidation/public/invalidation_util.h"
#include "components/invalidation/public/object_id_invalidation_map.h"
#include "components/sync_driver/invalidation_adapter.h"
Expand Down Expand Up @@ -38,6 +40,10 @@ namespace syncer {
class InternalComponentsFactory;
} // namespace syncer

namespace net {
class URLFetcher;
}

namespace {

// Enums for UMAs.
Expand All @@ -49,6 +55,11 @@ enum SyncBackendInitState {
SYNC_BACKEND_INIT_STATE_COUNT
};

void BindFetcherToDataTracker(net::URLFetcher* fetcher) {
data_use_measurement::DataUseUserData::AttachToFetcher(
fetcher, data_use_measurement::DataUseUserData::SYNC);
}

} // namespace

namespace browser_sync {
Expand Down Expand Up @@ -425,7 +436,8 @@ void SyncBackendHostCore::DoInitialize(

// Finish initializing the HttpBridgeFactory. We do this here because
// building the user agent may block on some platforms.
options->http_bridge_factory->Init(options->sync_user_agent);
options->http_bridge_factory->Init(options->sync_user_agent,
base::Bind(&BindFetcherToDataTracker));

// Blow away the partial or corrupt sync data folder before doing any more
// initialization, if necessary.
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/sync/test/test_http_bridge_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ TestHttpBridgeFactory::TestHttpBridgeFactory() {}

TestHttpBridgeFactory::~TestHttpBridgeFactory() {}

void TestHttpBridgeFactory::Init(const std::string& user_agent) {}
void TestHttpBridgeFactory::Init(
const std::string& user_agent,
const syncer::BindToTrackerCallback& bind_to_tracker_callback) {}

syncer::HttpPostProviderInterface* TestHttpBridgeFactory::Create() {
return new TestHttpBridge();
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/sync/test/test_http_bridge_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class TestHttpBridgeFactory : public syncer::HttpPostProviderFactory {
~TestHttpBridgeFactory() override;

// syncer::HttpPostProviderFactory:
void Init(const std::string& user_agent) override;
void Init(
const std::string& user_agent,
const syncer::BindToTrackerCallback& bind_to_tracker_callback) override;
syncer::HttpPostProviderInterface* Create() override;
void Destroy(syncer::HttpPostProviderInterface* http) override;
};
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_browser.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -3121,6 +3121,7 @@
'../components/components.gyp:content_settings_core_common',
'../components/components.gyp:crx_file',
'../components/components.gyp:data_reduction_proxy_core_browser',
'../components/components.gyp:data_use_measurement_core',
'../components/components.gyp:domain_reliability',
'../components/components.gyp:enhanced_bookmarks',
'../components/components.gyp:favicon_base',
Expand Down
1 change: 1 addition & 0 deletions components/autofill.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
'autofill_core_common',
'components_resources.gyp:components_resources',
'components_strings.gyp:components_strings',
'data_use_measurement_core',
'infobars_core',
'keyed_service_core',
'os_crypt',
Expand Down
1 change: 1 addition & 0 deletions components/autofill/core/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ source_set("browser") {
"//base:i18n",
"//base:prefs",
"//components/autofill/core/common",
"//components/data_use_measurement/core",
"//components/infobars/core",
"//components/keyed_service/core",
"//components/os_crypt",
Expand Down
1 change: 1 addition & 0 deletions components/autofill/core/browser/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+components/data_use_measurement/core",
"+components/infobars/core",
"+components/keyed_service/core",
"+components/signin/core/browser",
Expand Down
3 changes: 3 additions & 0 deletions components/autofill/core/browser/autofill_download_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "components/autofill/core/browser/autofill_xml_parser.h"
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/common/autofill_pref_names.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/variations/net/variations_http_header_provider.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
Expand Down Expand Up @@ -183,6 +184,8 @@ bool AutofillDownloadManager::StartRequest(
net::URLFetcher* fetcher =
net::URLFetcher::Create(fetcher_id_for_unittest_++, request_url,
net::URLFetcher::POST, this).release();
data_use_measurement::DataUseUserData::AttachToFetcher(
fetcher, data_use_measurement::DataUseUserData::AUTOFILL);
url_fetchers_[fetcher] = request_data;
fetcher->SetAutomaticallyRetryOn5xx(false);
fetcher->SetRequestContext(request_context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/values.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/common/autofill_switches.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "google_apis/gaia/identity_provider.h"
#include "net/base/escape.h"
#include "net/base/load_flags.h"
Expand Down Expand Up @@ -218,6 +219,8 @@ void RealPanWalletClient::OnGetTokenFailure(
void RealPanWalletClient::CreateRequest() {
request_ = net::URLFetcher::Create(0, GetUnmaskCardRequestUrl(),
net::URLFetcher::POST, this);
data_use_measurement::DataUseUserData::AttachToFetcher(
request_.get(), data_use_measurement::DataUseUserData::AUTOFILL);
request_->SetRequestContext(context_getter_.get());
request_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DISABLE_CACHE);
Expand Down
26 changes: 26 additions & 0 deletions components/data_use_measurement/core/data_use_user_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ std::string DataUseUserData::GetServiceNameAsString(ServiceName service_name) {
return "Suggestions";
case NOT_TAGGED:
return "NotTagged";
case TRANSLATE:
return "Translate";
case SYNC:
return "Sync";
case OMNIBOX:
return "Omnibox";
case INVALIDATION:
return "Invalidation";
case RAPPOR:
return "Rappor";
case VARIATIONS:
return "Variations";
case UMA:
return "UMA";
case DOMAIN_RELIABILITY:
return "DomainReliability";
case PROFILE_DOWNLOADER:
return "ProfileDownloader";
case GOOGLE_URL_TRACKER:
return "GoogleURLTracker";
case AUTOFILL:
return "Autofill";
case POLICY:
return "Policy";
case SPELL_CHECKER:
return "SpellChecker";
}
return "INVALID";
}
Expand Down
13 changes: 13 additions & 0 deletions components/data_use_measurement/core/data_use_user_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ class DataUseUserData : public base::SupportsUserData::Data {
enum ServiceName {
NOT_TAGGED,
SUGGESTIONS,
TRANSLATE,
SYNC,
OMNIBOX,
INVALIDATION,
RAPPOR,
VARIATIONS,
UMA,
DOMAIN_RELIABILITY,
PROFILE_DOWNLOADER,
GOOGLE_URL_TRACKER,
AUTOFILL,
POLICY,
SPELL_CHECKER,
};

explicit DataUseUserData(ServiceName service_name);
Expand Down
1 change: 1 addition & 0 deletions components/domain_reliability.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'dependencies': [
'../base/base.gyp:base',
'../base/base.gyp:base_prefs',
'../components/components.gyp:data_use_measurement_core',
'../components/components.gyp:keyed_service_core',
'../content/content.gyp:content_browser',
'../net/net.gyp:net',
Expand Down
1 change: 1 addition & 0 deletions components/domain_reliability/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ component("domain_reliability") {
deps = [
":bake_in_configs",
"//base",
"//components/data_use_measurement/core",
"//components/keyed_service/core",
"//content/public/browser",
"//net",
Expand Down
1 change: 1 addition & 0 deletions components/domain_reliability/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

include_rules = [
"+net",
"+components/data_use_measurement/core",
"+components/keyed_service/core",
]

3 changes: 3 additions & 0 deletions components/domain_reliability/uploader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/metrics/sparse_histogram.h"
#include "base/stl_util.h"
#include "base/supports_user_data.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/domain_reliability/util.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
Expand Down Expand Up @@ -77,6 +78,8 @@ class DomainReliabilityUploaderImpl
net::URLFetcher* fetcher =
net::URLFetcher::Create(0, upload_url, net::URLFetcher::POST, this)
.release();
data_use_measurement::DataUseUserData::AttachToFetcher(
fetcher, data_use_measurement::DataUseUserData::DOMAIN_RELIABILITY);
fetcher->SetRequestContext(url_request_context_getter_.get());
fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES);
Expand Down
1 change: 1 addition & 0 deletions components/google.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'../net/net.gyp:net',
'../url/url.gyp:url_lib',
'components_strings.gyp:components_strings',
'data_use_measurement_core',
'keyed_service_core',
'pref_registry',
'url_formatter/url_formatter.gyp:url_formatter',
Expand Down
1 change: 1 addition & 0 deletions components/google/core/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static_library("browser") {
deps = [
"//base",
"//base:prefs",
"//components/data_use_measurement/core",
"//components/keyed_service/core",
"//components/pref_registry",
"//components/strings",
Expand Down
1 change: 1 addition & 0 deletions components/google/core/browser/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+components/data_use_measurement/core",
"+components/keyed_service/core",
"+components/pref_registry",
]
4 changes: 4 additions & 0 deletions components/google/core/browser/google_url_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "base/thread_task_runner_handle.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/google/core/browser/google_pref_names.h"
#include "components/google/core/browser/google_switches.h"
#include "components/google/core/browser/google_util.h"
Expand Down Expand Up @@ -163,6 +164,9 @@ void GoogleURLTracker::StartFetchIfDesirable() {
already_fetched_ = true;
fetcher_ = net::URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL),
net::URLFetcher::GET, this);
data_use_measurement::DataUseUserData::AttachToFetcher(
fetcher_.get(),
data_use_measurement::DataUseUserData::GOOGLE_URL_TRACKER);
++fetcher_id_;
// We don't want this fetch to set new entries in the cache or cookies, lest
// we alarm the user.
Expand Down
1 change: 1 addition & 0 deletions components/invalidation.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'../google_apis/google_apis.gyp:google_apis',
'../jingle/jingle.gyp:notifier',
'../third_party/cacheinvalidation/cacheinvalidation.gyp:cacheinvalidation_proto_cpp',
'data_use_measurement_core',
'gcm_driver',
'keyed_service_core',
'pref_registry',
Expand Down
1 change: 1 addition & 0 deletions components/invalidation/impl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ source_set("impl") {
"//base",
"//base:i18n",
"//base:prefs",
"//components/data_use_measurement/core",
"//components/gcm_driver",
"//components/keyed_service/core",
"//components/pref_registry",
Expand Down
1 change: 1 addition & 0 deletions components/invalidation/impl/DEPS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include_rules = [
"+components/invalidation/public",

"+components/data_use_measurement/core",
"+components/gcm_driver",
"+components/keyed_service",
"+components/pref_registry",
Expand Down
3 changes: 3 additions & 0 deletions components/invalidation/impl/gcm_network_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "google/cacheinvalidation/channel_common.pb.h"
#include "google/cacheinvalidation/types.pb.h"
#endif
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/invalidation/impl/gcm_network_channel.h"
#include "components/invalidation/impl/gcm_network_channel_delegate.h"
#include "google_apis/gaia/google_service_auth_error.h"
Expand Down Expand Up @@ -211,6 +212,8 @@ void GCMNetworkChannel::OnGetTokenComplete(
DVLOG(2) << "Got access token, sending message";
fetcher_ = net::URLFetcher::Create(BuildUrl(registration_id_),
net::URLFetcher::POST, this);
data_use_measurement::DataUseUserData::AttachToFetcher(
fetcher_.get(), data_use_measurement::DataUseUserData::INVALIDATION);
fetcher_->SetRequestContext(request_context_getter_.get());
const std::string auth_header("Authorization: Bearer " + access_token_);
fetcher_->AddExtraRequestHeader(auth_header);
Expand Down
Loading

0 comments on commit aa789c8

Please sign in to comment.