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" | 5 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/base64url.h" | 13 #include "base/base64url.h" |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/location.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
17 #include "base/message_loop/message_loop.h" | |
18 #include "base/metrics/sparse_histogram.h" | 18 #include "base/metrics/sparse_histogram.h" |
| 19 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
21 #include "base/sys_byteorder.h" | 22 #include "base/sys_byteorder.h" |
22 #include "base/threading/non_thread_safe.h" | 23 #include "base/threading/non_thread_safe.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" |
23 #include "google_apis/gaia/gaia_constants.h" | 25 #include "google_apis/gaia/gaia_constants.h" |
24 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
25 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
26 #include "net/url_request/url_fetcher.h" | 28 #include "net/url_request/url_fetcher.h" |
27 #include "net/url_request/url_fetcher_delegate.h" | 29 #include "net/url_request/url_fetcher_delegate.h" |
28 #include "net/url_request/url_request_status.h" | 30 #include "net/url_request/url_request_status.h" |
29 #include "sync/api/attachments/attachment.h" | 31 #include "sync/api/attachments/attachment.h" |
30 #include "sync/protocol/sync.pb.h" | 32 #include "sync/protocol/sync.pb.h" |
31 | 33 |
32 namespace { | 34 namespace { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 259 } |
258 | 260 |
259 void AttachmentUploaderImpl::UploadState::StopAndReportResult( | 261 void AttachmentUploaderImpl::UploadState::StopAndReportResult( |
260 const UploadResult& result, | 262 const UploadResult& result, |
261 const AttachmentId& attachment_id) { | 263 const AttachmentId& attachment_id) { |
262 DCHECK(!is_stopped_); | 264 DCHECK(!is_stopped_); |
263 is_stopped_ = true; | 265 is_stopped_ = true; |
264 UploadCallbackList::const_iterator iter = user_callbacks_.begin(); | 266 UploadCallbackList::const_iterator iter = user_callbacks_.begin(); |
265 UploadCallbackList::const_iterator end = user_callbacks_.end(); | 267 UploadCallbackList::const_iterator end = user_callbacks_.end(); |
266 for (; iter != end; ++iter) { | 268 for (; iter != end; ++iter) { |
267 base::MessageLoop::current()->PostTask( | 269 base::ThreadTaskRunnerHandle::Get()->PostTask( |
268 FROM_HERE, base::Bind(*iter, result, attachment_id)); | 270 FROM_HERE, base::Bind(*iter, result, attachment_id)); |
269 } | 271 } |
270 base::MessageLoop::current()->PostTask( | 272 base::ThreadTaskRunnerHandle::Get()->PostTask( |
271 FROM_HERE, | 273 FROM_HERE, base::Bind(&AttachmentUploaderImpl::OnUploadStateStopped, |
272 base::Bind(&AttachmentUploaderImpl::OnUploadStateStopped, | 274 owner_, attachment_id.GetProto().unique_id())); |
273 owner_, | |
274 attachment_id.GetProto().unique_id())); | |
275 } | 275 } |
276 | 276 |
277 AttachmentUploaderImpl::AttachmentUploaderImpl( | 277 AttachmentUploaderImpl::AttachmentUploaderImpl( |
278 const GURL& sync_service_url, | 278 const GURL& sync_service_url, |
279 const scoped_refptr<net::URLRequestContextGetter>& | 279 const scoped_refptr<net::URLRequestContextGetter>& |
280 url_request_context_getter, | 280 url_request_context_getter, |
281 const std::string& account_id, | 281 const std::string& account_id, |
282 const OAuth2TokenService::ScopeSet& scopes, | 282 const OAuth2TokenService::ScopeSet& scopes, |
283 const scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>& | 283 const scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>& |
284 token_service_provider, | 284 token_service_provider, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 "%s: %s", kSyncStoreBirthday, encoded_store_birthday.c_str())); | 393 "%s: %s", kSyncStoreBirthday, encoded_store_birthday.c_str())); |
394 | 394 |
395 // Use field number to pass ModelType because it's stable and we have server | 395 // Use field number to pass ModelType because it's stable and we have server |
396 // code to decode it. | 396 // code to decode it. |
397 const int field_number = GetSpecificsFieldNumberFromModelType(model_type); | 397 const int field_number = GetSpecificsFieldNumberFromModelType(model_type); |
398 fetcher->AddExtraRequestHeader( | 398 fetcher->AddExtraRequestHeader( |
399 base::StringPrintf("%s: %d", kSyncDataTypeId, field_number)); | 399 base::StringPrintf("%s: %d", kSyncDataTypeId, field_number)); |
400 } | 400 } |
401 | 401 |
402 } // namespace syncer | 402 } // namespace syncer |
OLD | NEW |