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

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

Issue 2893233002: Network traffic annotation added to URLLoaderImpl. (Closed)
Patch Set: Changed ParamTraits to StructTraits. Created 3 years, 6 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_url_loader_factory.h" 5 #include "content/browser/appcache/appcache_url_loader_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_entry.h" 9 #include "content/browser/appcache/appcache_entry.h"
10 #include "content/browser/appcache/appcache_policy.h" 10 #include "content/browser/appcache/appcache_policy.h"
11 #include "content/browser/appcache/appcache_request.h" 11 #include "content/browser/appcache/appcache_request.h"
12 #include "content/browser/appcache/appcache_storage.h" 12 #include "content/browser/appcache/appcache_storage.h"
13 #include "content/browser/appcache/chrome_appcache_service.h" 13 #include "content/browser/appcache/chrome_appcache_service.h"
14 #include "content/browser/url_loader_factory_getter.h" 14 #include "content/browser/url_loader_factory_getter.h"
15 #include "content/common/network_service.mojom.h" 15 #include "content/common/network_service.mojom.h"
16 #include "content/common/resource_request.h" 16 #include "content/common/resource_request.h"
17 #include "content/common/url_loader.mojom.h" 17 #include "content/common/url_loader.mojom.h"
18 #include "content/common/url_loader_factory.mojom.h" 18 #include "content/common/url_loader_factory.mojom.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "mojo/public/cpp/bindings/associated_binding.h" 20 #include "mojo/public/cpp/bindings/associated_binding.h"
21 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" 21 #include "mojo/public/cpp/bindings/associated_interface_ptr.h"
22 #include "mojo/public/cpp/bindings/binding_set.h" 22 #include "mojo/public/cpp/bindings/binding_set.h"
23 #include "net/traffic_annotation/network_traffic_annotation.h"
23 24
24 namespace content { 25 namespace content {
25 26
26 namespace { 27 namespace {
27 28
28 // Handles AppCache URL loads for the network service. 29 // Handles AppCache URL loads for the network service.
29 class AppCacheURLLoader : public AppCacheStorage::Delegate, 30 class AppCacheURLLoader : public AppCacheStorage::Delegate,
30 public mojom::URLLoader { 31 public mojom::URLLoader {
31 public: 32 public:
32 AppCacheURLLoader(const ResourceRequest& request, 33 AppCacheURLLoader(const ResourceRequest& request,
33 mojom::URLLoaderAssociatedRequest url_loader_request, 34 mojom::URLLoaderAssociatedRequest url_loader_request,
34 int32_t routing_id, 35 int32_t routing_id,
35 int32_t request_id, 36 int32_t request_id,
36 mojom::URLLoaderClientPtr client_info, 37 mojom::URLLoaderClientPtr client_info,
37 ChromeAppCacheService* appcache_service, 38 ChromeAppCacheService* appcache_service,
38 URLLoaderFactoryGetter* factory_getter) 39 URLLoaderFactoryGetter* factory_getter,
40 const net::NetworkTrafficAnnotationTag& traffic_annotation)
39 : request_(request), 41 : request_(request),
40 routing_id_(routing_id), 42 routing_id_(routing_id),
41 request_id_(request_id), 43 request_id_(request_id),
42 client_info_(std::move(client_info)), 44 client_info_(std::move(client_info)),
43 appcache_service_(appcache_service), 45 appcache_service_(appcache_service),
44 factory_getter_(factory_getter), 46 factory_getter_(factory_getter),
45 binding_(this, std::move(url_loader_request)) { 47 binding_(this, std::move(url_loader_request)),
48 traffic_annotation_(traffic_annotation) {
46 binding_.set_connection_error_handler(base::Bind( 49 binding_.set_connection_error_handler(base::Bind(
47 &AppCacheURLLoader::OnConnectionError, base::Unretained(this))); 50 &AppCacheURLLoader::OnConnectionError, base::Unretained(this)));
48 } 51 }
49 52
50 ~AppCacheURLLoader() override {} 53 ~AppCacheURLLoader() override {}
51 54
52 void Start() { 55 void Start() {
53 // If the origin does not exist in the AppCache usage map, then we can 56 // If the origin does not exist in the AppCache usage map, then we can
54 // safely call the network service here. 57 // safely call the network service here.
55 if (appcache_service_->storage()->usage_map()->find( 58 if (appcache_service_->storage()->usage_map()->find(
56 request_.url.GetOrigin()) == 59 request_.url.GetOrigin()) ==
57 appcache_service_->storage()->usage_map()->end()) { 60 appcache_service_->storage()->usage_map()->end()) {
58 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( 61 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart(
59 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, 62 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_,
60 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); 63 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_),
64 net::MutableNetworkTrafficAnnotationTag(traffic_annotation_));
61 return; 65 return;
62 } 66 }
63 67
64 appcache_service_->storage()->FindResponseForMainRequest(request_.url, 68 appcache_service_->storage()->FindResponseForMainRequest(request_.url,
65 GURL(), this); 69 GURL(), this);
66 } 70 }
67 71
68 // mojom::URLLoader implementation: 72 // mojom::URLLoader implementation:
69 void FollowRedirect() override { network_loader_request_->FollowRedirect(); } 73 void FollowRedirect() override { network_loader_request_->FollowRedirect(); }
70 74
(...skipping 14 matching lines...) Expand all
85 AppCachePolicy* policy = appcache_service_->appcache_policy(); 89 AppCachePolicy* policy = appcache_service_->appcache_policy();
86 bool was_blocked_by_policy = 90 bool was_blocked_by_policy =
87 !manifest_url.is_empty() && policy && 91 !manifest_url.is_empty() && policy &&
88 !policy->CanLoadAppCache(manifest_url, 92 !policy->CanLoadAppCache(manifest_url,
89 request_.first_party_for_cookies); 93 request_.first_party_for_cookies);
90 94
91 if (was_blocked_by_policy || !entry.has_response_id() || 95 if (was_blocked_by_policy || !entry.has_response_id() ||
92 cache_id == kAppCacheNoCacheId) { 96 cache_id == kAppCacheNoCacheId) {
93 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( 97 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart(
94 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, 98 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_,
95 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); 99 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_),
100 net::MutableNetworkTrafficAnnotationTag(NO_TRAFFIC_ANNOTATION_YET));
jochen (gone - plz use gerrit) 2017/06/08 17:00:58 why is this not using traffic_annotation_?
Ramin Halavati 2017/06/09 07:08:53 Done.
96 } else { 101 } else {
97 DLOG(WARNING) << "AppCache found for url " << url 102 DLOG(WARNING) << "AppCache found for url " << url
98 << " Returning AppCache factory\n"; 103 << " Returning AppCache factory\n";
99 // TODO(ananta) 104 // TODO(ananta)
100 // Provide the plumbing to initiate AppCache requests here. 105 // Provide the plumbing to initiate AppCache requests here.
101 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( 106 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart(
102 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, 107 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_,
103 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); 108 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_),
109 net::MutableNetworkTrafficAnnotationTag(NO_TRAFFIC_ANNOTATION_YET));
104 } 110 }
105 } 111 }
106 112
107 void OnConnectionError() { delete this; } 113 void OnConnectionError() { delete this; }
108 114
109 // The current request. 115 // The current request.
110 ResourceRequest request_; 116 ResourceRequest request_;
111 117
112 // URLLoader proxy for the network service. 118 // URLLoader proxy for the network service.
113 mojom::URLLoaderAssociatedPtr network_loader_request_; 119 mojom::URLLoaderAssociatedPtr network_loader_request_;
(...skipping 13 matching lines...) Expand all
127 /// AppCache. 133 /// AppCache.
128 scoped_refptr<ChromeAppCacheService> appcache_service_; 134 scoped_refptr<ChromeAppCacheService> appcache_service_;
129 135
130 // Used to retrieve the network service factory to pass requests to the 136 // Used to retrieve the network service factory to pass requests to the
131 // network service. 137 // network service.
132 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; 138 scoped_refptr<URLLoaderFactoryGetter> factory_getter_;
133 139
134 // Binds the URLLoaderClient with us. 140 // Binds the URLLoaderClient with us.
135 mojo::AssociatedBinding<mojom::URLLoader> binding_; 141 mojo::AssociatedBinding<mojom::URLLoader> binding_;
136 142
143 const net::NetworkTrafficAnnotationTag traffic_annotation_;
144
137 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader); 145 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader);
138 }; 146 };
139 147
140 } // namespace 148 } // namespace
141 149
142 // Implements the URLLoaderFactory mojom for AppCache requests. 150 // Implements the URLLoaderFactory mojom for AppCache requests.
143 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory( 151 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory(
144 ChromeAppCacheService* appcache_service, 152 ChromeAppCacheService* appcache_service,
145 URLLoaderFactoryGetter* factory_getter) 153 URLLoaderFactoryGetter* factory_getter)
146 : appcache_service_(appcache_service), factory_getter_(factory_getter) {} 154 : appcache_service_(appcache_service), factory_getter_(factory_getter) {}
(...skipping 11 matching lines...) Expand all
158 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance), 166 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance),
159 std::move(request)); 167 std::move(request));
160 } 168 }
161 169
162 void AppCacheURLLoaderFactory::CreateLoaderAndStart( 170 void AppCacheURLLoaderFactory::CreateLoaderAndStart(
163 mojom::URLLoaderAssociatedRequest url_loader_request, 171 mojom::URLLoaderAssociatedRequest url_loader_request,
164 int32_t routing_id, 172 int32_t routing_id,
165 int32_t request_id, 173 int32_t request_id,
166 uint32_t options, 174 uint32_t options,
167 const ResourceRequest& request, 175 const ResourceRequest& request,
168 mojom::URLLoaderClientPtr client) { 176 mojom::URLLoaderClientPtr client,
177 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
169 DCHECK_CURRENTLY_ON(BrowserThread::IO); 178 DCHECK_CURRENTLY_ON(BrowserThread::IO);
170 179
171 // This will get deleted when the connection is dropped by the client. 180 // This will get deleted when the connection is dropped by the client.
172 AppCacheURLLoader* loader = new AppCacheURLLoader( 181 AppCacheURLLoader* loader = new AppCacheURLLoader(
173 request, std::move(url_loader_request), routing_id, request_id, 182 request, std::move(url_loader_request), routing_id, request_id,
174 std::move(client), appcache_service_.get(), factory_getter_.get()); 183 std::move(client), appcache_service_.get(), factory_getter_.get(),
184 static_cast<net::NetworkTrafficAnnotationTag>(traffic_annotation));
175 loader->Start(); 185 loader->Start();
176 } 186 }
177 187
178 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id, 188 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id,
179 int32_t request_id, 189 int32_t request_id,
180 const ResourceRequest& request, 190 const ResourceRequest& request,
181 SyncLoadCallback callback) { 191 SyncLoadCallback callback) {
182 NOTREACHED(); 192 NOTREACHED();
183 } 193 }
184 194
185 } // namespace content 195 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698