Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "components/sync/engine_impl/attachments/attachment_uploader_impl.h" | 5 #include "components/sync/engine_impl/attachments/attachment_uploader_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/base64url.h" | 11 #include "base/base64url.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/sys_byteorder.h" | 19 #include "base/sys_byteorder.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "components/data_use_measurement/core/data_use_user_data.h" | 21 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 22 #include "components/sync/model/attachments/attachment.h" | 22 #include "components/sync/model/attachments/attachment.h" |
| 23 #include "components/sync/protocol/sync.pb.h" | 23 #include "components/sync/protocol/sync.pb.h" |
| 24 #include "google_apis/gaia/gaia_constants.h" | 24 #include "google_apis/gaia/gaia_constants.h" |
| 25 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
| 26 #include "net/http/http_status_code.h" | 26 #include "net/http/http_status_code.h" |
| 27 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 27 #include "net/url_request/url_fetcher.h" | 28 #include "net/url_request/url_fetcher.h" |
| 28 #include "net/url_request/url_fetcher_delegate.h" | 29 #include "net/url_request/url_fetcher_delegate.h" |
| 29 #include "net/url_request/url_request_status.h" | 30 #include "net/url_request/url_request_status.h" |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 const char kContentType[] = "application/octet-stream"; | 34 const char kContentType[] = "application/octet-stream"; |
| 34 const char kAttachments[] = "attachments/"; | 35 const char kAttachments[] = "attachments/"; |
| 35 const char kSyncStoreBirthday[] = "X-Sync-Store-Birthday"; | 36 const char kSyncStoreBirthday[] = "X-Sync-Store-Birthday"; |
| 36 const char kSyncDataTypeId[] = "X-Sync-Data-Type-Id"; | 37 const char kSyncDataTypeId[] = "X-Sync-Data-Type-Id"; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 const std::string& access_token, | 208 const std::string& access_token, |
| 208 const base::Time& expiration_time) { | 209 const base::Time& expiration_time) { |
| 209 DCHECK(CalledOnValidThread()); | 210 DCHECK(CalledOnValidThread()); |
| 210 if (is_stopped_) { | 211 if (is_stopped_) { |
| 211 return; | 212 return; |
| 212 } | 213 } |
| 213 | 214 |
| 214 DCHECK_EQ(access_token_request_.get(), request); | 215 DCHECK_EQ(access_token_request_.get(), request); |
| 215 access_token_request_.reset(); | 216 access_token_request_.reset(); |
| 216 access_token_ = access_token; | 217 access_token_ = access_token; |
| 217 fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::POST, this); | 218 net::NetworkTrafficAnnotationTag traffic_annotation = |
|
Nicolas Zea
2017/03/03 22:39:56
same as the http bridge
Ramin Halavati
2017/03/06 06:55:45
Done.
| |
| 219 net::DefineNetworkTrafficAnnotation("...", R"( | |
| 220 semantics { | |
| 221 sender: "..." | |
| 222 description: "..." | |
| 223 trigger: "..." | |
| 224 data: "..." | |
| 225 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
| 226 } | |
| 227 policy { | |
| 228 cookies_allowed: false/true | |
| 229 cookies_store: "..." | |
| 230 setting: "..." | |
| 231 policy { | |
| 232 [POLICY_NAME] { | |
| 233 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
| 234 value: ... | |
| 235 } | |
| 236 } | |
| 237 policy_exception_justification: "..." | |
| 238 })"); | |
| 239 fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::POST, this, | |
| 240 traffic_annotation); | |
| 218 ConfigureURLFetcherCommon(fetcher_.get(), access_token_, raw_store_birthday_, | 241 ConfigureURLFetcherCommon(fetcher_.get(), access_token_, raw_store_birthday_, |
| 219 model_type_, url_request_context_getter_.get()); | 242 model_type_, url_request_context_getter_.get()); |
| 220 data_use_measurement::DataUseUserData::AttachToFetcher( | 243 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 221 fetcher_.get(), data_use_measurement::DataUseUserData::SYNC); | 244 fetcher_.get(), data_use_measurement::DataUseUserData::SYNC); |
| 222 const uint32_t crc32c = attachment_.GetCrc32c(); | 245 const uint32_t crc32c = attachment_.GetCrc32c(); |
| 223 fetcher_->AddExtraRequestHeader(base::StringPrintf( | 246 fetcher_->AddExtraRequestHeader(base::StringPrintf( |
| 224 "X-Goog-Hash: crc32c=%s", FormatCrc32cHash(crc32c).c_str())); | 247 "X-Goog-Hash: crc32c=%s", FormatCrc32cHash(crc32c).c_str())); |
| 225 | 248 |
| 226 // TODO(maniscalco): Is there a better way? Copying the attachment data into | 249 // TODO(maniscalco): Is there a better way? Copying the attachment data into |
| 227 // a string feels wrong given how large attachments may be (several MBs). If | 250 // a string feels wrong given how large attachments may be (several MBs). If |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 "%s: %s", kSyncStoreBirthday, encoded_store_birthday.c_str())); | 414 "%s: %s", kSyncStoreBirthday, encoded_store_birthday.c_str())); |
| 392 | 415 |
| 393 // Use field number to pass ModelType because it's stable and we have server | 416 // Use field number to pass ModelType because it's stable and we have server |
| 394 // code to decode it. | 417 // code to decode it. |
| 395 const int field_number = GetSpecificsFieldNumberFromModelType(model_type); | 418 const int field_number = GetSpecificsFieldNumberFromModelType(model_type); |
| 396 fetcher->AddExtraRequestHeader( | 419 fetcher->AddExtraRequestHeader( |
| 397 base::StringPrintf("%s: %d", kSyncDataTypeId, field_number)); | 420 base::StringPrintf("%s: %d", kSyncDataTypeId, field_number)); |
| 398 } | 421 } |
| 399 | 422 |
| 400 } // namespace syncer | 423 } // namespace syncer |
| OLD | NEW |