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

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

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

Powered by Google App Engine
This is Rietveld 408576698