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

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

Issue 2956373002: Add support for subresource request loads in AppCache for the network service. (Closed)
Patch Set: Moved the SubresourceLoadInfo structure to the appcache_url_loader_job.h/.cc files. Created 3 years, 5 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
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/browser/appcache/appcache_subresource_url_factory.h" 5 #include "content/browser/appcache/appcache_subresource_url_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/appcache/appcache_host.h"
9 #include "content/browser/appcache/appcache_request_handler.h" 10 #include "content/browser/appcache/appcache_request_handler.h"
10 #include "content/browser/appcache/appcache_url_loader_job.h" 11 #include "content/browser/appcache/appcache_url_loader_job.h"
11 #include "content/browser/appcache/appcache_url_loader_request.h" 12 #include "content/browser/appcache/appcache_url_loader_request.h"
12 #include "content/browser/url_loader_factory_getter.h" 13 #include "content/browser/url_loader_factory_getter.h"
13 #include "content/common/resource_request.h" 14 #include "content/common/resource_request.h"
14 #include "content/common/url_loader_factory.mojom.h" 15 #include "content/common/url_loader_factory.mojom.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "mojo/public/cpp/bindings/binding.h" 17 #include "mojo/public/cpp/bindings/binding.h"
17 #include "mojo/public/cpp/bindings/binding_set.h" 18 #include "mojo/public/cpp/bindings/binding_set.h"
18 #include "mojo/public/cpp/bindings/interface_ptr.h" 19 #include "mojo/public/cpp/bindings/interface_ptr.h"
19 #include "net/traffic_annotation/network_traffic_annotation.h" 20 #include "net/traffic_annotation/network_traffic_annotation.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 // Implements the URLLoaderFactory mojom for AppCache requests. 24 // Implements the URLLoaderFactory mojom for AppCache requests.
24 AppCacheSubresourceURLFactory::AppCacheSubresourceURLFactory( 25 AppCacheSubresourceURLFactory::AppCacheSubresourceURLFactory(
25 mojom::URLLoaderFactoryRequest request, 26 mojom::URLLoaderFactoryRequest request,
26 URLLoaderFactoryGetter* default_url_loader_factory_getter) 27 URLLoaderFactoryGetter* default_url_loader_factory_getter,
28 base::WeakPtr<AppCacheHost> host)
27 : binding_(this, std::move(request)), 29 : binding_(this, std::move(request)),
28 default_url_loader_factory_getter_(default_url_loader_factory_getter) { 30 default_url_loader_factory_getter_(default_url_loader_factory_getter),
31 appcache_host_(host->GetWeakPtr()) {
kinuko 2017/07/03 06:34:15 |host|'s already weakptr, isn't it?
ananta 2017/07/03 07:36:47 Sorry I missed this. Fixed
29 binding_.set_connection_error_handler( 32 binding_.set_connection_error_handler(
30 base::Bind(&AppCacheSubresourceURLFactory::OnConnectionError, 33 base::Bind(&AppCacheSubresourceURLFactory::OnConnectionError,
31 base::Unretained(this))); 34 base::Unretained(this)));
32 } 35 }
33 36
34 AppCacheSubresourceURLFactory::~AppCacheSubresourceURLFactory() {} 37 AppCacheSubresourceURLFactory::~AppCacheSubresourceURLFactory() {}
35 38
36 // static 39 // static
37 mojom::URLLoaderFactoryPtr 40 AppCacheSubresourceURLFactory*
38 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( 41 AppCacheSubresourceURLFactory::CreateURLLoaderFactory(
39 URLLoaderFactoryGetter* default_url_loader_factory_getter) { 42 URLLoaderFactoryGetter* default_url_loader_factory_getter,
40 mojom::URLLoaderFactoryPtr loader_factory; 43 base::WeakPtr<AppCacheHost> host,
41 mojom::URLLoaderFactoryRequest request = mojo::MakeRequest(&loader_factory); 44 mojom::URLLoaderFactoryPtr* loader_factory) {
45 mojom::URLLoaderFactoryRequest request = mojo::MakeRequest(loader_factory);
42 46
43 // This instance will get deleted when the client drops the connection. 47 // This instance will get deleted when the client drops the connection.
44 // Please see OnConnectionError() for details. 48 // Please see OnConnectionError() for details.
45 new AppCacheSubresourceURLFactory(std::move(request), 49 return new AppCacheSubresourceURLFactory(
46 default_url_loader_factory_getter); 50 std::move(request), default_url_loader_factory_getter, host);
47 return loader_factory;
48 } 51 }
49 52
50 void AppCacheSubresourceURLFactory::CreateLoaderAndStart( 53 void AppCacheSubresourceURLFactory::CreateLoaderAndStart(
51 mojom::URLLoaderAssociatedRequest url_loader_request, 54 mojom::URLLoaderAssociatedRequest url_loader_request,
52 int32_t routing_id, 55 int32_t routing_id,
53 int32_t request_id, 56 int32_t request_id,
54 uint32_t options, 57 uint32_t options,
55 const ResourceRequest& request, 58 const ResourceRequest& request,
56 mojom::URLLoaderClientPtr client, 59 mojom::URLLoaderClientPtr client,
57 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { 60 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
58 DCHECK_CURRENTLY_ON(BrowserThread::IO); 61 DCHECK_CURRENTLY_ON(BrowserThread::IO);
59 DLOG(WARNING) << "Received request for loading : " << request.url.spec(); 62 DLOG(WARNING) << "Received request for loading : " << request.url.spec();
60 default_url_loader_factory_getter_->GetNetworkFactory() 63
61 ->get() 64 // If the host is invalid, it means that the renderer has probably died.
62 ->CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest(), routing_id, 65 // (Frame has navigated elsewhere?)
63 request_id, options, request, std::move(client), 66 if (!appcache_host_.get())
64 traffic_annotation); 67 return;
68
69 std::unique_ptr<AppCacheRequestHandler> handler =
70 appcache_host_->CreateRequestHandler(
71 AppCacheURLLoaderRequest::Create(request), request.resource_type,
72 request.should_reset_appcache);
73 if (!handler)
74 return;
75
76 handler->set_network_url_loader_factory_getter(
77 default_url_loader_factory_getter_.get());
78
79 std::unique_ptr<SubresourceLoadInfo> load_info(new SubresourceLoadInfo());
80 load_info->url_loader_request = std::move(url_loader_request);
81 load_info->routing_id = routing_id;
82 load_info->request_id = request_id;
83 load_info->options = options;
84 load_info->request = request;
85 load_info->client = std::move(client);
86 load_info->traffic_annotation = traffic_annotation;
87
88 handler->SetSubresourceRequestLoadInfo(std::move(load_info));
89
90 handler->MaybeLoadResource(nullptr);
91 // The handler is owned by the job.
92 handler.release();
kinuko 2017/07/03 06:34:15 MaybeLoadResource may not call CreateJob, then wou
ananta 2017/07/03 07:36:47 Thanks. done. I added a setter to the AppCacheURLL
65 } 93 }
66 94
67 void AppCacheSubresourceURLFactory::SyncLoad(int32_t routing_id, 95 void AppCacheSubresourceURLFactory::SyncLoad(int32_t routing_id,
68 int32_t request_id, 96 int32_t request_id,
69 const ResourceRequest& request, 97 const ResourceRequest& request,
70 SyncLoadCallback callback) { 98 SyncLoadCallback callback) {
71 NOTREACHED(); 99 NOTREACHED();
72 } 100 }
73 101
74 void AppCacheSubresourceURLFactory::OnConnectionError() { 102 void AppCacheSubresourceURLFactory::OnConnectionError() {
75 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 103 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
76 } 104 }
77 105
78 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698