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

Side by Side Diff: sync/internal_api/attachments/attachment_downloader_impl.cc

Issue 1539843002: Convert Pass()→std::move() in sync/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
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 #include "sync/internal_api/public/attachments/attachment_downloader_impl.h" 5 #include <utility>
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/sparse_histogram.h" 12 #include "base/metrics/sparse_histogram.h"
13 #include "base/sys_byteorder.h" 13 #include "base/sys_byteorder.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
16 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
17 #include "net/http/http_status_code.h" 17 #include "net/http/http_status_code.h"
18 #include "net/http/http_util.h" 18 #include "net/http/http_util.h"
19 #include "net/url_request/url_fetcher.h" 19 #include "net/url_request/url_fetcher.h"
20 #include "net/url_request/url_request_status.h" 20 #include "net/url_request/url_request_status.h"
21 #include "sync/internal_api/public/attachments/attachment_downloader_impl.h"
21 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h" 22 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h"
Nicolas Zea 2015/12/18 23:46:54 This should remain up top
dcheng 2015/12/20 00:27:53 Hmm. I have a script that does this all automatica
22 #include "sync/internal_api/public/attachments/attachment_util.h" 23 #include "sync/internal_api/public/attachments/attachment_util.h"
23 #include "sync/protocol/sync.pb.h" 24 #include "sync/protocol/sync.pb.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 namespace syncer { 27 namespace syncer {
27 28
28 struct AttachmentDownloaderImpl::DownloadState { 29 struct AttachmentDownloaderImpl::DownloadState {
29 public: 30 public:
30 DownloadState(const AttachmentId& attachment_id, 31 DownloadState(const AttachmentId& attachment_id,
31 const AttachmentUrl& attachment_url); 32 const AttachmentUrl& attachment_url);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 82
82 AttachmentUrl url = AttachmentUploaderImpl::GetURLForAttachmentId( 83 AttachmentUrl url = AttachmentUploaderImpl::GetURLForAttachmentId(
83 sync_service_url_, attachment_id).spec(); 84 sync_service_url_, attachment_id).spec();
84 85
85 StateMap::iterator iter = state_map_.find(url); 86 StateMap::iterator iter = state_map_.find(url);
86 if (iter == state_map_.end()) { 87 if (iter == state_map_.end()) {
87 // There is no request started for this attachment id. Let's create 88 // There is no request started for this attachment id. Let's create
88 // DownloadState and request access token for it. 89 // DownloadState and request access token for it.
89 scoped_ptr<DownloadState> new_download_state( 90 scoped_ptr<DownloadState> new_download_state(
90 new DownloadState(attachment_id, url)); 91 new DownloadState(attachment_id, url));
91 iter = state_map_.add(url, new_download_state.Pass()).first; 92 iter = state_map_.add(url, std::move(new_download_state)).first;
92 RequestAccessToken(iter->second); 93 RequestAccessToken(iter->second);
93 } 94 }
94 DownloadState* download_state = iter->second; 95 DownloadState* download_state = iter->second;
95 DCHECK(download_state->attachment_id == attachment_id); 96 DCHECK(download_state->attachment_id == attachment_id);
96 download_state->user_callbacks.push_back(callback); 97 download_state->user_callbacks.push_back(callback);
97 } 98 }
98 99
99 void AttachmentDownloaderImpl::OnGetTokenSuccess( 100 void AttachmentDownloaderImpl::OnGetTokenSuccess(
100 const OAuth2TokenService::Request* request, 101 const OAuth2TokenService::Request* request,
101 const std::string& access_token, 102 const std::string& access_token,
102 const base::Time& expiration_time) { 103 const base::Time& expiration_time) {
103 DCHECK(CalledOnValidThread()); 104 DCHECK(CalledOnValidThread());
104 DCHECK(request == access_token_request_.get()); 105 DCHECK(request == access_token_request_.get());
105 access_token_request_.reset(); 106 access_token_request_.reset();
106 StateList::const_iterator iter; 107 StateList::const_iterator iter;
107 // Start downloads for all download requests waiting for access token. 108 // Start downloads for all download requests waiting for access token.
108 for (iter = requests_waiting_for_access_token_.begin(); 109 for (iter = requests_waiting_for_access_token_.begin();
109 iter != requests_waiting_for_access_token_.end(); 110 iter != requests_waiting_for_access_token_.end();
110 ++iter) { 111 ++iter) {
111 DownloadState* download_state = *iter; 112 DownloadState* download_state = *iter;
112 download_state->access_token = access_token; 113 download_state->access_token = access_token;
113 download_state->url_fetcher = 114 download_state->url_fetcher =
114 CreateFetcher(download_state->attachment_url, access_token).Pass(); 115 CreateFetcher(download_state->attachment_url, access_token);
115 download_state->start_time = base::TimeTicks::Now(); 116 download_state->start_time = base::TimeTicks::Now();
116 download_state->url_fetcher->Start(); 117 download_state->url_fetcher->Start();
117 } 118 }
118 requests_waiting_for_access_token_.clear(); 119 requests_waiting_for_access_token_.clear();
119 } 120 }
120 121
121 void AttachmentDownloaderImpl::OnGetTokenFailure( 122 void AttachmentDownloaderImpl::OnGetTokenFailure(
122 const OAuth2TokenService::Request* request, 123 const OAuth2TokenService::Request* request,
123 const GoogleServiceAuthError& error) { 124 const GoogleServiceAuthError& error) {
124 DCHECK(CalledOnValidThread()); 125 DCHECK(CalledOnValidThread());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 205 }
205 206
206 scoped_ptr<net::URLFetcher> AttachmentDownloaderImpl::CreateFetcher( 207 scoped_ptr<net::URLFetcher> AttachmentDownloaderImpl::CreateFetcher(
207 const AttachmentUrl& url, 208 const AttachmentUrl& url,
208 const std::string& access_token) { 209 const std::string& access_token) {
209 scoped_ptr<net::URLFetcher> url_fetcher = 210 scoped_ptr<net::URLFetcher> url_fetcher =
210 net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this); 211 net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this);
211 AttachmentUploaderImpl::ConfigureURLFetcherCommon( 212 AttachmentUploaderImpl::ConfigureURLFetcherCommon(
212 url_fetcher.get(), access_token, raw_store_birthday_, model_type_, 213 url_fetcher.get(), access_token, raw_store_birthday_, model_type_,
213 url_request_context_getter_.get()); 214 url_request_context_getter_.get());
214 return url_fetcher.Pass(); 215 return url_fetcher;
215 } 216 }
216 217
217 void AttachmentDownloaderImpl::RequestAccessToken( 218 void AttachmentDownloaderImpl::RequestAccessToken(
218 DownloadState* download_state) { 219 DownloadState* download_state) {
219 requests_waiting_for_access_token_.push_back(download_state); 220 requests_waiting_for_access_token_.push_back(download_state);
220 // Start access token request if there is no active one. 221 // Start access token request if there is no active one.
221 if (access_token_request_ == NULL) { 222 if (access_token_request_ == NULL) {
222 access_token_request_ = OAuth2TokenServiceRequest::CreateAndStart( 223 access_token_request_ = OAuth2TokenServiceRequest::CreateAndStart(
223 token_service_provider_.get(), account_id_, oauth2_scopes_, this); 224 token_service_provider_.get(), account_id_, oauth2_scopes_, this);
224 } 225 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 278
278 if (crc32c_raw.size() != sizeof(*crc32c)) 279 if (crc32c_raw.size() != sizeof(*crc32c))
279 return false; 280 return false;
280 281
281 *crc32c = 282 *crc32c =
282 base::NetToHost32(*reinterpret_cast<const uint32_t*>(crc32c_raw.c_str())); 283 base::NetToHost32(*reinterpret_cast<const uint32_t*>(crc32c_raw.c_str()));
283 return true; 284 return true;
284 } 285 }
285 286
286 } // namespace syncer 287 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698