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

Side by Side Diff: components/sync/driver/sync_stopped_reporter.cc

Issue 2539063003: Add data usage tracking for sync service (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/sync/driver/sync_stopped_reporter.h" 5 #include "components/sync/driver/sync_stopped_reporter.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "components/data_use_measurement/core/data_use_user_data.h"
12 #include "components/sync/protocol/sync.pb.h" 13 #include "components/sync/protocol/sync.pb.h"
13 #include "net/base/load_flags.h" 14 #include "net/base/load_flags.h"
14 #include "net/http/http_status_code.h" 15 #include "net/http/http_status_code.h"
15 16
16 namespace { 17 namespace {
17 18
18 const char kEventEndpoint[] = "event"; 19 const char kEventEndpoint[] = "event";
19 20
20 // The request is tiny, so even on poor connections 10 seconds should be 21 // The request is tiny, so even on poor connections 10 seconds should be
21 // plenty of time. Since sync is off when this request is started, we don't 22 // plenty of time. Since sync is off when this request is started, we don't
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 fetcher_->AddExtraRequestHeader(base::StringPrintf( 66 fetcher_->AddExtraRequestHeader(base::StringPrintf(
66 "%s: Bearer %s", net::HttpRequestHeaders::kAuthorization, 67 "%s: Bearer %s", net::HttpRequestHeaders::kAuthorization,
67 access_token.c_str())); 68 access_token.c_str()));
68 fetcher_->AddExtraRequestHeader(base::StringPrintf( 69 fetcher_->AddExtraRequestHeader(base::StringPrintf(
69 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); 70 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str()));
70 fetcher_->SetRequestContext(request_context_.get()); 71 fetcher_->SetRequestContext(request_context_.get());
71 fetcher_->SetUploadData("application/octet-stream", msg); 72 fetcher_->SetUploadData("application/octet-stream", msg);
72 fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | 73 fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE |
73 net::LOAD_DO_NOT_SAVE_COOKIES | 74 net::LOAD_DO_NOT_SAVE_COOKIES |
74 net::LOAD_DO_NOT_SEND_COOKIES); 75 net::LOAD_DO_NOT_SEND_COOKIES);
76 data_use_measurement::DataUseUserData::AttachToFetcher(
77 fetcher_.get(), data_use_measurement::DataUseUserData::SYNC);
75 fetcher_->Start(); 78 fetcher_->Start();
76 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kRequestTimeoutSeconds), 79 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kRequestTimeoutSeconds),
77 this, &SyncStoppedReporter::OnTimeout); 80 this, &SyncStoppedReporter::OnTimeout);
78 } 81 }
79 82
80 void SyncStoppedReporter::OnURLFetchComplete(const net::URLFetcher* source) { 83 void SyncStoppedReporter::OnURLFetchComplete(const net::URLFetcher* source) {
81 Result result = 84 Result result =
82 source->GetResponseCode() == net::HTTP_OK ? RESULT_SUCCESS : RESULT_ERROR; 85 source->GetResponseCode() == net::HTTP_OK ? RESULT_SUCCESS : RESULT_ERROR;
83 fetcher_.reset(); 86 fetcher_.reset();
84 timer_.Stop(); 87 timer_.Stop();
(...skipping 22 matching lines...) Expand all
107 replacements.SetPathStr(path); 110 replacements.SetPathStr(path);
108 return sync_service_url.ReplaceComponents(replacements); 111 return sync_service_url.ReplaceComponents(replacements);
109 } 112 }
110 113
111 void SyncStoppedReporter::SetTimerTaskRunnerForTest( 114 void SyncStoppedReporter::SetTimerTaskRunnerForTest(
112 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { 115 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
113 timer_.SetTaskRunner(task_runner); 116 timer_.SetTaskRunner(task_runner);
114 } 117 }
115 118
116 } // namespace syncer 119 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698