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

Side by Side Diff: sync/internal_api/public/attachments/attachment_downloader_impl.h

Issue 356953009: Revert of Consolidate attachment URL construction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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_IMPL_H_ 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_IMPL_H_
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_IMPL_H_ 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_IMPL_H_
7 7
8 #include "base/containers/scoped_ptr_hash_map.h" 8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/threading/non_thread_safe.h" 9 #include "base/threading/non_thread_safe.h"
10 #include "google_apis/gaia/oauth2_token_service_request.h" 10 #include "google_apis/gaia/oauth2_token_service_request.h"
11 #include "net/url_request/url_fetcher_delegate.h" 11 #include "net/url_request/url_fetcher_delegate.h"
12 #include "net/url_request/url_request_context_getter.h" 12 #include "net/url_request/url_request_context_getter.h"
13 #include "sync/api/attachments/attachment_downloader.h" 13 #include "sync/api/attachments/attachment_downloader.h"
14 #include "url/gurl.h"
15 14
16 namespace syncer { 15 namespace syncer {
17 16
18 // An implementation of AttachmentDownloader. 17 // An implementation of AttachmentDownloader.
19 class AttachmentDownloaderImpl : public AttachmentDownloader, 18 class AttachmentDownloaderImpl : public AttachmentDownloader,
20 public OAuth2TokenService::Consumer, 19 public OAuth2TokenService::Consumer,
21 public net::URLFetcherDelegate, 20 public net::URLFetcherDelegate,
22 public base::NonThreadSafe { 21 public base::NonThreadSafe {
23 public: 22 public:
24 // |sync_service_url| is the URL of the sync service. 23 // |url_prefix| is the URL prefix (including trailing slash) to be used when
24 // downloading attachments.
25 // 25 //
26 // |url_request_context_getter| provides a URLRequestContext. 26 // |url_request_context_getter| provides a URLRequestContext.
27 // 27 //
28 // |account_id| is the account id to use for downloads. 28 // |account_id| is the account id to use for downloads.
29 // 29 //
30 // |scopes| is the set of scopes to use for downloads. 30 // |scopes| is the set of scopes to use for downloads.
31 // 31 //
32 // |token_service_provider| provides an OAuth2 token service. 32 // |token_service_provider| provides an OAuth2 token service.
33 AttachmentDownloaderImpl( 33 AttachmentDownloaderImpl(
34 const GURL& sync_service_url, 34 const std::string& url_prefix,
35 const scoped_refptr<net::URLRequestContextGetter>& 35 const scoped_refptr<net::URLRequestContextGetter>&
36 url_request_context_getter, 36 url_request_context_getter,
37 const std::string& account_id, 37 const std::string& account_id,
38 const OAuth2TokenService::ScopeSet& scopes, 38 const OAuth2TokenService::ScopeSet& scopes,
39 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider> 39 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider>
40 token_service_provider); 40 token_service_provider);
41 virtual ~AttachmentDownloaderImpl(); 41 virtual ~AttachmentDownloaderImpl();
42 42
43 // AttachmentDownloader implementation. 43 // AttachmentDownloader implementation.
44 virtual void DownloadAttachment(const AttachmentId& attachment_id, 44 virtual void DownloadAttachment(const AttachmentId& attachment_id,
45 const DownloadCallback& callback) OVERRIDE; 45 const DownloadCallback& callback) OVERRIDE;
46 46
47 // OAuth2TokenService::Consumer implementation. 47 // OAuth2TokenService::Consumer implementation.
48 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 48 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
49 const std::string& access_token, 49 const std::string& access_token,
50 const base::Time& expiration_time) OVERRIDE; 50 const base::Time& expiration_time) OVERRIDE;
51 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, 51 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
52 const GoogleServiceAuthError& error) OVERRIDE; 52 const GoogleServiceAuthError& error) OVERRIDE;
53 53
54 // net::URLFetcherDelegate implementation. 54 // net::URLFetcherDelegate implementation.
55 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 55 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
56 56
57 private: 57 private:
58 struct DownloadState; 58 struct DownloadState;
59 typedef std::string AttachmentUrl; 59 typedef std::string AttachmentUrl;
60 typedef base::ScopedPtrHashMap<AttachmentUrl, DownloadState> StateMap; 60 typedef base::ScopedPtrHashMap<AttachmentUrl, DownloadState> StateMap;
61 typedef std::vector<DownloadState*> StateList; 61 typedef std::vector<DownloadState*> StateList;
62 62
63 AttachmentUrl GetAttachmentUrl(const AttachmentId& attachment_id);
63 scoped_ptr<net::URLFetcher> CreateFetcher(const AttachmentUrl& url, 64 scoped_ptr<net::URLFetcher> CreateFetcher(const AttachmentUrl& url,
64 const std::string& access_token); 65 const std::string& access_token);
65 void RequestAccessToken(DownloadState* download_state); 66 void RequestAccessToken(DownloadState* download_state);
66 void ReportResult( 67 void ReportResult(
67 const DownloadState& download_state, 68 const DownloadState& download_state,
68 const DownloadResult& result, 69 const DownloadResult& result,
69 const scoped_refptr<base::RefCountedString>& attachment_data); 70 const scoped_refptr<base::RefCountedString>& attachment_data);
70 71
71 GURL sync_service_url_; 72 std::string url_prefix_;
72 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; 73 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
73 74
74 std::string account_id_; 75 std::string account_id_;
75 OAuth2TokenService::ScopeSet oauth2_scopes_; 76 OAuth2TokenService::ScopeSet oauth2_scopes_;
76 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider> 77 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider>
77 token_service_provider_; 78 token_service_provider_;
78 scoped_ptr<OAuth2TokenService::Request> access_token_request_; 79 scoped_ptr<OAuth2TokenService::Request> access_token_request_;
79 80
80 StateMap state_map_; 81 StateMap state_map_;
81 // |requests_waiting_for_access_token_| only keeps references to DownloadState 82 // |requests_waiting_for_access_token_| only keeps references to DownloadState
82 // objects while access token request is pending. It doesn't control objects' 83 // objects while access token request is pending. It doesn't control objects'
83 // lifetime. 84 // lifetime.
84 StateList requests_waiting_for_access_token_; 85 StateList requests_waiting_for_access_token_;
85 86
86 DISALLOW_COPY_AND_ASSIGN(AttachmentDownloaderImpl); 87 DISALLOW_COPY_AND_ASSIGN(AttachmentDownloaderImpl);
87 }; 88 };
88 89
89 } // namespace syncer 90 } // namespace syncer
90 91
91 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_IMPL_H_ 92 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_DOWNLOADER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698