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 "sync/internal_api/public/attachments/attachment_uploader_impl.h" | |
| 6 | |
| 7 #include <string> | 5 #include <string> |
| 6 #include <utility> | |
| 8 #include <vector> | 7 #include <vector> |
| 9 | 8 |
| 10 #include "base/base64.h" | 9 #include "base/base64.h" |
| 11 #include "base/base64url.h" | 10 #include "base/base64url.h" |
| 12 #include "base/bind.h" | 11 #include "base/bind.h" |
| 13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/sparse_histogram.h" | 15 #include "base/metrics/sparse_histogram.h" |
| 17 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 18 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 19 #include "base/sys_byteorder.h" | 18 #include "base/sys_byteorder.h" |
| 20 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
| 21 #include "google_apis/gaia/gaia_constants.h" | 20 #include "google_apis/gaia/gaia_constants.h" |
| 22 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
| 23 #include "net/http/http_status_code.h" | 22 #include "net/http/http_status_code.h" |
| 24 #include "net/url_request/url_fetcher.h" | 23 #include "net/url_request/url_fetcher.h" |
| 25 #include "net/url_request/url_fetcher_delegate.h" | 24 #include "net/url_request/url_fetcher_delegate.h" |
| 26 #include "net/url_request/url_request_status.h" | 25 #include "net/url_request/url_request_status.h" |
| 27 #include "sync/api/attachments/attachment.h" | 26 #include "sync/api/attachments/attachment.h" |
| 27 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h" | |
|
Nicolas Zea
2015/12/18 23:46:54
keep up top
| |
| 28 #include "sync/protocol/sync.pb.h" | 28 #include "sync/protocol/sync.pb.h" |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 const char kContentType[] = "application/octet-stream"; | 32 const char kContentType[] = "application/octet-stream"; |
| 33 const char kAttachments[] = "attachments/"; | 33 const char kAttachments[] = "attachments/"; |
| 34 const char kSyncStoreBirthday[] = "X-Sync-Store-Birthday"; | 34 const char kSyncStoreBirthday[] = "X-Sync-Store-Birthday"; |
| 35 const char kSyncDataTypeId[] = "X-Sync-Data-Type-Id"; | 35 const char kSyncDataTypeId[] = "X-Sync-Data-Type-Id"; |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 // It's stopped so we can't use it. Delete it. | 320 // It's stopped so we can't use it. Delete it. |
| 321 state_map_.erase(iter); | 321 state_map_.erase(iter); |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 const GURL url = GetURLForAttachmentId(sync_service_url_, attachment_id); | 325 const GURL url = GetURLForAttachmentId(sync_service_url_, attachment_id); |
| 326 scoped_ptr<UploadState> upload_state(new UploadState( | 326 scoped_ptr<UploadState> upload_state(new UploadState( |
| 327 url, url_request_context_getter_, attachment, callback, account_id_, | 327 url, url_request_context_getter_, attachment, callback, account_id_, |
| 328 scopes_, token_service_provider_.get(), raw_store_birthday_, | 328 scopes_, token_service_provider_.get(), raw_store_birthday_, |
| 329 weak_ptr_factory_.GetWeakPtr(), model_type_)); | 329 weak_ptr_factory_.GetWeakPtr(), model_type_)); |
| 330 state_map_.add(unique_id, upload_state.Pass()); | 330 state_map_.add(unique_id, std::move(upload_state)); |
| 331 } | 331 } |
| 332 | 332 |
| 333 // Static. | 333 // Static. |
| 334 GURL AttachmentUploaderImpl::GetURLForAttachmentId( | 334 GURL AttachmentUploaderImpl::GetURLForAttachmentId( |
| 335 const GURL& sync_service_url, | 335 const GURL& sync_service_url, |
| 336 const AttachmentId& attachment_id) { | 336 const AttachmentId& attachment_id) { |
| 337 std::string path = sync_service_url.path(); | 337 std::string path = sync_service_url.path(); |
| 338 if (path.empty() || *path.rbegin() != '/') { | 338 if (path.empty() || *path.rbegin() != '/') { |
| 339 path += '/'; | 339 path += '/'; |
| 340 } | 340 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 "%s: %s", kSyncStoreBirthday, encoded_store_birthday.c_str())); | 391 "%s: %s", kSyncStoreBirthday, encoded_store_birthday.c_str())); |
| 392 | 392 |
| 393 // Use field number to pass ModelType because it's stable and we have server | 393 // Use field number to pass ModelType because it's stable and we have server |
| 394 // code to decode it. | 394 // code to decode it. |
| 395 const int field_number = GetSpecificsFieldNumberFromModelType(model_type); | 395 const int field_number = GetSpecificsFieldNumberFromModelType(model_type); |
| 396 fetcher->AddExtraRequestHeader( | 396 fetcher->AddExtraRequestHeader( |
| 397 base::StringPrintf("%s: %d", kSyncDataTypeId, field_number)); | 397 base::StringPrintf("%s: %d", kSyncDataTypeId, field_number)); |
| 398 } | 398 } |
| 399 | 399 |
| 400 } // namespace syncer | 400 } // namespace syncer |
| OLD | NEW |