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

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

Issue 1874893002: Convert //content/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_request_handler.h" 5 #include "content/browser/appcache/appcache_request_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "content/browser/appcache/appcache.h" 10 #include "content/browser/appcache/appcache.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 // Clear out our 'found' fields since we're starting a request for a 73 // Clear out our 'found' fields since we're starting a request for a
74 // new resource, any values in those fields are no longer valid. 74 // new resource, any values in those fields are no longer valid.
75 found_entry_ = AppCacheEntry(); 75 found_entry_ = AppCacheEntry();
76 found_fallback_entry_ = AppCacheEntry(); 76 found_fallback_entry_ = AppCacheEntry();
77 found_cache_id_ = kAppCacheNoCacheId; 77 found_cache_id_ = kAppCacheNoCacheId;
78 found_manifest_url_ = GURL(); 78 found_manifest_url_ = GURL();
79 found_network_namespace_ = false; 79 found_network_namespace_ = false;
80 80
81 scoped_ptr<AppCacheURLRequestJob> job; 81 std::unique_ptr<AppCacheURLRequestJob> job;
82 if (is_main_resource()) 82 if (is_main_resource())
83 job = MaybeLoadMainResource(request, network_delegate); 83 job = MaybeLoadMainResource(request, network_delegate);
84 else 84 else
85 job = MaybeLoadSubResource(request, network_delegate); 85 job = MaybeLoadSubResource(request, network_delegate);
86 86
87 // If its been setup to deliver a network response, we can just delete 87 // If its been setup to deliver a network response, we can just delete
88 // it now and return NULL instead to achieve that since it couldn't 88 // it now and return NULL instead to achieve that since it couldn't
89 // have been started yet. 89 // have been started yet.
90 if (job && job->is_delivering_network_response()) { 90 if (job && job->is_delivering_network_response()) {
91 DCHECK(!job->has_been_started()); 91 DCHECK(!job->has_been_started());
(...skipping 14 matching lines...) Expand all
106 return NULL; 106 return NULL;
107 // TODO(vabr) This is a temporary fix (see crbug/141114). We should get rid of 107 // TODO(vabr) This is a temporary fix (see crbug/141114). We should get rid of
108 // it once a more general solution to crbug/121325 is in place. 108 // it once a more general solution to crbug/121325 is in place.
109 if (!maybe_load_resource_executed_) 109 if (!maybe_load_resource_executed_)
110 return NULL; 110 return NULL;
111 if (request->url().GetOrigin() == location.GetOrigin()) 111 if (request->url().GetOrigin() == location.GetOrigin())
112 return NULL; 112 return NULL;
113 113
114 DCHECK(!job_.get()); // our jobs never generate redirects 114 DCHECK(!job_.get()); // our jobs never generate redirects
115 115
116 scoped_ptr<AppCacheURLRequestJob> job; 116 std::unique_ptr<AppCacheURLRequestJob> job;
117 if (found_fallback_entry_.has_response_id()) { 117 if (found_fallback_entry_.has_response_id()) {
118 // 6.9.6, step 4: If this results in a redirect to another origin, 118 // 6.9.6, step 4: If this results in a redirect to another origin,
119 // get the resource of the fallback entry. 119 // get the resource of the fallback entry.
120 job = CreateJob(request, network_delegate); 120 job = CreateJob(request, network_delegate);
121 DeliverAppCachedResponse( 121 DeliverAppCachedResponse(
122 found_fallback_entry_, found_cache_id_, found_group_id_, 122 found_fallback_entry_, found_cache_id_, found_group_id_,
123 found_manifest_url_, true, found_namespace_entry_url_); 123 found_manifest_url_, true, found_namespace_entry_url_);
124 } else if (!found_network_namespace_) { 124 } else if (!found_network_namespace_) {
125 // 6.9.6, step 6: Fail the resource load. 125 // 6.9.6, step 6: Fail the resource load.
126 job = CreateJob(request, network_delegate); 126 job = CreateJob(request, network_delegate);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 const std::string kFallbackOverrideValue( 163 const std::string kFallbackOverrideValue(
164 "disallow-fallback"); 164 "disallow-fallback");
165 std::string header_value; 165 std::string header_value;
166 request->GetResponseHeaderByName(kFallbackOverrideHeader, &header_value); 166 request->GetResponseHeaderByName(kFallbackOverrideHeader, &header_value);
167 if (header_value == kFallbackOverrideValue) 167 if (header_value == kFallbackOverrideValue)
168 return NULL; 168 return NULL;
169 } 169 }
170 170
171 // 6.9.6, step 4: If this results in a 4xx or 5xx status code 171 // 6.9.6, step 4: If this results in a 4xx or 5xx status code
172 // or there were network errors, get the resource of the fallback entry. 172 // or there were network errors, get the resource of the fallback entry.
173 scoped_ptr<AppCacheURLRequestJob> job = CreateJob(request, network_delegate); 173 std::unique_ptr<AppCacheURLRequestJob> job =
174 CreateJob(request, network_delegate);
174 DeliverAppCachedResponse( 175 DeliverAppCachedResponse(
175 found_fallback_entry_, found_cache_id_, found_group_id_, 176 found_fallback_entry_, found_cache_id_, found_group_id_,
176 found_manifest_url_, true, found_namespace_entry_url_); 177 found_manifest_url_, true, found_namespace_entry_url_);
177 return job.release(); 178 return job.release();
178 } 179 }
179 180
180 void AppCacheRequestHandler::GetExtraResponseInfo(int64_t* cache_id, 181 void AppCacheRequestHandler::GetExtraResponseInfo(int64_t* cache_id,
181 GURL* manifest_url) { 182 GURL* manifest_url) {
182 *cache_id = cache_id_; 183 *cache_id = cache_id_;
183 *manifest_url = manifest_url_; 184 *manifest_url = manifest_url_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 manifest_url_ = GURL(); 271 manifest_url_ = GURL();
271 272
272 cache_entry_not_found_ = job_->cache_entry_not_found(); 273 cache_entry_not_found_ = job_->cache_entry_not_found();
273 is_delivering_network_response_ = job_->is_delivering_network_response(); 274 is_delivering_network_response_ = job_->is_delivering_network_response();
274 275
275 storage()->CancelDelegateCallbacks(this); 276 storage()->CancelDelegateCallbacks(this);
276 277
277 job_.reset(); 278 job_.reset();
278 } 279 }
279 280
280 scoped_ptr<AppCacheURLRequestJob> AppCacheRequestHandler::CreateJob( 281 std::unique_ptr<AppCacheURLRequestJob> AppCacheRequestHandler::CreateJob(
281 net::URLRequest* request, 282 net::URLRequest* request,
282 net::NetworkDelegate* network_delegate) { 283 net::NetworkDelegate* network_delegate) {
283 scoped_ptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( 284 std::unique_ptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob(
284 request, network_delegate, storage(), host_, is_main_resource(), 285 request, network_delegate, storage(), host_, is_main_resource(),
285 base::Bind(&AppCacheRequestHandler::OnPrepareToRestart, 286 base::Bind(&AppCacheRequestHandler::OnPrepareToRestart,
286 base::Unretained(this)))); 287 base::Unretained(this))));
287 job_ = job->GetWeakPtr(); 288 job_ = job->GetWeakPtr();
288 return job; 289 return job;
289 } 290 }
290 291
291 // Main-resource handling ---------------------------------------------- 292 // Main-resource handling ----------------------------------------------
292 293
293 scoped_ptr<AppCacheURLRequestJob> AppCacheRequestHandler::MaybeLoadMainResource( 294 std::unique_ptr<AppCacheURLRequestJob>
295 AppCacheRequestHandler::MaybeLoadMainResource(
294 net::URLRequest* request, 296 net::URLRequest* request,
295 net::NetworkDelegate* network_delegate) { 297 net::NetworkDelegate* network_delegate) {
296 DCHECK(!job_.get()); 298 DCHECK(!job_.get());
297 DCHECK(host_); 299 DCHECK(host_);
298 300
299 // If a page falls into the scope of a ServiceWorker, any matching AppCaches 301 // If a page falls into the scope of a ServiceWorker, any matching AppCaches
300 // should be ignored. This depends on the ServiceWorker handler being invoked 302 // should be ignored. This depends on the ServiceWorker handler being invoked
301 // prior to the AppCache handler. 303 // prior to the AppCache handler.
302 if (ServiceWorkerRequestHandler::IsControlledByServiceWorker(request)) { 304 if (ServiceWorkerRequestHandler::IsControlledByServiceWorker(request)) {
303 host_->enable_cache_selection(false); 305 host_->enable_cache_selection(false);
304 return nullptr; 306 return nullptr;
305 } 307 }
306 308
307 host_->enable_cache_selection(true); 309 host_->enable_cache_selection(true);
308 310
309 const AppCacheHost* spawning_host = 311 const AppCacheHost* spawning_host =
310 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ? 312 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ?
311 host_ : host_->GetSpawningHost(); 313 host_ : host_->GetSpawningHost();
312 GURL preferred_manifest_url = spawning_host ? 314 GURL preferred_manifest_url = spawning_host ?
313 spawning_host->preferred_manifest_url() : GURL(); 315 spawning_host->preferred_manifest_url() : GURL();
314 316
315 // We may have to wait for our storage query to complete, but 317 // We may have to wait for our storage query to complete, but
316 // this query can also complete syncrhonously. 318 // this query can also complete syncrhonously.
317 scoped_ptr<AppCacheURLRequestJob> job = CreateJob(request, network_delegate); 319 std::unique_ptr<AppCacheURLRequestJob> job =
320 CreateJob(request, network_delegate);
318 storage()->FindResponseForMainRequest( 321 storage()->FindResponseForMainRequest(
319 request->url(), preferred_manifest_url, this); 322 request->url(), preferred_manifest_url, this);
320 return job; 323 return job;
321 } 324 }
322 325
323 void AppCacheRequestHandler::OnMainResponseFound( 326 void AppCacheRequestHandler::OnMainResponseFound(
324 const GURL& url, 327 const GURL& url,
325 const AppCacheEntry& entry, 328 const AppCacheEntry& entry,
326 const GURL& namespace_entry_url, 329 const GURL& namespace_entry_url,
327 const AppCacheEntry& fallback_entry, 330 const AppCacheEntry& fallback_entry,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 DeliverAppCachedResponse( 388 DeliverAppCachedResponse(
386 found_entry_, found_cache_id_, found_group_id_, found_manifest_url_, 389 found_entry_, found_cache_id_, found_group_id_, found_manifest_url_,
387 false, found_namespace_entry_url_); 390 false, found_namespace_entry_url_);
388 } else { 391 } else {
389 DeliverNetworkResponse(); 392 DeliverNetworkResponse();
390 } 393 }
391 } 394 }
392 395
393 // Sub-resource handling ---------------------------------------------- 396 // Sub-resource handling ----------------------------------------------
394 397
395 scoped_ptr<AppCacheURLRequestJob> AppCacheRequestHandler::MaybeLoadSubResource( 398 std::unique_ptr<AppCacheURLRequestJob>
399 AppCacheRequestHandler::MaybeLoadSubResource(
396 net::URLRequest* request, 400 net::URLRequest* request,
397 net::NetworkDelegate* network_delegate) { 401 net::NetworkDelegate* network_delegate) {
398 DCHECK(!job_.get()); 402 DCHECK(!job_.get());
399 403
400 if (host_->is_selection_pending()) { 404 if (host_->is_selection_pending()) {
401 // We have to wait until cache selection is complete and the 405 // We have to wait until cache selection is complete and the
402 // selected cache is loaded. 406 // selected cache is loaded.
403 is_waiting_for_cache_selection_ = true; 407 is_waiting_for_cache_selection_ = true;
404 return CreateJob(request, network_delegate); 408 return CreateJob(request, network_delegate);
405 } 409 }
406 410
407 if (!host_->associated_cache() || 411 if (!host_->associated_cache() ||
408 !host_->associated_cache()->is_complete() || 412 !host_->associated_cache()->is_complete() ||
409 host_->associated_cache()->owning_group()->is_being_deleted()) { 413 host_->associated_cache()->owning_group()->is_being_deleted()) {
410 return nullptr; 414 return nullptr;
411 } 415 }
412 416
413 scoped_ptr<AppCacheURLRequestJob> job = CreateJob(request, network_delegate); 417 std::unique_ptr<AppCacheURLRequestJob> job =
418 CreateJob(request, network_delegate);
414 ContinueMaybeLoadSubResource(); 419 ContinueMaybeLoadSubResource();
415 return job; 420 return job;
416 } 421 }
417 422
418 void AppCacheRequestHandler::ContinueMaybeLoadSubResource() { 423 void AppCacheRequestHandler::ContinueMaybeLoadSubResource() {
419 // 6.9.6 Changes to the networking model 424 // 6.9.6 Changes to the networking model
420 // If the resource is not to be fetched using the HTTP GET mechanism or 425 // If the resource is not to be fetched using the HTTP GET mechanism or
421 // equivalent ... then fetch the resource normally. 426 // equivalent ... then fetch the resource normally.
422 DCHECK(job_.get()); 427 DCHECK(job_.get());
423 DCHECK(host_->associated_cache() && host_->associated_cache()->is_complete()); 428 DCHECK(host_->associated_cache() && host_->associated_cache()->is_complete());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 if (!host_->associated_cache() || 487 if (!host_->associated_cache() ||
483 !host_->associated_cache()->is_complete()) { 488 !host_->associated_cache()->is_complete()) {
484 DeliverNetworkResponse(); 489 DeliverNetworkResponse();
485 return; 490 return;
486 } 491 }
487 492
488 ContinueMaybeLoadSubResource(); 493 ContinueMaybeLoadSubResource();
489 } 494 }
490 495
491 } // namespace content 496 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_request_handler.h ('k') | content/browser/appcache/appcache_request_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698