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

Side by Side Diff: sync/internal_api/attachments/attachment_uploader_impl.cc

Issue 1330443002: Report data usage UMA for Chrome services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NewArchServices
Patch Set: Addressing sclittle's comments. 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/attachments/attachment_uploader_impl.h" 5 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/sparse_histogram.h" 12 #include "base/metrics/sparse_histogram.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/sys_byteorder.h" 16 #include "base/sys_byteorder.h"
17 #include "base/threading/non_thread_safe.h" 17 #include "base/threading/non_thread_safe.h"
18 #include "components/data_use_measurement/core/data_use_user_data.h"
18 #include "google_apis/gaia/gaia_constants.h" 19 #include "google_apis/gaia/gaia_constants.h"
19 #include "net/base/load_flags.h" 20 #include "net/base/load_flags.h"
20 #include "net/http/http_status_code.h" 21 #include "net/http/http_status_code.h"
21 #include "net/url_request/url_fetcher.h" 22 #include "net/url_request/url_fetcher.h"
22 #include "net/url_request/url_fetcher_delegate.h" 23 #include "net/url_request/url_fetcher_delegate.h"
23 #include "net/url_request/url_request_status.h" 24 #include "net/url_request/url_request_status.h"
24 #include "sync/api/attachments/attachment.h" 25 #include "sync/api/attachments/attachment.h"
25 #include "sync/protocol/sync.pb.h" 26 #include "sync/protocol/sync.pb.h"
26 27
27 namespace { 28 namespace {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 const base::Time& expiration_time) { 205 const base::Time& expiration_time) {
205 DCHECK(CalledOnValidThread()); 206 DCHECK(CalledOnValidThread());
206 if (is_stopped_) { 207 if (is_stopped_) {
207 return; 208 return;
208 } 209 }
209 210
210 DCHECK_EQ(access_token_request_.get(), request); 211 DCHECK_EQ(access_token_request_.get(), request);
211 access_token_request_.reset(); 212 access_token_request_.reset();
212 access_token_ = access_token; 213 access_token_ = access_token;
213 fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::POST, this); 214 fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::POST, this);
215 data_use_measurement::DataUseUserData::AttachToFetcher(
216 fetcher_.get(), data_use_measurement::DataUseUserData::SYNC);
214 ConfigureURLFetcherCommon(fetcher_.get(), access_token_, raw_store_birthday_, 217 ConfigureURLFetcherCommon(fetcher_.get(), access_token_, raw_store_birthday_,
215 model_type_, url_request_context_getter_.get()); 218 model_type_, url_request_context_getter_.get());
216 219
217 const uint32_t crc32c = attachment_.GetCrc32c(); 220 const uint32_t crc32c = attachment_.GetCrc32c();
218 fetcher_->AddExtraRequestHeader(base::StringPrintf( 221 fetcher_->AddExtraRequestHeader(base::StringPrintf(
219 "X-Goog-Hash: crc32c=%s", FormatCrc32cHash(crc32c).c_str())); 222 "X-Goog-Hash: crc32c=%s", FormatCrc32cHash(crc32c).c_str()));
220 223
221 // TODO(maniscalco): Is there a better way? Copying the attachment data into 224 // TODO(maniscalco): Is there a better way? Copying the attachment data into
222 // a string feels wrong given how large attachments may be (several MBs). If 225 // a string feels wrong given how large attachments may be (several MBs). If
223 // we may end up switching from URLFetcher to URLRequest, this copy won't be 226 // we may end up switching from URLFetcher to URLRequest, this copy won't be
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 397
395 void AttachmentUploaderImpl::Base64URLSafeEncode(const std::string& input, 398 void AttachmentUploaderImpl::Base64URLSafeEncode(const std::string& input,
396 std::string* output) { 399 std::string* output) {
397 base::Base64Encode(input, output); 400 base::Base64Encode(input, output);
398 base::ReplaceChars(*output, "+", "-", output); 401 base::ReplaceChars(*output, "+", "-", output);
399 base::ReplaceChars(*output, "/", "_", output); 402 base::ReplaceChars(*output, "/", "_", output);
400 base::TrimString(*output, "=", output); 403 base::TrimString(*output, "=", output);
401 } 404 }
402 405
403 } // namespace syncer 406 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698