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" |
11 #include "content/browser/loader/async_revalidation_driver.h" | 11 #include "content/browser/loader/async_revalidation_driver.h" |
12 #include "content/browser/loader/resource_message_filter.h" | |
13 #include "content/browser/loader/resource_request_info_impl.h" | 12 #include "content/browser/loader/resource_request_info_impl.h" |
14 #include "content/browser/loader/resource_scheduler.h" | 13 #include "content/browser/loader/resource_scheduler.h" |
15 #include "content/common/resource_messages.h" | 14 #include "content/common/resource_messages.h" |
16 #include "content/common/resource_request.h" | 15 #include "content/common/resource_request.h" |
17 #include "content/public/browser/resource_throttle.h" | 16 #include "content/public/browser/resource_throttle.h" |
18 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
19 #include "net/http/http_transaction_factory.h" | 18 #include "net/http/http_transaction_factory.h" |
20 #include "net/http/http_util.h" | 19 #include "net/http/http_util.h" |
21 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
22 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
(...skipping 22 matching lines...) Expand all Loading... |
45 std::tie(rhs.resource_context, rhs.http_cache, rhs.url_key); | 44 std::tie(rhs.resource_context, rhs.http_cache, rhs.url_key); |
46 } | 45 } |
47 | 46 |
48 AsyncRevalidationManager::AsyncRevalidationManager() {} | 47 AsyncRevalidationManager::AsyncRevalidationManager() {} |
49 | 48 |
50 AsyncRevalidationManager::~AsyncRevalidationManager() { | 49 AsyncRevalidationManager::~AsyncRevalidationManager() { |
51 DCHECK(in_progress_.empty()); | 50 DCHECK(in_progress_.empty()); |
52 } | 51 } |
53 | 52 |
54 void AsyncRevalidationManager::BeginAsyncRevalidation( | 53 void AsyncRevalidationManager::BeginAsyncRevalidation( |
55 const net::URLRequest& for_request, | 54 net::URLRequest* for_request, |
56 ResourceScheduler* scheduler) { | 55 ResourceScheduler* scheduler) { |
57 DCHECK_EQ(for_request.url_chain().size(), 1u); | 56 DCHECK_EQ(for_request->url_chain().size(), 1u); |
58 const ResourceRequestInfoImpl* info = | 57 ResourceRequestInfoImpl* info = |
59 ResourceRequestInfoImpl::ForRequest(&for_request); | 58 ResourceRequestInfoImpl::ForRequest(for_request); |
60 DCHECK(info); | 59 DCHECK(info); |
61 if (!info->filter()) { | 60 DCHECK(info->requester_info()->IsRenderer()); |
| 61 if (!info->requester_info()->filter()) { |
62 // The child has gone away and we can no longer get ResourceContext and | 62 // The child has gone away and we can no longer get ResourceContext and |
63 // URLRequestContext to perform async revalidation. | 63 // URLRequestContext to perform async revalidation. |
64 // This can happen in the following cases, ordered from bad to not-so-bad | 64 // This can happen in the following cases, ordered from bad to not-so-bad |
65 // | 65 // |
66 // 1. PlzNavigate (but enabling PlzNavigate automatically disables | 66 // 1. PlzNavigate (but enabling PlzNavigate automatically disables |
67 // stale-while-revalidate; see crbug.com/561609) | 67 // stale-while-revalidate; see crbug.com/561609) |
68 // 2. <link rel=prefetch> may read a stale cache entry without a | 68 // 2. <link rel=prefetch> may read a stale cache entry without a |
69 // revalidation being performed if the original renderer goes away. This | 69 // revalidation being performed if the original renderer goes away. This |
70 // is a lost optimisation opportunity. | 70 // is a lost optimisation opportunity. |
71 // | 71 // |
(...skipping 10 matching lines...) Expand all Loading... |
82 // | 82 // |
83 // TODO(ricea): Resolve these lifetime issues. crbug.com/561591 | 83 // TODO(ricea): Resolve these lifetime issues. crbug.com/561591 |
84 return; | 84 return; |
85 } | 85 } |
86 | 86 |
87 ResourceContext* resource_context = nullptr; | 87 ResourceContext* resource_context = nullptr; |
88 net::URLRequestContext* request_context = nullptr; | 88 net::URLRequestContext* request_context = nullptr; |
89 | 89 |
90 // The embedder of //content needs to ensure that the URLRequestContext object | 90 // The embedder of //content needs to ensure that the URLRequestContext object |
91 // remains valid until after the ResourceContext object is destroyed. | 91 // remains valid until after the ResourceContext object is destroyed. |
92 info->filter()->GetContexts(info->GetResourceType(), &resource_context, | 92 info->requester_info()->GetContexts(info->GetResourceType(), |
93 &request_context); | 93 &resource_context, &request_context); |
94 | 94 |
95 AsyncRevalidationKey async_revalidation_key( | 95 AsyncRevalidationKey async_revalidation_key( |
96 resource_context, request_context->http_transaction_factory()->GetCache(), | 96 resource_context, request_context->http_transaction_factory()->GetCache(), |
97 for_request.url()); | 97 for_request->url()); |
98 std::pair<AsyncRevalidationMap::iterator, bool> insert_result = | 98 std::pair<AsyncRevalidationMap::iterator, bool> insert_result = |
99 in_progress_.insert(AsyncRevalidationMap::value_type( | 99 in_progress_.insert(AsyncRevalidationMap::value_type( |
100 async_revalidation_key, std::unique_ptr<AsyncRevalidationDriver>())); | 100 async_revalidation_key, std::unique_ptr<AsyncRevalidationDriver>())); |
101 if (!insert_result.second) { | 101 if (!insert_result.second) { |
102 // A matching async revalidation is already in progress for this cache; we | 102 // A matching async revalidation is already in progress for this cache; we |
103 // don't need another one. | 103 // don't need another one. |
104 return; | 104 return; |
105 } | 105 } |
106 | 106 |
107 net::HttpRequestHeaders headers; | 107 net::HttpRequestHeaders headers; |
108 headers.AddHeadersFromString(info->original_headers()); | 108 headers.AddHeadersFromString(info->original_headers()); |
109 | 109 |
110 // Construct the request. | 110 // Construct the request. |
111 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( | 111 std::unique_ptr<net::URLRequest> new_request = |
112 for_request.url(), net::IDLE, nullptr); | 112 request_context->CreateRequest(for_request->url(), net::IDLE, nullptr); |
113 | 113 |
114 new_request->set_method(for_request.method()); | 114 new_request->set_method(for_request->method()); |
115 new_request->set_first_party_for_cookies( | 115 new_request->set_first_party_for_cookies( |
116 for_request.first_party_for_cookies()); | 116 for_request->first_party_for_cookies()); |
117 new_request->set_initiator(for_request.initiator()); | 117 new_request->set_initiator(for_request->initiator()); |
118 new_request->set_first_party_url_policy(for_request.first_party_url_policy()); | 118 new_request->set_first_party_url_policy( |
| 119 for_request->first_party_url_policy()); |
119 | 120 |
120 new_request->SetReferrer(for_request.referrer()); | 121 new_request->SetReferrer(for_request->referrer()); |
121 new_request->set_referrer_policy(for_request.referrer_policy()); | 122 new_request->set_referrer_policy(for_request->referrer_policy()); |
122 | 123 |
123 new_request->SetExtraRequestHeaders(headers); | 124 new_request->SetExtraRequestHeaders(headers); |
124 | 125 |
125 // Remove LOAD_SUPPORT_ASYNC_REVALIDATION and LOAD_MAIN_FRAME_DEPRECATED | 126 // Remove LOAD_SUPPORT_ASYNC_REVALIDATION and LOAD_MAIN_FRAME_DEPRECATED |
126 // flags. | 127 // flags. |
127 // Also remove things which shouldn't have been there to begin with, | 128 // Also remove things which shouldn't have been there to begin with, |
128 // and unrecognised flags. | 129 // and unrecognised flags. |
129 int load_flags = | 130 int load_flags = |
130 for_request.load_flags() & | 131 for_request->load_flags() & |
131 (net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_BYPASS_PROXY | | 132 (net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_BYPASS_PROXY | |
132 net::LOAD_VERIFY_EV_CERT | net::LOAD_DO_NOT_SEND_COOKIES | | 133 net::LOAD_VERIFY_EV_CERT | net::LOAD_DO_NOT_SEND_COOKIES | |
133 net::LOAD_DO_NOT_SEND_AUTH_DATA | net::LOAD_MAYBE_USER_GESTURE | | 134 net::LOAD_DO_NOT_SEND_AUTH_DATA | net::LOAD_MAYBE_USER_GESTURE | |
134 net::LOAD_DO_NOT_USE_EMBEDDED_IDENTITY); | 135 net::LOAD_DO_NOT_USE_EMBEDDED_IDENTITY); |
135 new_request->SetLoadFlags(load_flags); | 136 new_request->SetLoadFlags(load_flags); |
136 | 137 |
137 // These values would be -1 if the request was created by PlzNavigate. This | 138 // These values would be -1 if the request was created by PlzNavigate. This |
138 // would cause the async revalidation to start immediately. | 139 // would cause the async revalidation to start immediately. |
139 // stale-while-revalidate is disabled when PlzNavigate is enabled | 140 // stale-while-revalidate is disabled when PlzNavigate is enabled |
140 // to prevent this and other issues. See crbug.com/561610. | 141 // to prevent this and other issues. See crbug.com/561610. |
(...skipping 43 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 |