summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authoramohammadkhan <amohammadkhan@google.com>2015-09-14 10:34:43 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-14 17:35:19 +0000
commitf76ae11f25dc0056cea63e15c16039fdbd5f3470 (patch)
treefd1285923858b8b5ed211c405aefd9ec9cb98106 /sync
parent7ba3d6825c0bb7ce3eee3b4fae4a3fa7325d5e11 (diff)
downloadchromium_src-f76ae11f25dc0056cea63e15c16039fdbd5f3470.zip
chromium_src-f76ae11f25dc0056cea63e15c16039fdbd5f3470.tar.gz
chromium_src-f76ae11f25dc0056cea63e15c16039fdbd5f3470.tar.bz2
Report data usage UMA for Chrome services
This issue has the same goals as issue 1330443002( It was reverted because it breaded compile on multiple bots). 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,pkasting@chromium.org,sclittle@chromium.org,thestig@chromium.org,isherman@chromium.org,rouslan@chromium.org,nyquist@chromium.org,bengr@chromium.org,asvltkine@chromium.org,zea@chromium.org,mmenke@chromium.org BUG=527304 Review URL: https://codereview.chromium.org/1336333003 Cr-Commit-Position: refs/heads/master@{#348645}
Diffstat (limited to 'sync')
-rw-r--r--sync/internal_api/http_bridge.cc19
-rw-r--r--sync/internal_api/http_bridge_unittest.cc20
-rw-r--r--sync/internal_api/public/http_bridge.h14
-rw-r--r--sync/internal_api/public/http_post_provider_factory.h10
-rw-r--r--sync/internal_api/sync_manager_impl_unittest.cc3
-rw-r--r--sync/internal_api/syncapi_server_connection_manager_unittest.cc4
-rw-r--r--sync/test/fake_server/fake_server_http_post_provider.cc4
-rw-r--r--sync/test/fake_server/fake_server_http_post_provider.h5
-rw-r--r--sync/tools/sync_client.cc3
9 files changed, 60 insertions, 22 deletions
diff --git a/sync/internal_api/http_bridge.cc b/sync/internal_api/http_bridge.cc
index 04e339c..6da0dd3 100644
--- a/sync/internal_api/http_bridge.cc
+++ b/sync/internal_api/http_bridge.cc
@@ -161,8 +161,11 @@ HttpBridgeFactory::~HttpBridgeFactory() {
cancelation_signal_->UnregisterHandler(this);
}
-void HttpBridgeFactory::Init(const std::string& user_agent) {
+void HttpBridgeFactory::Init(
+ const std::string& user_agent,
+ const BindToTrackerCallback& bind_to_tracker_callback) {
user_agent_ = user_agent;
+ bind_to_tracker_callback_ = bind_to_tracker_callback;
}
HttpPostProviderInterface* HttpBridgeFactory::Create() {
@@ -174,8 +177,9 @@ HttpPostProviderInterface* HttpBridgeFactory::Create() {
// we've been asked to shut down.
CHECK(request_context_getter_.get());
- scoped_refptr<HttpBridge> http = new HttpBridge(
- user_agent_, request_context_getter_, network_time_update_callback_);
+ scoped_refptr<HttpBridge> http =
+ new HttpBridge(user_agent_, request_context_getter_,
+ network_time_update_callback_, bind_to_tracker_callback_);
http->AddRef();
return http.get();
}
@@ -204,14 +208,15 @@ HttpBridge::URLFetchState::~URLFetchState() {}
HttpBridge::HttpBridge(
const std::string& user_agent,
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
- const NetworkTimeUpdateCallback& network_time_update_callback)
+ const NetworkTimeUpdateCallback& network_time_update_callback,
+ const BindToTrackerCallback& bind_to_tracker_callback)
: created_on_loop_(base::MessageLoop::current()),
user_agent_(user_agent),
http_post_completed_(false, false),
request_context_getter_(context_getter),
network_task_runner_(request_context_getter_->GetNetworkTaskRunner()),
- network_time_update_callback_(network_time_update_callback) {
-}
+ network_time_update_callback_(network_time_update_callback),
+ bind_to_tracker_callback_(bind_to_tracker_callback) {}
HttpBridge::~HttpBridge() {
}
@@ -313,6 +318,8 @@ void HttpBridge::MakeAsynchronousPost() {
fetch_state_.url_poster =
net::URLFetcher::Create(url_for_request_, net::URLFetcher::POST, this)
.release();
+ if (!bind_to_tracker_callback_.is_null())
+ bind_to_tracker_callback_.Run(fetch_state_.url_poster);
fetch_state_.url_poster->SetRequestContext(request_context_getter_.get());
fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_);
diff --git a/sync/internal_api/http_bridge_unittest.cc b/sync/internal_api/http_bridge_unittest.cc
index 4ea4e70..7c6fe822 100644
--- a/sync/internal_api/http_bridge_unittest.cc
+++ b/sync/internal_api/http_bridge_unittest.cc
@@ -14,6 +14,7 @@
#include "net/url_request/url_request_test_util.h"
#include "sync/internal_api/public/base/cancelation_signal.h"
#include "sync/internal_api/public/http_bridge.h"
+#include "sync/internal_api/public/http_post_provider_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/zlib/zlib.h"
@@ -144,9 +145,8 @@ class MAYBE_SyncHttpBridgeTest : public testing::Test {
fake_default_request_context_getter_->AddRef();
}
HttpBridge* bridge =
- new HttpBridge(kUserAgent,
- fake_default_request_context_getter_,
- NetworkTimeUpdateCallback());
+ new HttpBridge(kUserAgent, fake_default_request_context_getter_,
+ NetworkTimeUpdateCallback(), BindToTrackerCallback());
return bridge;
}
@@ -207,11 +207,15 @@ class ShuntedHttpBridge : public HttpBridge {
// If |never_finishes| is true, the simulated request never actually
// returns.
ShuntedHttpBridge(net::URLRequestContextGetter* baseline_context_getter,
- MAYBE_SyncHttpBridgeTest* test, bool never_finishes)
+ MAYBE_SyncHttpBridgeTest* test,
+ bool never_finishes)
: HttpBridge(kUserAgent,
baseline_context_getter,
- NetworkTimeUpdateCallback()),
- test_(test), never_finishes_(never_finishes) { }
+ NetworkTimeUpdateCallback(),
+ BindToTrackerCallback()),
+ test_(test),
+ never_finishes_(never_finishes) {}
+
protected:
void MakeAsynchronousPost() override {
ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop());
@@ -579,7 +583,7 @@ void HttpBridgeRunOnSyncThread(
new syncer::HttpBridgeFactory(baseline_context_getter,
NetworkTimeUpdateCallback(),
factory_cancelation_signal));
- bridge_factory->Init("test");
+ bridge_factory->Init("test", BindToTrackerCallback());
*bridge_factory_out = bridge_factory.get();
HttpPostProviderInterface* bridge = bridge_factory->Create();
@@ -673,7 +677,7 @@ TEST_F(MAYBE_SyncHttpBridgeTest, EarlyAbortFactory) {
// Sync thread: Finally run the posted task, only to find that our
// HttpBridgeFactory has been neutered. Should not crash.
- factory->Init("TestUserAgent");
+ factory->Init("TestUserAgent", BindToTrackerCallback());
// At this point, attempting to use the factory would trigger a crash. Both
// this test and the real world code should make sure this never happens.
diff --git a/sync/internal_api/public/http_bridge.h b/sync/internal_api/public/http_bridge.h
index 36704e2..73e68a52 100644
--- a/sync/internal_api/public/http_bridge.h
+++ b/sync/internal_api/public/http_bridge.h
@@ -54,7 +54,8 @@ class SYNC_EXPORT_PRIVATE HttpBridge
public:
HttpBridge(const std::string& user_agent,
const scoped_refptr<net::URLRequestContextGetter>& context,
- const NetworkTimeUpdateCallback& network_time_update_callback);
+ const NetworkTimeUpdateCallback& network_time_update_callback,
+ const BindToTrackerCallback& bind_to_tracker_callback);
// HttpPostProvider implementation.
void SetExtraRequestHeaders(const char* headers) override;
@@ -180,6 +181,10 @@ class SYNC_EXPORT_PRIVATE HttpBridge
// Callback for updating network time.
NetworkTimeUpdateCallback network_time_update_callback_;
+ // A callback to tag Sync request to be able to record data use of this
+ // service by data_use_measurement component.
+ BindToTrackerCallback bind_to_tracker_callback_;
+
DISALLOW_COPY_AND_ASSIGN(HttpBridge);
};
@@ -194,7 +199,8 @@ class SYNC_EXPORT HttpBridgeFactory : public HttpPostProviderFactory,
~HttpBridgeFactory() override;
// HttpPostProviderFactory:
- void Init(const std::string& user_agent) override;
+ void Init(const std::string& user_agent,
+ const BindToTrackerCallback& bind_to_tracker_callback) override;
HttpPostProviderInterface* Create() override;
void Destroy(HttpPostProviderInterface* http) override;
@@ -216,6 +222,10 @@ class SYNC_EXPORT HttpBridgeFactory : public HttpPostProviderFactory,
CancelationSignal* const cancelation_signal_;
+ // A callback to tag Sync request to be able to record data use of this
+ // service by data_use_measurement component.
+ BindToTrackerCallback bind_to_tracker_callback_;
+
DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory);
};
diff --git a/sync/internal_api/public/http_post_provider_factory.h b/sync/internal_api/public/http_post_provider_factory.h
index 9346651..ef6af9b 100644
--- a/sync/internal_api/public/http_post_provider_factory.h
+++ b/sync/internal_api/public/http_post_provider_factory.h
@@ -7,10 +7,17 @@
#include <string>
+#include "base/callback.h"
#include "sync/base/sync_export.h"
+namespace net {
+class URLFetcher;
+}
+
namespace syncer {
+typedef base::Callback<void(net::URLFetcher*)> BindToTrackerCallback;
+
class HttpPostProviderInterface;
// A factory to create HttpPostProviders to hide details about the
@@ -21,7 +28,8 @@ class SYNC_EXPORT HttpPostProviderFactory {
public:
virtual ~HttpPostProviderFactory() {}
- virtual void Init(const std::string& user_agent) = 0;
+ virtual void Init(const std::string& user_agent,
+ const BindToTrackerCallback& bind_to_tracker_callback) = 0;
// Obtain a new HttpPostProviderInterface instance, owned by caller.
virtual HttpPostProviderInterface* Create() = 0;
diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc
index 04b97b5..27791ff 100644
--- a/sync/internal_api/sync_manager_impl_unittest.cc
+++ b/sync/internal_api/sync_manager_impl_unittest.cc
@@ -801,7 +801,8 @@ class TestHttpPostProviderInterface : public HttpPostProviderInterface {
class TestHttpPostProviderFactory : public HttpPostProviderFactory {
public:
~TestHttpPostProviderFactory() override {}
- void Init(const std::string& user_agent) override {}
+ void Init(const std::string& user_agent,
+ const BindToTrackerCallback& bind_to_tracker_callback) override {}
HttpPostProviderInterface* Create() override {
return new TestHttpPostProviderInterface();
}
diff --git a/sync/internal_api/syncapi_server_connection_manager_unittest.cc b/sync/internal_api/syncapi_server_connection_manager_unittest.cc
index 10dc311..e438ac1 100644
--- a/sync/internal_api/syncapi_server_connection_manager_unittest.cc
+++ b/sync/internal_api/syncapi_server_connection_manager_unittest.cc
@@ -51,7 +51,9 @@ class BlockingHttpPost : public HttpPostProviderInterface {
class BlockingHttpPostFactory : public HttpPostProviderFactory {
public:
~BlockingHttpPostFactory() override {}
- void Init(const std::string& user_agent) override {}
+ void Init(const std::string& user_agent,
+ const BindToTrackerCallback& bind_to_tracker_callback) override {}
+
HttpPostProviderInterface* Create() override {
return new BlockingHttpPost();
}
diff --git a/sync/test/fake_server/fake_server_http_post_provider.cc b/sync/test/fake_server/fake_server_http_post_provider.cc
index 75c5d46e..7a844b9 100644
--- a/sync/test/fake_server/fake_server_http_post_provider.cc
+++ b/sync/test/fake_server/fake_server_http_post_provider.cc
@@ -26,7 +26,9 @@ FakeServerHttpPostProviderFactory::FakeServerHttpPostProviderFactory(
FakeServerHttpPostProviderFactory::~FakeServerHttpPostProviderFactory() { }
-void FakeServerHttpPostProviderFactory::Init(const std::string& user_agent) { }
+void FakeServerHttpPostProviderFactory::Init(
+ const std::string& user_agent,
+ const syncer::BindToTrackerCallback& bind_to_tracker_callback) {}
HttpPostProviderInterface* FakeServerHttpPostProviderFactory::Create() {
FakeServerHttpPostProvider* http =
diff --git a/sync/test/fake_server/fake_server_http_post_provider.h b/sync/test/fake_server/fake_server_http_post_provider.h
index 593be1d..3ee4d42 100644
--- a/sync/test/fake_server/fake_server_http_post_provider.h
+++ b/sync/test/fake_server/fake_server_http_post_provider.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
@@ -70,7 +71,9 @@ class FakeServerHttpPostProviderFactory
~FakeServerHttpPostProviderFactory() override;
// 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;
diff --git a/sync/tools/sync_client.cc b/sync/tools/sync_client.cc
index 2ec1f19..5999e11 100644
--- a/sync/tools/sync_client.cc
+++ b/sync/tools/sync_client.cc
@@ -34,6 +34,7 @@
#include "sync/internal_api/public/base_node.h"
#include "sync/internal_api/public/engine/passive_model_worker.h"
#include "sync/internal_api/public/http_bridge.h"
+#include "sync/internal_api/public/http_post_provider_factory.h"
#include "sync/internal_api/public/internal_components_factory_impl.h"
#include "sync/internal_api/public/read_node.h"
#include "sync/internal_api/public/sync_manager.h"
@@ -405,7 +406,7 @@ int SyncClientMain(int argc, char* argv[]) {
new HttpBridgeFactory(context_getter.get(),
base::Bind(&StubNetworkTimeUpdateCallback),
&factory_cancelation_signal));
- post_factory->Init(kUserAgent);
+ post_factory->Init(kUserAgent, BindToTrackerCallback());
// Used only when committing bookmarks, so it's okay to leave this
// as NULL.
ExtensionsActivity* extensions_activity = NULL;