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.
5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_
8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/threading/non_thread_safe.h"
10 #include "google_apis/gaia/oauth2_token_service_request.h"
11 #include "net/url_request/url_request_context_getter.h"
12 #include "sync/api/attachments/attachment_uploader.h"
17 class URLRequestContextGetter;
22 // An implementation of AttachmentUploader.
23 class SYNC_EXPORT AttachmentUploaderImpl : public AttachmentUploader,
24 public base::NonThreadSafe {
26 // |url_prefix| is the URL prefix (including trailing slash) to be used when
27 // uploading attachments.
29 // |url_request_context_getter| provides a URLRequestContext.
31 // |account_id| is the account id to use for uploads.
33 // |scopes| is the set of scopes to use for uploads.
35 // |token_service_provider| provides an OAuth2 token service.
36 AttachmentUploaderImpl(
37 const std::string& url_prefix,
38 const scoped_refptr<net::URLRequestContextGetter>&
39 url_request_context_getter,
40 const std::string& account_id,
41 const OAuth2TokenService::ScopeSet& scopes,
42 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider>
43 token_service_provider);
44 virtual ~AttachmentUploaderImpl();
46 // AttachmentUploader implementation.
47 virtual void UploadAttachment(const Attachment& attachment,
48 const UploadCallback& callback) OVERRIDE;
52 typedef std::string UniqueId;
53 typedef base::ScopedPtrHashMap<UniqueId, UploadState> StateMap;
55 GURL GetUploadURLForAttachmentId(const AttachmentId& attachment_id) const;
56 void DeleteUploadStateFor(const UniqueId& unique_id);
58 std::string url_prefix_;
59 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
60 std::string account_id_;
61 OAuth2TokenService::ScopeSet scopes_;
62 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider>
63 token_service_provider_;
65 DISALLOW_COPY_AND_ASSIGN(AttachmentUploaderImpl);
70 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_