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 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 9 #include "base/threading/non_thread_safe.h" | 9 #include "base/threading/non_thread_safe.h" |
| 10 #include "google_apis/gaia/oauth2_token_service_request.h" | 10 #include "google_apis/gaia/oauth2_token_service_request.h" |
| 11 #include "net/url_request/url_request_context_getter.h" | 11 #include "net/url_request/url_request_context_getter.h" |
| 12 #include "sync/api/attachments/attachment_uploader.h" | 12 #include "sync/api/attachments/attachment_uploader.h" |
| 13 | 13 |
| 14 class GURL; | 14 class GURL; |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 class URLRequestContextGetter; | 17 class URLRequestContextGetter; |
| 18 } // namespace net | 18 } // namespace net |
| 19 | 19 |
| 20 namespace syncer { | 20 namespace syncer { |
| 21 | 21 |
| 22 // An implementation of AttachmentUploader. | 22 // An implementation of AttachmentUploader. |
| 23 class SYNC_EXPORT AttachmentUploaderImpl : public AttachmentUploader, | 23 class SYNC_EXPORT AttachmentUploaderImpl : public AttachmentUploader, |
| 24 public base::NonThreadSafe { | 24 public base::NonThreadSafe { |
| 25 public: | 25 public: |
| 26 // |url_prefix| is the URL prefix (including trailing slash) to be used when | 26 // Return the URL for the given |sync_service_url| and |attachment_id|. |
| 27 // uploading attachments. | 27 static GURL GetURLForAttachmentId(const GURL& sync_service_url, |
|
pavely
2014/06/26 21:09:03
nit: In chromium code I saw static methods declare
maniscalco
2014/06/26 21:31:33
Good catch. Done.
| |
| 28 const AttachmentId& attachment_id); | |
| 29 | |
| 30 // |sync_service_url| is the URL of the sync service. | |
| 28 // | 31 // |
| 29 // |url_request_context_getter| provides a URLRequestContext. | 32 // |url_request_context_getter| provides a URLRequestContext. |
| 30 // | 33 // |
| 31 // |account_id| is the account id to use for uploads. | 34 // |account_id| is the account id to use for uploads. |
| 32 // | 35 // |
| 33 // |scopes| is the set of scopes to use for uploads. | 36 // |scopes| is the set of scopes to use for uploads. |
| 34 // | 37 // |
| 35 // |token_service_provider| provides an OAuth2 token service. | 38 // |token_service_provider| provides an OAuth2 token service. |
| 36 AttachmentUploaderImpl( | 39 AttachmentUploaderImpl( |
| 37 const std::string& url_prefix, | 40 const GURL& sync_service_url, |
| 38 const scoped_refptr<net::URLRequestContextGetter>& | 41 const scoped_refptr<net::URLRequestContextGetter>& |
| 39 url_request_context_getter, | 42 url_request_context_getter, |
| 40 const std::string& account_id, | 43 const std::string& account_id, |
| 41 const OAuth2TokenService::ScopeSet& scopes, | 44 const OAuth2TokenService::ScopeSet& scopes, |
| 42 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider> | 45 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider> |
| 43 token_service_provider); | 46 token_service_provider); |
| 44 virtual ~AttachmentUploaderImpl(); | 47 virtual ~AttachmentUploaderImpl(); |
| 45 | 48 |
| 46 // AttachmentUploader implementation. | 49 // AttachmentUploader implementation. |
| 47 virtual void UploadAttachment(const Attachment& attachment, | 50 virtual void UploadAttachment(const Attachment& attachment, |
| 48 const UploadCallback& callback) OVERRIDE; | 51 const UploadCallback& callback) OVERRIDE; |
| 49 | 52 |
| 50 private: | 53 private: |
| 51 class UploadState; | 54 class UploadState; |
| 52 typedef std::string UniqueId; | 55 typedef std::string UniqueId; |
| 53 typedef base::ScopedPtrHashMap<UniqueId, UploadState> StateMap; | 56 typedef base::ScopedPtrHashMap<UniqueId, UploadState> StateMap; |
| 54 | 57 |
| 55 GURL GetUploadURLForAttachmentId(const AttachmentId& attachment_id) const; | 58 GURL GetUploadURLForAttachmentId(const AttachmentId& attachment_id) const; |
| 56 void DeleteUploadStateFor(const UniqueId& unique_id); | 59 void DeleteUploadStateFor(const UniqueId& unique_id); |
| 57 | 60 |
| 58 std::string url_prefix_; | 61 GURL sync_service_url_; |
| 59 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 62 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 60 std::string account_id_; | 63 std::string account_id_; |
| 61 OAuth2TokenService::ScopeSet scopes_; | 64 OAuth2TokenService::ScopeSet scopes_; |
| 62 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider> | 65 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider> |
| 63 token_service_provider_; | 66 token_service_provider_; |
| 64 StateMap state_map_; | 67 StateMap state_map_; |
| 65 DISALLOW_COPY_AND_ASSIGN(AttachmentUploaderImpl); | 68 DISALLOW_COPY_AND_ASSIGN(AttachmentUploaderImpl); |
| 66 }; | 69 }; |
| 67 | 70 |
| 68 } // namespace syncer | 71 } // namespace syncer |
| 69 | 72 |
| 70 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_ | 73 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_ |
| OLD | NEW |