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

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

Issue 2501343003: PlzNavigate: AppCache support. (Closed)
Patch Set: Fix content_browsertests rednesss Created 4 years 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_dispatcher_host.h" 5 #include "content/browser/appcache/appcache_dispatcher_host.h"
6 6
7 #include <map>
7 #include "base/bind.h" 8 #include "base/bind.h"
8 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
9 #include "content/browser/appcache/chrome_appcache_service.h" 10 #include "content/browser/appcache/chrome_appcache_service.h"
10 #include "content/browser/bad_message.h" 11 #include "content/browser/bad_message.h"
11 #include "content/common/appcache_messages.h" 12 #include "content/common/appcache_messages.h"
13 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/user_metrics.h" 14 #include "content/public/browser/user_metrics.h"
15 #include "content/public/common/browser_side_navigation_policy.h"
16
17 namespace {
18
19 using ProcessIdToHostMap = std::map < int, content::AppCacheDispatcherHost* >;
20 base::LazyInstance<ProcessIdToHostMap> g_process_id_host_map;
21
22 } // namespace
13 23
14 namespace content { 24 namespace content {
15 25
16 AppCacheDispatcherHost::AppCacheDispatcherHost( 26 AppCacheDispatcherHost::AppCacheDispatcherHost(
17 ChromeAppCacheService* appcache_service, 27 ChromeAppCacheService* appcache_service,
18 int process_id) 28 int process_id)
19 : BrowserMessageFilter(AppCacheMsgStart), 29 : BrowserMessageFilter(AppCacheMsgStart),
20 appcache_service_(appcache_service), 30 appcache_service_(appcache_service),
21 frontend_proxy_(this), 31 frontend_proxy_(this),
22 process_id_(process_id), 32 process_id_(process_id),
23 weak_factory_(this) { 33 weak_factory_(this) {
34 g_process_id_host_map.Get()[process_id] = this;
michaeln 2016/12/05 21:52:54 ok, we have to do something about accessing this m
ananta 2016/12/06 01:24:38 Done. Thanks for the tip. PTAL
24 } 35 }
25 36
26 void AppCacheDispatcherHost::OnChannelConnected(int32_t peer_pid) { 37 void AppCacheDispatcherHost::OnChannelConnected(int32_t peer_pid) {
27 if (appcache_service_.get()) { 38 if (!appcache_service_.get())
28 backend_impl_.Initialize( 39 return;
29 appcache_service_.get(), &frontend_proxy_, process_id_); 40
30 get_status_callback_ = 41 backend_impl_.Initialize(appcache_service_.get(), &frontend_proxy_,
31 base::Bind(&AppCacheDispatcherHost::GetStatusCallback, 42 process_id_);
32 weak_factory_.GetWeakPtr()); 43 get_status_callback_ = base::Bind(&AppCacheDispatcherHost::GetStatusCallback,
33 start_update_callback_ = 44 weak_factory_.GetWeakPtr());
34 base::Bind(&AppCacheDispatcherHost::StartUpdateCallback, 45 start_update_callback_ = base::Bind(
35 weak_factory_.GetWeakPtr()); 46 &AppCacheDispatcherHost::StartUpdateCallback, weak_factory_.GetWeakPtr());
36 swap_cache_callback_ = 47 swap_cache_callback_ = base::Bind(&AppCacheDispatcherHost::SwapCacheCallback,
37 base::Bind(&AppCacheDispatcherHost::SwapCacheCallback, 48 weak_factory_.GetWeakPtr());
38 weak_factory_.GetWeakPtr());
39 }
40 } 49 }
41 50
42 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) { 51 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) {
43 bool handled = true; 52 bool handled = true;
44 IPC_BEGIN_MESSAGE_MAP(AppCacheDispatcherHost, message) 53 IPC_BEGIN_MESSAGE_MAP(AppCacheDispatcherHost, message)
45 IPC_MESSAGE_HANDLER(AppCacheHostMsg_RegisterHost, OnRegisterHost) 54 IPC_MESSAGE_HANDLER(AppCacheHostMsg_RegisterHost, OnRegisterHost)
46 IPC_MESSAGE_HANDLER(AppCacheHostMsg_UnregisterHost, OnUnregisterHost) 55 IPC_MESSAGE_HANDLER(AppCacheHostMsg_UnregisterHost, OnUnregisterHost)
47 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SetSpawningHostId, OnSetSpawningHostId) 56 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SetSpawningHostId, OnSetSpawningHostId)
48 IPC_MESSAGE_HANDLER(AppCacheHostMsg_GetResourceList, OnGetResourceList) 57 IPC_MESSAGE_HANDLER(AppCacheHostMsg_GetResourceList, OnGetResourceList)
49 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCache, OnSelectCache) 58 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCache, OnSelectCache)
50 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForWorker, 59 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForWorker,
51 OnSelectCacheForWorker) 60 OnSelectCacheForWorker)
52 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForSharedWorker, 61 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForSharedWorker,
53 OnSelectCacheForSharedWorker) 62 OnSelectCacheForSharedWorker)
54 IPC_MESSAGE_HANDLER(AppCacheHostMsg_MarkAsForeignEntry, 63 IPC_MESSAGE_HANDLER(AppCacheHostMsg_MarkAsForeignEntry,
55 OnMarkAsForeignEntry) 64 OnMarkAsForeignEntry)
56 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_GetStatus, OnGetStatus) 65 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_GetStatus, OnGetStatus)
57 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_StartUpdate, OnStartUpdate) 66 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_StartUpdate, OnStartUpdate)
58 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_SwapCache, OnSwapCache) 67 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_SwapCache, OnSwapCache)
59 IPC_MESSAGE_UNHANDLED(handled = false) 68 IPC_MESSAGE_UNHANDLED(handled = false)
60 IPC_END_MESSAGE_MAP() 69 IPC_END_MESSAGE_MAP()
61 70
62 return handled; 71 return handled;
63 } 72 }
64 73
65 AppCacheDispatcherHost::~AppCacheDispatcherHost() {} 74 AppCacheDispatcherHost::~AppCacheDispatcherHost() {
75 ProcessIdToHostMap::iterator index =
76 g_process_id_host_map.Get().find(process_id_);
77 if ((index != g_process_id_host_map.Get().end()) && index->second == this)
78 g_process_id_host_map.Get().erase(index);
79 }
80
81 void AppCacheDispatcherHost::RegisterPrecreatedHost(
82 std::unique_ptr<AppCacheHost> host) {
83 DCHECK(host.get());
84 DCHECK(IsBrowserSideNavigationEnabled());
85 backend_impl_.RegisterPrecreatedHost(std::move(host));
86 }
66 87
67 void AppCacheDispatcherHost::OnRegisterHost(int host_id) { 88 void AppCacheDispatcherHost::OnRegisterHost(int host_id) {
68 if (appcache_service_.get()) { 89 if (appcache_service_.get()) {
69 if (!backend_impl_.RegisterHost(host_id)) { 90 if (!backend_impl_.RegisterHost(host_id)) {
70 bad_message::ReceivedBadMessage(this, bad_message::ACDH_REGISTER); 91 bad_message::ReceivedBadMessage(this, bad_message::ACDH_REGISTER);
71 } 92 }
72 } 93 }
73 } 94 }
74 95
75 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { 96 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) {
(...skipping 11 matching lines...) Expand all
87 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SET_SPAWNING); 108 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SET_SPAWNING);
88 } 109 }
89 } 110 }
90 111
91 void AppCacheDispatcherHost::OnSelectCache( 112 void AppCacheDispatcherHost::OnSelectCache(
92 int host_id, 113 int host_id,
93 const GURL& document_url, 114 const GURL& document_url,
94 int64_t cache_document_was_loaded_from, 115 int64_t cache_document_was_loaded_from,
95 const GURL& opt_manifest_url) { 116 const GURL& opt_manifest_url) {
96 if (appcache_service_.get()) { 117 if (appcache_service_.get()) {
97 if (!backend_impl_.SelectCache(host_id, 118 if (!backend_impl_.SelectCache(host_id, document_url,
98 document_url,
99 cache_document_was_loaded_from, 119 cache_document_was_loaded_from,
100 opt_manifest_url)) { 120 opt_manifest_url)) {
101 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SELECT_CACHE); 121 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SELECT_CACHE);
102 } 122 }
103 } else { 123 } else {
104 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); 124 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo());
105 } 125 }
106 } 126 }
107 127
108 void AppCacheDispatcherHost::OnSelectCacheForWorker( 128 void AppCacheDispatcherHost::OnSelectCacheForWorker(
109 int host_id, int parent_process_id, int parent_host_id) { 129 int host_id, int parent_process_id, int parent_host_id) {
110 if (appcache_service_.get()) { 130 if (appcache_service_.get()) {
111 if (!backend_impl_.SelectCacheForWorker( 131 if (!backend_impl_.SelectCacheForWorker(host_id, parent_process_id,
112 host_id, parent_process_id, parent_host_id)) { 132 parent_host_id)) {
113 bad_message::ReceivedBadMessage( 133 bad_message::ReceivedBadMessage(
114 this, bad_message::ACDH_SELECT_CACHE_FOR_WORKER); 134 this, bad_message::ACDH_SELECT_CACHE_FOR_WORKER);
115 } 135 }
116 } else { 136 } else {
117 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); 137 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo());
118 } 138 }
119 } 139 }
120 140
121 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker(int host_id, 141 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker(int host_id,
122 int64_t appcache_id) { 142 int64_t appcache_id) {
123 if (appcache_service_.get()) { 143 if (appcache_service_.get()) {
124 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id)) 144 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id))
125 bad_message::ReceivedBadMessage( 145 bad_message::ReceivedBadMessage(
126 this, bad_message::ACDH_SELECT_CACHE_FOR_SHARED_WORKER); 146 this, bad_message::ACDH_SELECT_CACHE_FOR_SHARED_WORKER);
127 } else { 147 } else {
128 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); 148 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo());
129 } 149 }
130 } 150 }
131 151
132 void AppCacheDispatcherHost::OnMarkAsForeignEntry( 152 void AppCacheDispatcherHost::OnMarkAsForeignEntry(
133 int host_id, 153 int host_id,
134 const GURL& document_url, 154 const GURL& document_url,
135 int64_t cache_document_was_loaded_from) { 155 int64_t cache_document_was_loaded_from) {
136 if (appcache_service_.get()) { 156 if (appcache_service_.get()) {
137 if (!backend_impl_.MarkAsForeignEntry( 157 if (!backend_impl_.MarkAsForeignEntry(host_id, document_url,
138 host_id, document_url, cache_document_was_loaded_from)) { 158 cache_document_was_loaded_from)) {
139 bad_message::ReceivedBadMessage(this, 159 bad_message::ReceivedBadMessage(this,
140 bad_message::ACDH_MARK_AS_FOREIGN_ENTRY); 160 bad_message::ACDH_MARK_AS_FOREIGN_ENTRY);
141 } 161 }
142 } 162 }
143 } 163 }
144 164
145 void AppCacheDispatcherHost::OnGetResourceList( 165 void AppCacheDispatcherHost::OnGetResourceList(
146 int host_id, std::vector<AppCacheResourceInfo>* params) { 166 int host_id, std::vector<AppCacheResourceInfo>* params) {
147 if (appcache_service_.get()) 167 if (appcache_service_.get())
148 backend_impl_.GetResourceList(host_id, params); 168 backend_impl_.GetResourceList(host_id, params);
149 } 169 }
150 170
151 void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) { 171 void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) {
152 if (pending_reply_msg_) { 172 if (pending_reply_msg_) {
153 bad_message::ReceivedBadMessage( 173 bad_message::ReceivedBadMessage(
154 this, bad_message::ACDH_PENDING_REPLY_IN_GET_STATUS); 174 this, bad_message::ACDH_PENDING_REPLY_IN_GET_STATUS);
155 delete reply_msg; 175 delete reply_msg;
156 return; 176 return;
157 } 177 }
158 178
159 pending_reply_msg_.reset(reply_msg); 179 pending_reply_msg_.reset(reply_msg);
160 if (appcache_service_.get()) { 180 if (appcache_service_.get()) {
161 if (!backend_impl_.GetStatusWithCallback( 181 if (!backend_impl_.GetStatusWithCallback(host_id, get_status_callback_,
162 host_id, get_status_callback_, reply_msg)) { 182 reply_msg)) {
163 bad_message::ReceivedBadMessage(this, bad_message::ACDH_GET_STATUS); 183 bad_message::ReceivedBadMessage(this, bad_message::ACDH_GET_STATUS);
164 } 184 }
165 return; 185 return;
166 } 186 }
167 187
168 GetStatusCallback(APPCACHE_STATUS_UNCACHED, reply_msg); 188 GetStatusCallback(APPCACHE_STATUS_UNCACHED, reply_msg);
169 } 189 }
170 190
171 void AppCacheDispatcherHost::OnStartUpdate(int host_id, 191 void AppCacheDispatcherHost::OnStartUpdate(int host_id,
172 IPC::Message* reply_msg) { 192 IPC::Message* reply_msg) {
173 if (pending_reply_msg_) { 193 if (pending_reply_msg_) {
174 bad_message::ReceivedBadMessage( 194 bad_message::ReceivedBadMessage(
175 this, bad_message::ACDH_PENDING_REPLY_IN_START_UPDATE); 195 this, bad_message::ACDH_PENDING_REPLY_IN_START_UPDATE);
176 delete reply_msg; 196 delete reply_msg;
177 return; 197 return;
178 } 198 }
179 199
180 pending_reply_msg_.reset(reply_msg); 200 pending_reply_msg_.reset(reply_msg);
181 if (appcache_service_.get()) { 201 if (appcache_service_.get()) {
182 if (!backend_impl_.StartUpdateWithCallback( 202 if (!backend_impl_.StartUpdateWithCallback(host_id, start_update_callback_,
183 host_id, start_update_callback_, reply_msg)) { 203 reply_msg)) {
184 bad_message::ReceivedBadMessage(this, bad_message::ACDH_START_UPDATE); 204 bad_message::ReceivedBadMessage(this, bad_message::ACDH_START_UPDATE);
185 } 205 }
186 return; 206 return;
187 } 207 }
188 208
189 StartUpdateCallback(false, reply_msg); 209 StartUpdateCallback(false, reply_msg);
190 } 210 }
191 211
192 void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) { 212 void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) {
193 if (pending_reply_msg_) { 213 if (pending_reply_msg_) {
194 bad_message::ReceivedBadMessage( 214 bad_message::ReceivedBadMessage(
195 this, bad_message::ACDH_PENDING_REPLY_IN_SWAP_CACHE); 215 this, bad_message::ACDH_PENDING_REPLY_IN_SWAP_CACHE);
196 delete reply_msg; 216 delete reply_msg;
197 return; 217 return;
198 } 218 }
199 219
200 pending_reply_msg_.reset(reply_msg); 220 pending_reply_msg_.reset(reply_msg);
201 if (appcache_service_.get()) { 221 if (appcache_service_.get()) {
202 if (!backend_impl_.SwapCacheWithCallback( 222 if (!backend_impl_.SwapCacheWithCallback(host_id, swap_cache_callback_,
203 host_id, swap_cache_callback_, reply_msg)) { 223 reply_msg)) {
204 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SWAP_CACHE); 224 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SWAP_CACHE);
205 } 225 }
206 return; 226 return;
207 } 227 }
208 228
209 SwapCacheCallback(false, reply_msg); 229 SwapCacheCallback(false, reply_msg);
210 } 230 }
211 231
212 void AppCacheDispatcherHost::GetStatusCallback( 232 void AppCacheDispatcherHost::GetStatusCallback(
213 AppCacheStatus status, void* param) { 233 AppCacheStatus status, void* param) {
(...skipping 10 matching lines...) Expand all
224 Send(pending_reply_msg_.release()); 244 Send(pending_reply_msg_.release());
225 } 245 }
226 246
227 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { 247 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) {
228 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); 248 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param);
229 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); 249 DCHECK_EQ(pending_reply_msg_.get(), reply_msg);
230 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result); 250 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result);
231 Send(pending_reply_msg_.release()); 251 Send(pending_reply_msg_.release());
232 } 252 }
233 253
254 // static
255 scoped_refptr<AppCacheDispatcherHost> AppCacheDispatcherHost::GetHostForProcess(
256 int process_id) {
257 ProcessIdToHostMap::iterator index =
258 g_process_id_host_map.Get().find(process_id);
259 if (index == g_process_id_host_map.Get().end())
260 return scoped_refptr<AppCacheDispatcherHost>();
261 return index->second;
262 }
263
234 } // namespace content 264 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698