| 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_DOWNLOADER_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "google_apis/gaia/oauth2_token_service_request.h" | 12 #include "google_apis/gaia/oauth2_token_service_request.h" |
| 13 #include "sync/api/attachments/attachment.h" | 13 #include "sync/api/attachments/attachment.h" |
| 14 #include "sync/base/sync_export.h" | 14 #include "sync/base/sync_export.h" |
| 15 #include "sync/internal_api/public/base/model_type.h" | 15 #include "sync/internal_api/public/base/model_type.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
| 19 } // namespace net | 19 } // namespace net |
| 20 | 20 |
| 21 namespace syncer { | 21 namespace syncer { |
| 22 | 22 |
| 23 // AttachmentDownloader is responsible for downloading attachments from server. | 23 // AttachmentDownloader is responsible for downloading attachments from server. |
| 24 class SYNC_EXPORT AttachmentDownloader { | 24 class SYNC_EXPORT AttachmentDownloader { |
| 25 public: | 25 public: |
| 26 // The result of a DownloadAttachment operation. | 26 // The result of a DownloadAttachment operation. |
| 27 enum DownloadResult { | 27 enum DownloadResult { |
| 28 DOWNLOAD_SUCCESS, // No error, attachment was downloaded | 28 DOWNLOAD_SUCCESS, // No error, attachment was downloaded |
| 29 // successfully. | 29 // successfully. |
| 30 DOWNLOAD_TRANSIENT_ERROR, // A transient error occurred, try again later. | 30 DOWNLOAD_TRANSIENT_ERROR, // A transient error occurred, try again later. |
| 31 DOWNLOAD_UNSPECIFIED_ERROR, // An unspecified error occurred. | 31 DOWNLOAD_UNSPECIFIED_ERROR, // An unspecified error occurred. |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 typedef base::Callback<void(const DownloadResult&, scoped_ptr<Attachment>)> | 34 typedef base::Callback<void(const DownloadResult&, |
| 35 std::unique_ptr<Attachment>)> |
| 35 DownloadCallback; | 36 DownloadCallback; |
| 36 | 37 |
| 37 virtual ~AttachmentDownloader(); | 38 virtual ~AttachmentDownloader(); |
| 38 | 39 |
| 39 // Download attachment referred by |attachment_id| and invoke |callback| when | 40 // Download attachment referred by |attachment_id| and invoke |callback| when |
| 40 // done. | 41 // done. |
| 41 // | 42 // |
| 42 // |callback| will receive a DownloadResult code and an Attachment object. If | 43 // |callback| will receive a DownloadResult code and an Attachment object. If |
| 43 // DownloadResult is not DOWNLOAD_SUCCESS then attachment pointer is NULL. | 44 // DownloadResult is not DOWNLOAD_SUCCESS then attachment pointer is NULL. |
| 44 virtual void DownloadAttachment(const AttachmentId& attachment_id, | 45 virtual void DownloadAttachment(const AttachmentId& attachment_id, |
| 45 const DownloadCallback& callback) = 0; | 46 const DownloadCallback& callback) = 0; |
| 46 | 47 |
| 47 // Create instance of AttachmentDownloaderImpl. | 48 // Create instance of AttachmentDownloaderImpl. |
| 48 // |sync_service_url| is the URL of the sync service. | 49 // |sync_service_url| is the URL of the sync service. |
| 49 // | 50 // |
| 50 // |url_request_context_getter| provides a URLRequestContext. | 51 // |url_request_context_getter| provides a URLRequestContext. |
| 51 // | 52 // |
| 52 // |account_id| is the account id to use for downloads. | 53 // |account_id| is the account id to use for downloads. |
| 53 // | 54 // |
| 54 // |scopes| is the set of scopes to use for downloads. | 55 // |scopes| is the set of scopes to use for downloads. |
| 55 // | 56 // |
| 56 // |token_service_provider| provides an OAuth2 token service. | 57 // |token_service_provider| provides an OAuth2 token service. |
| 57 // | 58 // |
| 58 // |store_birthday| is the raw, sync store birthday. | 59 // |store_birthday| is the raw, sync store birthday. |
| 59 // | 60 // |
| 60 // |model_type| is the model type this downloader is used with. | 61 // |model_type| is the model type this downloader is used with. |
| 61 static scoped_ptr<AttachmentDownloader> Create( | 62 static std::unique_ptr<AttachmentDownloader> Create( |
| 62 const GURL& sync_service_url, | 63 const GURL& sync_service_url, |
| 63 const scoped_refptr<net::URLRequestContextGetter>& | 64 const scoped_refptr<net::URLRequestContextGetter>& |
| 64 url_request_context_getter, | 65 url_request_context_getter, |
| 65 const std::string& account_id, | 66 const std::string& account_id, |
| 66 const OAuth2TokenService::ScopeSet scopes, | 67 const OAuth2TokenService::ScopeSet scopes, |
| 67 const scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>& | 68 const scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>& |
| 68 token_service_provider, | 69 token_service_provider, |
| 69 const std::string& store_birthday, | 70 const std::string& store_birthday, |
| 70 ModelType model_type); | 71 ModelType model_type); |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 } // namespace syncer | 74 } // namespace syncer |
| 74 | 75 |
| 75 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_H_ | 76 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_H_ |
| OLD | NEW |