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/internal_api/public/attachments/attachment_uploader.h"
17 class URLRequestContextGetter;
22 // An implementation of AttachmentUploader.
23 class SYNC_EXPORT AttachmentUploaderImpl : public AttachmentUploader,
24 public base::NonThreadSafe {
26 // |sync_service_url| is the URL of the sync service.
28 // |url_request_context_getter| provides a URLRequestContext.
30 // |account_id| is the account id to use for uploads.
32 // |scopes| is the set of scopes to use for uploads.
34 // |token_service_provider| provides an OAuth2 token service.
35 AttachmentUploaderImpl(
36 const GURL& sync_service_url,
37 const scoped_refptr<net::URLRequestContextGetter>&
38 url_request_context_getter,
39 const std::string& account_id,
40 const OAuth2TokenService::ScopeSet& scopes,
41 const scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>&
42 token_service_provider);
43 virtual ~AttachmentUploaderImpl();
45 // AttachmentUploader implementation.
46 virtual void UploadAttachment(const Attachment& attachment,
47 const UploadCallback& callback) OVERRIDE;
49 // Return the URL for the given |sync_service_url| and |attachment_id|.
50 static GURL GetURLForAttachmentId(const GURL& sync_service_url,
51 const AttachmentId& attachment_id);
55 typedef std::string UniqueId;
56 typedef base::ScopedPtrHashMap<UniqueId, UploadState> StateMap;
58 void OnUploadStateStopped(const UniqueId& unique_id);
60 GURL sync_service_url_;
61 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
62 std::string account_id_;
63 OAuth2TokenService::ScopeSet scopes_;
64 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>
65 token_service_provider_;
68 // Must be last data member.
69 base::WeakPtrFactory<AttachmentUploaderImpl> weak_ptr_factory_;
71 DISALLOW_COPY_AND_ASSIGN(AttachmentUploaderImpl);
76 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_UPLOADER_IMPL_H_