Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: components/sync/core/attachments/attachment_uploader_impl.h

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

Powered by Google App Engine
This is Rietveld 408576698