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

Side by Side Diff: mojo/fetcher/network_fetcher.cc

Issue 1538823002: Convert Pass()→std::move() in mojo/ (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
« no previous file with comments | « mojo/fetcher/local_fetcher.cc ('k') | mojo/fetcher/network_fetcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "mojo/fetcher/network_fetcher.h" 5 #include "mojo/fetcher/network_fetcher.h"
6 6
7 #include <utility>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/command_line.h" 10 #include "base/command_line.h"
9 #include "base/files/file.h" 11 #include "base/files/file.h"
10 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
12 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
13 #include "base/process/process.h" 15 #include "base/process/process.h"
14 #include "base/stl_util.h" 16 #include "base/stl_util.h"
15 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
(...skipping 13 matching lines...) Expand all
30 namespace fetcher { 32 namespace fetcher {
31 33
32 NetworkFetcher::NetworkFetcher(bool disable_cache, 34 NetworkFetcher::NetworkFetcher(bool disable_cache,
33 mojo::URLRequestPtr request, 35 mojo::URLRequestPtr request,
34 URLLoaderFactory* url_loader_factory, 36 URLLoaderFactory* url_loader_factory,
35 const FetchCallback& loader_callback) 37 const FetchCallback& loader_callback)
36 : Fetcher(loader_callback), 38 : Fetcher(loader_callback),
37 disable_cache_(false), 39 disable_cache_(false),
38 url_(request->url.To<GURL>()), 40 url_(request->url.To<GURL>()),
39 weak_ptr_factory_(this) { 41 weak_ptr_factory_(this) {
40 StartNetworkRequest(request.Pass(), url_loader_factory); 42 StartNetworkRequest(std::move(request), url_loader_factory);
41 } 43 }
42 44
43 NetworkFetcher::~NetworkFetcher() { 45 NetworkFetcher::~NetworkFetcher() {
44 } 46 }
45 47
46 const GURL& NetworkFetcher::GetURL() const { 48 const GURL& NetworkFetcher::GetURL() const {
47 return url_; 49 return url_;
48 } 50 }
49 51
50 GURL NetworkFetcher::GetRedirectURL() const { 52 GURL NetworkFetcher::GetRedirectURL() const {
(...skipping 16 matching lines...) Expand all
67 return GURL(response_->redirect_referrer); 69 return GURL(response_->redirect_referrer);
68 } 70 }
69 URLResponsePtr NetworkFetcher::AsURLResponse(base::TaskRunner* task_runner, 71 URLResponsePtr NetworkFetcher::AsURLResponse(base::TaskRunner* task_runner,
70 uint32_t skip) { 72 uint32_t skip) {
71 if (skip != 0) { 73 if (skip != 0) {
72 MojoResult result = ReadDataRaw( 74 MojoResult result = ReadDataRaw(
73 response_->body.get(), nullptr, &skip, 75 response_->body.get(), nullptr, &skip,
74 MOJO_READ_DATA_FLAG_ALL_OR_NONE | MOJO_READ_DATA_FLAG_DISCARD); 76 MOJO_READ_DATA_FLAG_ALL_OR_NONE | MOJO_READ_DATA_FLAG_DISCARD);
75 DCHECK_EQ(result, MOJO_RESULT_OK); 77 DCHECK_EQ(result, MOJO_RESULT_OK);
76 } 78 }
77 return response_.Pass(); 79 return std::move(response_);
78 } 80 }
79 81
80 void NetworkFetcher::RecordCacheToURLMapping(const base::FilePath& path, 82 void NetworkFetcher::RecordCacheToURLMapping(const base::FilePath& path,
81 const GURL& url) { 83 const GURL& url) {
82 // This is used to extract symbols on android. 84 // This is used to extract symbols on android.
83 // TODO(eseidel): All users of this log should move to using the map file. 85 // TODO(eseidel): All users of this log should move to using the map file.
84 VLOG(1) << "Caching mojo app " << url << " at " << path.value(); 86 VLOG(1) << "Caching mojo app " << url << " at " << path.value();
85 87
86 base::FilePath temp_dir; 88 base::FilePath temp_dir;
87 base::GetTempDir(&temp_dir); 89 base::GetTempDir(&temp_dir);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 void NetworkFetcher::AsPath( 192 void NetworkFetcher::AsPath(
191 base::TaskRunner* task_runner, 193 base::TaskRunner* task_runner,
192 base::Callback<void(const base::FilePath&, bool)> callback) { 194 base::Callback<void(const base::FilePath&, bool)> callback) {
193 if (!path_.empty() || !response_) { 195 if (!path_.empty() || !response_) {
194 base::MessageLoop::current()->PostTask( 196 base::MessageLoop::current()->PostTask(
195 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_))); 197 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_)));
196 return; 198 return;
197 } 199 }
198 200
199 base::CreateTemporaryFile(&path_); 201 base::CreateTemporaryFile(&path_);
200 common::CopyToFile(response_->body.Pass(), path_, task_runner, 202 common::CopyToFile(std::move(response_->body), path_, task_runner,
201 base::Bind(&NetworkFetcher::CopyCompleted, 203 base::Bind(&NetworkFetcher::CopyCompleted,
202 weak_ptr_factory_.GetWeakPtr(), callback)); 204 weak_ptr_factory_.GetWeakPtr(), callback));
203 } 205 }
204 206
205 std::string NetworkFetcher::MimeType() { 207 std::string NetworkFetcher::MimeType() {
206 return response_->mime_type; 208 return response_->mime_type;
207 } 209 }
208 210
209 bool NetworkFetcher::HasMojoMagic() { 211 bool NetworkFetcher::HasMojoMagic() {
210 std::string magic; 212 std::string magic;
211 return shell::BlockingPeekNBytes(response_->body.get(), &magic, 213 return shell::BlockingPeekNBytes(response_->body.get(), &magic,
212 strlen(kMojoMagic), kPeekTimeout) && 214 strlen(kMojoMagic), kPeekTimeout) &&
213 magic == kMojoMagic; 215 magic == kMojoMagic;
214 } 216 }
215 217
216 bool NetworkFetcher::PeekFirstLine(std::string* line) { 218 bool NetworkFetcher::PeekFirstLine(std::string* line) {
217 return shell::BlockingPeekLine(response_->body.get(), line, kMaxShebangLength, 219 return shell::BlockingPeekLine(response_->body.get(), line, kMaxShebangLength,
218 kPeekTimeout); 220 kPeekTimeout);
219 } 221 }
220 222
221 void NetworkFetcher::StartNetworkRequest(mojo::URLRequestPtr request, 223 void NetworkFetcher::StartNetworkRequest(mojo::URLRequestPtr request,
222 URLLoaderFactory* url_loader_factory) { 224 URLLoaderFactory* url_loader_factory) {
223 TRACE_EVENT_ASYNC_BEGIN1("mojo_shell", "NetworkFetcher::NetworkRequest", this, 225 TRACE_EVENT_ASYNC_BEGIN1("mojo_shell", "NetworkFetcher::NetworkRequest", this,
224 "url", request->url.To<std::string>()); 226 "url", request->url.To<std::string>());
225 request->auto_follow_redirects = false; 227 request->auto_follow_redirects = false;
226 request->bypass_cache = disable_cache_; 228 request->bypass_cache = disable_cache_;
227 229
228 url_loader_factory->CreateURLLoader(GetProxy(&url_loader_)); 230 url_loader_factory->CreateURLLoader(GetProxy(&url_loader_));
229 url_loader_->Start(request.Pass(), 231 url_loader_->Start(std::move(request),
230 base::Bind(&NetworkFetcher::OnLoadComplete, 232 base::Bind(&NetworkFetcher::OnLoadComplete,
231 weak_ptr_factory_.GetWeakPtr())); 233 weak_ptr_factory_.GetWeakPtr()));
232 } 234 }
233 235
234 void NetworkFetcher::OnLoadComplete(URLResponsePtr response) { 236 void NetworkFetcher::OnLoadComplete(URLResponsePtr response) {
235 TRACE_EVENT_ASYNC_END0("mojo_shell", "NetworkFetcher::NetworkRequest", this); 237 TRACE_EVENT_ASYNC_END0("mojo_shell", "NetworkFetcher::NetworkRequest", this);
236 scoped_ptr<Fetcher> owner(this); 238 scoped_ptr<Fetcher> owner(this);
237 if (response->error) { 239 if (response->error) {
238 LOG(ERROR) << "Error (" << response->error->code << ": " 240 LOG(ERROR) << "Error (" << response->error->code << ": "
239 << response->error->description << ") while fetching " 241 << response->error->description << ") while fetching "
240 << response->url; 242 << response->url;
241 loader_callback_.Run(nullptr); 243 loader_callback_.Run(nullptr);
242 return; 244 return;
243 } 245 }
244 246
245 response_ = response.Pass(); 247 response_ = std::move(response);
246 loader_callback_.Run(owner.Pass()); 248 loader_callback_.Run(std::move(owner));
247 } 249 }
248 250
249 } // namespace fetcher 251 } // namespace fetcher
250 } // namespace mojo 252 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/fetcher/local_fetcher.cc ('k') | mojo/fetcher/network_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698