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

Side by Side Diff: sync/internal_api/http_bridge.cc

Issue 1330443002: Report data usage UMA for Chrome services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NewArchServices
Patch Set: Fix calling Init function in sync_client.cc Created 5 years, 3 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "sync/internal_api/public/http_bridge.h" 5 #include "sync/internal_api/public/http_bridge.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // init. It would be impossible for a shutdown to have been requested at this 154 // init. It would be impossible for a shutdown to have been requested at this
155 // point. 155 // point.
156 bool result = cancelation_signal_->TryRegisterHandler(this); 156 bool result = cancelation_signal_->TryRegisterHandler(this);
157 DCHECK(result); 157 DCHECK(result);
158 } 158 }
159 159
160 HttpBridgeFactory::~HttpBridgeFactory() { 160 HttpBridgeFactory::~HttpBridgeFactory() {
161 cancelation_signal_->UnregisterHandler(this); 161 cancelation_signal_->UnregisterHandler(this);
162 } 162 }
163 163
164 void HttpBridgeFactory::Init(const std::string& user_agent) { 164 void HttpBridgeFactory::Init(
165 const std::string& user_agent,
166 const BindToTrackerCallback& bind_to_tracker_callback) {
165 user_agent_ = user_agent; 167 user_agent_ = user_agent;
168 bind_to_tracker_callback_ = bind_to_tracker_callback;
166 } 169 }
167 170
168 HttpPostProviderInterface* HttpBridgeFactory::Create() { 171 HttpPostProviderInterface* HttpBridgeFactory::Create() {
169 base::AutoLock lock(request_context_getter_lock_); 172 base::AutoLock lock(request_context_getter_lock_);
170 173
171 // If we've been asked to shut down (something which may happen asynchronously 174 // If we've been asked to shut down (something which may happen asynchronously
172 // and at pretty much any time), then we won't have a request_context_getter_. 175 // and at pretty much any time), then we won't have a request_context_getter_.
173 // Some external mechanism must ensure that this function is not called after 176 // Some external mechanism must ensure that this function is not called after
174 // we've been asked to shut down. 177 // we've been asked to shut down.
175 CHECK(request_context_getter_.get()); 178 CHECK(request_context_getter_.get());
176 179
177 scoped_refptr<HttpBridge> http = new HttpBridge( 180 scoped_refptr<HttpBridge> http =
178 user_agent_, request_context_getter_, network_time_update_callback_); 181 new HttpBridge(user_agent_, request_context_getter_,
182 network_time_update_callback_, bind_to_tracker_callback_);
179 http->AddRef(); 183 http->AddRef();
180 return http.get(); 184 return http.get();
181 } 185 }
182 186
183 void HttpBridgeFactory::Destroy(HttpPostProviderInterface* http) { 187 void HttpBridgeFactory::Destroy(HttpPostProviderInterface* http) {
184 static_cast<HttpBridge*>(http)->Release(); 188 static_cast<HttpBridge*>(http)->Release();
185 } 189 }
186 190
187 void HttpBridgeFactory::OnSignalReceived() { 191 void HttpBridgeFactory::OnSignalReceived() {
188 base::AutoLock lock(request_context_getter_lock_); 192 base::AutoLock lock(request_context_getter_lock_);
189 // Release |request_context_getter_| as soon as possible so that it 193 // Release |request_context_getter_| as soon as possible so that it
190 // is destroyed in the right order on its network task runner. 194 // is destroyed in the right order on its network task runner.
191 request_context_getter_ = NULL; 195 request_context_getter_ = NULL;
192 } 196 }
193 197
194 HttpBridge::URLFetchState::URLFetchState() 198 HttpBridge::URLFetchState::URLFetchState()
195 : url_poster(NULL), 199 : url_poster(NULL),
196 aborted(false), 200 aborted(false),
197 request_completed(false), 201 request_completed(false),
198 request_succeeded(false), 202 request_succeeded(false),
199 http_response_code(-1), 203 http_response_code(-1),
200 error_code(-1) { 204 error_code(-1) {
201 } 205 }
202 HttpBridge::URLFetchState::~URLFetchState() {} 206 HttpBridge::URLFetchState::~URLFetchState() {}
203 207
204 HttpBridge::HttpBridge( 208 HttpBridge::HttpBridge(
205 const std::string& user_agent, 209 const std::string& user_agent,
206 const scoped_refptr<net::URLRequestContextGetter>& context_getter, 210 const scoped_refptr<net::URLRequestContextGetter>& context_getter,
207 const NetworkTimeUpdateCallback& network_time_update_callback) 211 const NetworkTimeUpdateCallback& network_time_update_callback,
212 const BindToTrackerCallback& bind_to_tracker_callback)
208 : created_on_loop_(base::MessageLoop::current()), 213 : created_on_loop_(base::MessageLoop::current()),
209 user_agent_(user_agent), 214 user_agent_(user_agent),
210 http_post_completed_(false, false), 215 http_post_completed_(false, false),
211 request_context_getter_(context_getter), 216 request_context_getter_(context_getter),
212 network_task_runner_(request_context_getter_->GetNetworkTaskRunner()), 217 network_task_runner_(request_context_getter_->GetNetworkTaskRunner()),
213 network_time_update_callback_(network_time_update_callback) { 218 network_time_update_callback_(network_time_update_callback),
214 } 219 bind_to_tracker_callback_(bind_to_tracker_callback) {}
215 220
216 HttpBridge::~HttpBridge() { 221 HttpBridge::~HttpBridge() {
217 } 222 }
218 223
219 void HttpBridge::SetExtraRequestHeaders(const char * headers) { 224 void HttpBridge::SetExtraRequestHeaders(const char * headers) {
220 DCHECK(extra_headers_.empty()) 225 DCHECK(extra_headers_.empty())
221 << "HttpBridge::SetExtraRequestHeaders called twice."; 226 << "HttpBridge::SetExtraRequestHeaders called twice.";
222 extra_headers_.assign(headers); 227 extra_headers_.assign(headers);
223 } 228 }
224 229
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 fetch_state_.http_request_timeout_timer.reset(new base::Timer(false, false)); 311 fetch_state_.http_request_timeout_timer.reset(new base::Timer(false, false));
307 fetch_state_.http_request_timeout_timer->Start( 312 fetch_state_.http_request_timeout_timer->Start(
308 FROM_HERE, base::TimeDelta::FromSeconds(kMaxHttpRequestTimeSeconds), 313 FROM_HERE, base::TimeDelta::FromSeconds(kMaxHttpRequestTimeSeconds),
309 base::Bind(&HttpBridge::OnURLFetchTimedOut, this)); 314 base::Bind(&HttpBridge::OnURLFetchTimedOut, this));
310 315
311 DCHECK(request_context_getter_.get()); 316 DCHECK(request_context_getter_.get());
312 fetch_state_.start_time = base::Time::Now(); 317 fetch_state_.start_time = base::Time::Now();
313 fetch_state_.url_poster = 318 fetch_state_.url_poster =
314 net::URLFetcher::Create(url_for_request_, net::URLFetcher::POST, this) 319 net::URLFetcher::Create(url_for_request_, net::URLFetcher::POST, this)
315 .release(); 320 .release();
321 if (!bind_to_tracker_callback_.is_null())
322 bind_to_tracker_callback_.Run(fetch_state_.url_poster);
316 fetch_state_.url_poster->SetRequestContext(request_context_getter_.get()); 323 fetch_state_.url_poster->SetRequestContext(request_context_getter_.get());
317 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_); 324 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_);
318 325
319 int64 compressed_content_size = 0; 326 int64 compressed_content_size = 0;
320 if (IsSyncHttpContentCompressionEnabled()) { 327 if (IsSyncHttpContentCompressionEnabled()) {
321 std::string compressed_request_content; 328 std::string compressed_request_content;
322 GzipCompress(request_content_, &compressed_request_content); 329 GzipCompress(request_content_, &compressed_request_content);
323 compressed_content_size = compressed_request_content.size(); 330 compressed_content_size = compressed_request_content.size();
324 fetch_state_.url_poster->SetUploadData(content_type_, 331 fetch_state_.url_poster->SetUploadData(content_type_,
325 compressed_request_content); 332 compressed_request_content);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 int64 sane_time_ms = 0; 533 int64 sane_time_ms = 0;
527 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { 534 if (base::StringToInt64(sane_time_str, &sane_time_ms)) {
528 network_time_update_callback_.Run( 535 network_time_update_callback_.Run(
529 base::Time::FromJsTime(sane_time_ms), 536 base::Time::FromJsTime(sane_time_ms),
530 base::TimeDelta::FromMilliseconds(1), 537 base::TimeDelta::FromMilliseconds(1),
531 fetch_state_.end_time - fetch_state_.start_time); 538 fetch_state_.end_time - fetch_state_.start_time);
532 } 539 }
533 } 540 }
534 541
535 } // namespace syncer 542 } // namespace syncer
OLDNEW
« no previous file with comments | « components/variations/service/variations_service.cc ('k') | sync/internal_api/http_bridge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698