| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/loader/async_revalidation_manager.h" | 5 #include "content/browser/loader/async_revalidation_manager.h" |
| 6 | 6 |
| 7 #include <tuple> | 7 #include <tuple> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 DCHECK(in_progress_.empty()); | 51 DCHECK(in_progress_.empty()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void AsyncRevalidationManager::BeginAsyncRevalidation( | 54 void AsyncRevalidationManager::BeginAsyncRevalidation( |
| 55 const net::URLRequest& for_request, | 55 const net::URLRequest& for_request, |
| 56 ResourceScheduler* scheduler) { | 56 ResourceScheduler* scheduler) { |
| 57 DCHECK_EQ(for_request.url_chain().size(), 1u); | 57 DCHECK_EQ(for_request.url_chain().size(), 1u); |
| 58 const ResourceRequestInfoImpl* info = | 58 const ResourceRequestInfoImpl* info = |
| 59 ResourceRequestInfoImpl::ForRequest(&for_request); | 59 ResourceRequestInfoImpl::ForRequest(&for_request); |
| 60 DCHECK(info); | 60 DCHECK(info); |
| 61 if (!info->filter()) { | 61 if (!info->requester_info().IsRenderer() || |
| 62 !info->requester_info().filter()) { |
| 62 // The child has gone away and we can no longer get ResourceContext and | 63 // The child has gone away and we can no longer get ResourceContext and |
| 63 // URLRequestContext to perform async revalidation. | 64 // URLRequestContext to perform async revalidation. |
| 64 // This can happen in the following cases, ordered from bad to not-so-bad | 65 // This can happen in the following cases, ordered from bad to not-so-bad |
| 65 // | 66 // |
| 66 // 1. PlzNavigate (but enabling PlzNavigate automatically disables | 67 // 1. PlzNavigate (but enabling PlzNavigate automatically disables |
| 67 // stale-while-revalidate; see crbug.com/561609) | 68 // stale-while-revalidate; see crbug.com/561609) |
| 68 // 2. <link rel=prefetch> may read a stale cache entry without a | 69 // 2. <link rel=prefetch> may read a stale cache entry without a |
| 69 // revalidation being performed if the original renderer goes away. This | 70 // revalidation being performed if the original renderer goes away. This |
| 70 // is a lost optimisation opportunity. | 71 // is a lost optimisation opportunity. |
| 71 // | 72 // |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 // | 83 // |
| 83 // TODO(ricea): Resolve these lifetime issues. crbug.com/561591 | 84 // TODO(ricea): Resolve these lifetime issues. crbug.com/561591 |
| 84 return; | 85 return; |
| 85 } | 86 } |
| 86 | 87 |
| 87 ResourceContext* resource_context = nullptr; | 88 ResourceContext* resource_context = nullptr; |
| 88 net::URLRequestContext* request_context = nullptr; | 89 net::URLRequestContext* request_context = nullptr; |
| 89 | 90 |
| 90 // The embedder of //content needs to ensure that the URLRequestContext object | 91 // The embedder of //content needs to ensure that the URLRequestContext object |
| 91 // remains valid until after the ResourceContext object is destroyed. | 92 // remains valid until after the ResourceContext object is destroyed. |
| 92 info->filter()->GetContexts(info->GetResourceType(), &resource_context, | 93 info->requester_info().GetContexts(info->GetResourceType(), &resource_context, |
| 93 &request_context); | 94 &request_context); |
| 94 | 95 |
| 95 AsyncRevalidationKey async_revalidation_key( | 96 AsyncRevalidationKey async_revalidation_key( |
| 96 resource_context, request_context->http_transaction_factory()->GetCache(), | 97 resource_context, request_context->http_transaction_factory()->GetCache(), |
| 97 for_request.url()); | 98 for_request.url()); |
| 98 std::pair<AsyncRevalidationMap::iterator, bool> insert_result = | 99 std::pair<AsyncRevalidationMap::iterator, bool> insert_result = |
| 99 in_progress_.insert(AsyncRevalidationMap::value_type( | 100 in_progress_.insert(AsyncRevalidationMap::value_type( |
| 100 async_revalidation_key, std::unique_ptr<AsyncRevalidationDriver>())); | 101 async_revalidation_key, std::unique_ptr<AsyncRevalidationDriver>())); |
| 101 if (!insert_result.second) { | 102 if (!insert_result.second) { |
| 102 // A matching async revalidation is already in progress for this cache; we | 103 // A matching async revalidation is already in progress for this cache; we |
| 103 // don't need another one. | 104 // don't need another one. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 185 |
| 185 return true; | 186 return true; |
| 186 } | 187 } |
| 187 | 188 |
| 188 void AsyncRevalidationManager::OnAsyncRevalidationComplete( | 189 void AsyncRevalidationManager::OnAsyncRevalidationComplete( |
| 189 AsyncRevalidationMap::iterator it) { | 190 AsyncRevalidationMap::iterator it) { |
| 190 in_progress_.erase(it); | 191 in_progress_.erase(it); |
| 191 } | 192 } |
| 192 | 193 |
| 193 } // namespace content | 194 } // namespace content |
| OLD | NEW |