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 = |
| 219 net::DefineNetworkTrafficAnnotation("sync_attachment_uploader", R"( |
| 220 semantics { |
| 221 sender: "Chrome Sync" |
| 222 description: |
| 223 "Chrome Sync synchronizes profile data between Chromium clients " |
| 224 "and Google for a given user account." |
| 225 trigger: |
| 226 "User makes a change to syncable profile data after enabling sync " |
| 227 "on the device." |
| 228 data: |
| 229 "The device and user identifiers, along with any profile data that " |
| 230 "is changing." |
| 231 destination: GOOGLE_OWNED_SERVICE |
| 232 } |
| 233 policy { |
| 234 cookies_allowed: false |
| 235 setting: |
| 236 "Users can disable Chrome Sync by going into the profile settings " |
| 237 "and choosing to Sign Out." |
| 238 chrome_policy { |
| 239 SyncDisabled { |
| 240 policy_options {mode: MANDATORY} |
| 241 SyncDisabled: true |
| 242 } |
| 243 } |
| 244 })"); |
| 245 fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::POST, this, |
| 246 traffic_annotation); |
218 ConfigureURLFetcherCommon(fetcher_.get(), access_token_, raw_store_birthday_, | 247 ConfigureURLFetcherCommon(fetcher_.get(), access_token_, raw_store_birthday_, |
219 model_type_, url_request_context_getter_.get()); | 248 model_type_, url_request_context_getter_.get()); |
220 data_use_measurement::DataUseUserData::AttachToFetcher( | 249 data_use_measurement::DataUseUserData::AttachToFetcher( |
221 fetcher_.get(), data_use_measurement::DataUseUserData::SYNC); | 250 fetcher_.get(), data_use_measurement::DataUseUserData::SYNC); |
222 const uint32_t crc32c = attachment_.GetCrc32c(); | 251 const uint32_t crc32c = attachment_.GetCrc32c(); |
223 fetcher_->AddExtraRequestHeader(base::StringPrintf( | 252 fetcher_->AddExtraRequestHeader(base::StringPrintf( |
224 "X-Goog-Hash: crc32c=%s", FormatCrc32cHash(crc32c).c_str())); | 253 "X-Goog-Hash: crc32c=%s", FormatCrc32cHash(crc32c).c_str())); |
225 | 254 |
226 // TODO(maniscalco): Is there a better way? Copying the attachment data into | 255 // 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 | 256 // 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())); | 420 "%s: %s", kSyncStoreBirthday, encoded_store_birthday.c_str())); |
392 | 421 |
393 // Use field number to pass ModelType because it's stable and we have server | 422 // Use field number to pass ModelType because it's stable and we have server |
394 // code to decode it. | 423 // code to decode it. |
395 const int field_number = GetSpecificsFieldNumberFromModelType(model_type); | 424 const int field_number = GetSpecificsFieldNumberFromModelType(model_type); |
396 fetcher->AddExtraRequestHeader( | 425 fetcher->AddExtraRequestHeader( |
397 base::StringPrintf("%s: %d", kSyncDataTypeId, field_number)); | 426 base::StringPrintf("%s: %d", kSyncDataTypeId, field_number)); |
398 } | 427 } |
399 | 428 |
400 } // namespace syncer | 429 } // namespace syncer |
OLD | NEW |