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

Side by Side Diff: content/browser/appcache/appcache_url_loader_factory.cc

Issue 2891773002: Add a stub implementation of the URLLoaderFactory for AppCache. (Closed)
Patch Set: Call the network service if the origin is not in the usage map in the AppCacheStorage instance 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/appcache/appcache_url_loader_factory.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "content/browser/appcache/appcache_entry.h"
10 #include "content/browser/appcache/appcache_policy.h"
11 #include "content/browser/appcache/appcache_request.h"
12 #include "content/browser/appcache/appcache_storage.h"
13 #include "content/browser/appcache/chrome_appcache_service.h"
14 #include "content/browser/url_loader_factory_getter.h"
15 #include "content/common/network_service.mojom.h"
16 #include "content/common/resource_request.h"
17 #include "content/common/url_loader.mojom.h"
18 #include "content/common/url_loader_factory.mojom.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "mojo/public/cpp/bindings/associated_binding.h"
21 #include "mojo/public/cpp/bindings/associated_interface_ptr.h"
22 #include "mojo/public/cpp/bindings/binding_set.h"
23
24 namespace content {
25
26 namespace {
27
28 // Handles AppCache URL loads for the network service.
29 class AppCacheURLLoader : public AppCacheStorage::Delegate,
30 public mojom::URLLoader {
31 public:
32 AppCacheURLLoader(const ResourceRequest& request,
33 mojom::URLLoaderAssociatedRequest url_loader_request,
34 int32_t routing_id,
35 int32_t request_id,
36 mojom::URLLoaderClientPtr client_info,
37 ChromeAppCacheService* appcache_service,
38 URLLoaderFactoryGetter* factory_getter)
39 : request_(request),
40 routing_id_(routing_id),
41 request_id_(request_id),
42 client_info_(std::move(client_info)),
43 appcache_service_(appcache_service),
44 factory_getter_(factory_getter),
45 binding_(this, std::move(url_loader_request)) {
46 binding_.set_connection_error_handler(base::Bind(
47 &AppCacheURLLoader::OnConnectionError, base::Unretained(this)));
48 }
49
50 ~AppCacheURLLoader() override {}
51
52 void Start() {
53 // If the origin does not exist in the AppCache usage map, then we can
54 // safely call the network service here.
55 if (appcache_service_->storage()->usage_map()->find(
56 request_.url.GetOrigin()) ==
57 appcache_service_->storage()->usage_map()->end()) {
58 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart(
59 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_,
60 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_));
61 return;
62 }
63
64 appcache_service_->storage()->FindResponseForMainRequest(request_.url,
65 GURL(), this);
66 }
67
68 // mojom::URLLoader implementation:
69 void FollowRedirect() override {
70 network_loader_request_->FollowRedirect();
71 }
72
73 void SetPriority(net::RequestPriority priority,
74 int32_t intra_priority_value) override {
75 DCHECK(false);
76 }
77
78 private:
79 // AppCacheStorage::Delegate methods.
80 void OnMainResponseFound(const GURL& url,
81 const AppCacheEntry& entry,
82 const GURL& fallback_url,
83 const AppCacheEntry& fallback_entry,
84 int64_t cache_id,
85 int64_t group_id,
86 const GURL& manifest_url) override {
87 AppCachePolicy* policy = appcache_service_->appcache_policy();
88 bool was_blocked_by_policy =
89 !manifest_url.is_empty() && policy &&
90 !policy->CanLoadAppCache(manifest_url,
91 request_.first_party_for_cookies);
92
93 if (was_blocked_by_policy || !entry.has_response_id() ||
94 cache_id == kAppCacheNoCacheId) {
95 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart(
96 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_,
97 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_));
98 } else {
99 DLOG(WARNING) << "AppCache found for url " << url
100 << " Returning AppCache factory\n";
101 // TODO(ananta)
102 // Provide the plumbing to initiate AppCache requests here.
103 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart(
104 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_,
105 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_));
106 }
107 }
108
109 void OnConnectionError() { delete this; }
110
111 // The current request.
112 ResourceRequest request_;
113
114 // URLLoader proxy for the network service.
115 mojom::URLLoaderAssociatedPtr network_loader_request_;
116
117 // Routing id of the request. This is 0 for navigation requests. For
118 // subresource requests it is non zero.
119 int routing_id_;
120
121 // Request id.
122 int request_id_;
123
124 // The URLLoaderClient pointer. We call this interface with notifications
125 // about the URL load
126 mojom::URLLoaderClientPtr client_info_;
127
128 // Used to query AppCacheStorage to see if a request can be served out of the
129 /// AppCache.
130 scoped_refptr<ChromeAppCacheService> appcache_service_;
131
132 // Used to retrieve the network service factory to pass requests to the
133 // network service.
134 scoped_refptr<URLLoaderFactoryGetter> factory_getter_;
135
136 // Binds the URLLoaderClient with us.
137 mojo::AssociatedBinding<mojom::URLLoader> binding_;
138
139 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader);
140 };
141
142 } // namespace
143
144 // Implements the URLLoaderFactory mojom for AppCache requests.
145 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory(
146 ChromeAppCacheService* appcache_service,
147 URLLoaderFactoryGetter* factory_getter)
148 : appcache_service_(appcache_service), factory_getter_(factory_getter) {}
149
150 AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {}
151
152 // static
153 void AppCacheURLLoaderFactory::CreateURLLoaderFactory(
154 mojom::URLLoaderFactoryRequest request,
155 ChromeAppCacheService* appcache_service,
156 URLLoaderFactoryGetter* factory_getter) {
157 std::unique_ptr<AppCacheURLLoaderFactory> factory_instance(
158 new AppCacheURLLoaderFactory(appcache_service, factory_getter));
159 AppCacheURLLoaderFactory* raw_factory = factory_instance.get();
160 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance),
161 std::move(request));
162 }
163
164 void AppCacheURLLoaderFactory::CreateLoaderAndStart(
165 mojom::URLLoaderAssociatedRequest url_loader_request,
166 int32_t routing_id,
167 int32_t request_id,
168 uint32_t options,
169 const ResourceRequest& request,
170 mojom::URLLoaderClientPtr client) {
171 DCHECK_CURRENTLY_ON(BrowserThread::IO);
172
173 // This will get deleted when the connection is dropped by the client.
174 AppCacheURLLoader* loader = new AppCacheURLLoader(
175 request, std::move(url_loader_request), routing_id, request_id,
176 std::move(client), appcache_service_.get(), factory_getter_.get());
177 loader->Start();
178 }
179
180 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id,
181 int32_t request_id,
182 const ResourceRequest& request,
183 SyncLoadCallback callback) {
184 NOTREACHED();
185 }
186
187 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698