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

Side by Side Diff: content/network/cache_url_loader.cc

Issue 2874163004: Add support in the network service for different contexts. (Closed)
Patch Set: review comment and clang fixes Created 3 years, 7 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 | « content/network/cache_url_loader.h ('k') | content/network/network_context.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "content/network/cache_url_loader.h" 5 #include "content/network/cache_url_loader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "content/public/common/url_constants.h" 11 #include "content/public/common/url_constants.h"
12 #include "mojo/common/data_pipe_utils.h" 12 #include "mojo/common/data_pipe_utils.h"
13 #include "net/url_request/view_cache_helper.h" 13 #include "net/url_request/view_cache_helper.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 namespace { 17 namespace {
18 18
19 class CacheURLLoader { 19 class CacheURLLoader {
20 public: 20 public:
21 CacheURLLoader(const ResourceRequest& request, 21 CacheURLLoader(const GURL& url,
22 net::URLRequestContext* request_context, 22 net::URLRequestContext* request_context,
23 mojom::URLLoaderClientPtr client) 23 mojom::URLLoaderClientPtr client)
24 : client_(std::move(client)) { 24 : client_(std::move(client)) {
25 scoped_refptr<net::HttpResponseHeaders> headers( 25 scoped_refptr<net::HttpResponseHeaders> headers(
26 new net::HttpResponseHeaders("HTTP/1.1 200 OK")); 26 new net::HttpResponseHeaders("HTTP/1.1 200 OK"));
27 ResourceResponseHead resource_response; 27 ResourceResponseHead resource_response;
28 resource_response.headers = headers; 28 resource_response.headers = headers;
29 resource_response.mime_type = "text/html"; 29 resource_response.mime_type = "text/html";
30 client_->OnReceiveResponse(resource_response, base::nullopt, nullptr); 30 client_->OnReceiveResponse(resource_response, base::nullopt, nullptr);
31 31
32 std::string cache_key = 32 std::string cache_key =
33 request.url.spec().substr(strlen(kChromeUINetworkViewCacheURL)); 33 url.spec().substr(strlen(kChromeUINetworkViewCacheURL));
34 34
35 int rv; 35 int rv;
36 if (cache_key.empty()) { 36 if (cache_key.empty()) {
37 rv = cache_helper_.GetContentsHTML( 37 rv = cache_helper_.GetContentsHTML(
38 request_context, kChromeUINetworkViewCacheURL, &data_, 38 request_context, kChromeUINetworkViewCacheURL, &data_,
39 base::Bind(&CacheURLLoader::DataAvailable, base::Unretained(this))); 39 base::Bind(&CacheURLLoader::DataAvailable, base::Unretained(this)));
40 } else { 40 } else {
41 rv = cache_helper_.GetEntryInfoHTML( 41 rv = cache_helper_.GetEntryInfoHTML(
42 cache_key, request_context, &data_, 42 cache_key, request_context, &data_,
43 base::Bind(&CacheURLLoader::DataAvailable, base::Unretained(this))); 43 base::Bind(&CacheURLLoader::DataAvailable, base::Unretained(this)));
(...skipping 21 matching lines...) Expand all
65 } 65 }
66 66
67 std::string data_; 67 std::string data_;
68 mojom::URLLoaderClientPtr client_; 68 mojom::URLLoaderClientPtr client_;
69 net::ViewCacheHelper cache_helper_; 69 net::ViewCacheHelper cache_helper_;
70 70
71 DISALLOW_COPY_AND_ASSIGN(CacheURLLoader); 71 DISALLOW_COPY_AND_ASSIGN(CacheURLLoader);
72 }; 72 };
73 } 73 }
74 74
75 void StartCacheURLLoader(const ResourceRequest& request, 75 void StartCacheURLLoader(const GURL& url,
76 net::URLRequestContext* request_context, 76 net::URLRequestContext* request_context,
77 mojom::URLLoaderClientPtr client) { 77 mojom::URLLoaderClientPtr client) {
78 new CacheURLLoader(request, request_context, std::move(client)); 78 new CacheURLLoader(url, request_context, std::move(client));
79 } 79 }
80 80
81 } // namespace content 81 } // namespace content
OLDNEW
« no previous file with comments | « content/network/cache_url_loader.h ('k') | content/network/network_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698