OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_ | |
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <string> | |
11 #include <unordered_map> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/threading/non_thread_safe.h" | |
15 #include "google_apis/gaia/oauth2_token_service_request.h" | |
16 #include "net/url_request/url_request_context_getter.h" | |
17 #include "sync/internal_api/public/attachments/attachment_uploader.h" | |
18 #include "sync/internal_api/public/base/model_type.h" | |
19 | |
20 class GURL; | |
21 | |
22 namespace net { | |
23 class URLRequestContextGetter; | |
24 } // namespace net | |
25 | |
26 namespace syncer { | |
27 | |
28 // An implementation of AttachmentUploader. | |
29 class SYNC_EXPORT AttachmentUploaderImpl : public AttachmentUploader, | |
30 public base::NonThreadSafe { | |
31 public: | |
32 // |sync_service_url| is the URL of the sync service. | |
33 // | |
34 // |url_request_context_getter| provides a URLRequestContext. | |
35 // | |
36 // |account_id| is the account id to use for uploads. | |
37 // | |
38 // |scopes| is the set of scopes to use for uploads. | |
39 // | |
40 // |token_service_provider| provides an OAuth2 token service. | |
41 // | |
42 // |store_birthday| is the raw, sync store birthday. | |
43 // | |
44 // |model_type| is the model type this uploader is used with. | |
45 AttachmentUploaderImpl( | |
46 const GURL& sync_service_url, | |
47 const scoped_refptr<net::URLRequestContextGetter>& | |
48 url_request_context_getter, | |
49 const std::string& account_id, | |
50 const OAuth2TokenService::ScopeSet& scopes, | |
51 const scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>& | |
52 token_service_provider, | |
53 const std::string& store_birthday, | |
54 ModelType model_type); | |
55 ~AttachmentUploaderImpl() override; | |
56 | |
57 // AttachmentUploader implementation. | |
58 void UploadAttachment(const Attachment& attachment, | |
59 const UploadCallback& callback) override; | |
60 | |
61 // Return the URL for the given |sync_service_url| and |attachment_id|. | |
62 static GURL GetURLForAttachmentId(const GURL& sync_service_url, | |
63 const AttachmentId& attachment_id); | |
64 | |
65 // Format crc32c to pass into X-Goog-Hash header. | |
66 // | |
67 // The value is base64 encoded, big-endian format. Suitable for use in the | |
68 // X-Goog-Hash header | |
69 // (https://cloud.google.com/storage/docs/reference-headers#xgooghash). | |
70 static std::string FormatCrc32cHash(uint32_t crc32c); | |
71 | |
72 // Apply common settings to |fetcher|, suitable for both uploads and | |
73 // downloads. | |
74 static void ConfigureURLFetcherCommon( | |
75 net::URLFetcher* fetcher, | |
76 const std::string& auth_token, | |
77 const std::string& raw_store_birthday, | |
78 ModelType model_type, | |
79 net::URLRequestContextGetter* request_context_getter); | |
80 | |
81 private: | |
82 class UploadState; | |
83 typedef std::string UniqueId; | |
84 typedef std::unordered_map<UniqueId, std::unique_ptr<UploadState>> StateMap; | |
85 | |
86 void OnUploadStateStopped(const UniqueId& unique_id); | |
87 | |
88 GURL sync_service_url_; | |
89 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | |
90 std::string account_id_; | |
91 OAuth2TokenService::ScopeSet scopes_; | |
92 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> | |
93 token_service_provider_; | |
94 std::string raw_store_birthday_; | |
95 StateMap state_map_; | |
96 ModelType model_type_; | |
97 | |
98 // Must be last data member. | |
99 base::WeakPtrFactory<AttachmentUploaderImpl> weak_ptr_factory_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(AttachmentUploaderImpl); | |
102 }; | |
103 | |
104 } // namespace syncer | |
105 | |
106 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_ | |
OLD | NEW |