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

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

Issue 1342503003: Move fetching logic out of ApplicationManager, eliminate url mappings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 3 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
« no previous file with comments | « mojo/fetcher/network_fetcher.h ('k') | mojo/fetcher/switches.h » ('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/shell/network_fetcher.h" 5 #include "mojo/fetcher/network_fetcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/process/process.h" 13 #include "base/process/process.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/trace_event/trace_event.h" 19 #include "base/trace_event/trace_event.h"
20 #include "crypto/secure_hash.h" 20 #include "crypto/secure_hash.h"
21 #include "crypto/sha2.h" 21 #include "crypto/sha2.h"
22 #include "mojo/common/common_type_converters.h" 22 #include "mojo/common/common_type_converters.h"
23 #include "mojo/common/data_pipe_utils.h" 23 #include "mojo/common/data_pipe_utils.h"
24 #include "mojo/common/url_type_converters.h" 24 #include "mojo/common/url_type_converters.h"
25 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h" 25 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
26 #include "mojo/shell/data_pipe_peek.h" 26 #include "mojo/shell/data_pipe_peek.h"
27 #include "mojo/shell/switches.h" 27 #include "mojo/shell/switches.h"
28 28
29 namespace mojo { 29 namespace mojo {
30 namespace shell { 30 namespace fetcher {
31 31
32 NetworkFetcher::NetworkFetcher(bool disable_cache, 32 NetworkFetcher::NetworkFetcher(bool disable_cache,
33 mojo::URLRequestPtr request, 33 mojo::URLRequestPtr request,
34 URLLoaderFactory* url_loader_factory, 34 URLLoaderFactory* url_loader_factory,
35 const FetchCallback& loader_callback) 35 const FetchCallback& loader_callback)
36 : Fetcher(loader_callback), 36 : Fetcher(loader_callback),
37 disable_cache_(false), 37 disable_cache_(false),
38 url_(request->url.To<GURL>()), 38 url_(request->url.To<GURL>()),
39 weak_ptr_factory_(this) { 39 weak_ptr_factory_(this) {
40 StartNetworkRequest(request.Pass(), url_loader_factory); 40 StartNetworkRequest(request.Pass(), url_loader_factory);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 base::Bind(&NetworkFetcher::CopyCompleted, 201 base::Bind(&NetworkFetcher::CopyCompleted,
202 weak_ptr_factory_.GetWeakPtr(), callback)); 202 weak_ptr_factory_.GetWeakPtr(), callback));
203 } 203 }
204 204
205 std::string NetworkFetcher::MimeType() { 205 std::string NetworkFetcher::MimeType() {
206 return response_->mime_type; 206 return response_->mime_type;
207 } 207 }
208 208
209 bool NetworkFetcher::HasMojoMagic() { 209 bool NetworkFetcher::HasMojoMagic() {
210 std::string magic; 210 std::string magic;
211 return BlockingPeekNBytes(response_->body.get(), &magic, strlen(kMojoMagic), 211 return shell::BlockingPeekNBytes(response_->body.get(), &magic,
212 kPeekTimeout) && 212 strlen(kMojoMagic), kPeekTimeout) &&
213 magic == kMojoMagic; 213 magic == kMojoMagic;
214 } 214 }
215 215
216 bool NetworkFetcher::PeekFirstLine(std::string* line) { 216 bool NetworkFetcher::PeekFirstLine(std::string* line) {
217 return BlockingPeekLine(response_->body.get(), line, kMaxShebangLength, 217 return shell::BlockingPeekLine(response_->body.get(), line, kMaxShebangLength,
218 kPeekTimeout); 218 kPeekTimeout);
219 } 219 }
220 220
221 void NetworkFetcher::StartNetworkRequest(mojo::URLRequestPtr request, 221 void NetworkFetcher::StartNetworkRequest(mojo::URLRequestPtr request,
222 URLLoaderFactory* url_loader_factory) { 222 URLLoaderFactory* url_loader_factory) {
223 TRACE_EVENT_ASYNC_BEGIN1("mojo_shell", "NetworkFetcher::NetworkRequest", this, 223 TRACE_EVENT_ASYNC_BEGIN1("mojo_shell", "NetworkFetcher::NetworkRequest", this,
224 "url", request->url.To<std::string>()); 224 "url", request->url.To<std::string>());
225 request->auto_follow_redirects = false; 225 request->auto_follow_redirects = false;
226 request->bypass_cache = disable_cache_; 226 request->bypass_cache = disable_cache_;
227 227
228 url_loader_factory->CreateURLLoader(GetProxy(&url_loader_)); 228 url_loader_factory->CreateURLLoader(GetProxy(&url_loader_));
(...skipping 18 matching lines...) Expand all
247 << response->status_line << "): " 247 << response->status_line << "): "
248 << "while fetching " << response->url; 248 << "while fetching " << response->url;
249 loader_callback_.Run(nullptr); 249 loader_callback_.Run(nullptr);
250 return; 250 return;
251 } 251 }
252 252
253 response_ = response.Pass(); 253 response_ = response.Pass();
254 loader_callback_.Run(owner.Pass()); 254 loader_callback_.Run(owner.Pass());
255 } 255 }
256 256
257 } // namespace shell 257 } // namespace fetcher
258 } // namespace mojo 258 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/fetcher/network_fetcher.h ('k') | mojo/fetcher/switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698