Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 10 #include "content/browser/appcache/appcache_navigation_handle_core.h" | |
| 9 #include "content/browser/appcache/chrome_appcache_service.h" | 11 #include "content/browser/appcache/chrome_appcache_service.h" |
| 10 #include "content/browser/bad_message.h" | 12 #include "content/browser/bad_message.h" |
| 11 #include "content/common/appcache_messages.h" | 13 #include "content/common/appcache_messages.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" | |
| 13 | 16 |
| 14 namespace content { | 17 namespace content { |
| 15 | 18 |
| 16 AppCacheDispatcherHost::AppCacheDispatcherHost( | 19 AppCacheDispatcherHost::AppCacheDispatcherHost( |
| 17 ChromeAppCacheService* appcache_service, | 20 ChromeAppCacheService* appcache_service, |
| 18 int process_id) | 21 int process_id) |
| 19 : BrowserMessageFilter(AppCacheMsgStart), | 22 : BrowserMessageFilter(AppCacheMsgStart), |
| 20 appcache_service_(appcache_service), | 23 appcache_service_(appcache_service), |
| 21 frontend_proxy_(this), | 24 frontend_proxy_(this), |
| 22 process_id_(process_id), | 25 process_id_(process_id), |
| 23 weak_factory_(this) { | 26 weak_factory_(this) { |
| 24 } | 27 } |
| 25 | 28 |
| 26 void AppCacheDispatcherHost::OnChannelConnected(int32_t peer_pid) { | 29 void AppCacheDispatcherHost::OnChannelConnected(int32_t peer_pid) { |
| 27 if (appcache_service_.get()) { | 30 if (!appcache_service_.get()) |
| 28 backend_impl_.Initialize( | 31 return; |
| 29 appcache_service_.get(), &frontend_proxy_, process_id_); | 32 |
| 30 get_status_callback_ = | 33 backend_impl_.Initialize(appcache_service_.get(), &frontend_proxy_, |
| 31 base::Bind(&AppCacheDispatcherHost::GetStatusCallback, | 34 process_id_); |
| 32 weak_factory_.GetWeakPtr()); | 35 get_status_callback_ = base::Bind(&AppCacheDispatcherHost::GetStatusCallback, |
| 33 start_update_callback_ = | 36 weak_factory_.GetWeakPtr()); |
| 34 base::Bind(&AppCacheDispatcherHost::StartUpdateCallback, | 37 start_update_callback_ = base::Bind( |
| 35 weak_factory_.GetWeakPtr()); | 38 &AppCacheDispatcherHost::StartUpdateCallback, weak_factory_.GetWeakPtr()); |
| 36 swap_cache_callback_ = | 39 swap_cache_callback_ = base::Bind(&AppCacheDispatcherHost::SwapCacheCallback, |
| 37 base::Bind(&AppCacheDispatcherHost::SwapCacheCallback, | 40 weak_factory_.GetWeakPtr()); |
| 38 weak_factory_.GetWeakPtr()); | |
| 39 } | |
| 40 } | 41 } |
| 41 | 42 |
| 42 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) { | 43 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| 43 bool handled = true; | 44 bool handled = true; |
| 44 IPC_BEGIN_MESSAGE_MAP(AppCacheDispatcherHost, message) | 45 IPC_BEGIN_MESSAGE_MAP(AppCacheDispatcherHost, message) |
| 45 IPC_MESSAGE_HANDLER(AppCacheHostMsg_RegisterHost, OnRegisterHost) | 46 IPC_MESSAGE_HANDLER(AppCacheHostMsg_RegisterHost, OnRegisterHost) |
| 46 IPC_MESSAGE_HANDLER(AppCacheHostMsg_UnregisterHost, OnUnregisterHost) | 47 IPC_MESSAGE_HANDLER(AppCacheHostMsg_UnregisterHost, OnUnregisterHost) |
| 47 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SetSpawningHostId, OnSetSpawningHostId) | 48 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SetSpawningHostId, OnSetSpawningHostId) |
| 48 IPC_MESSAGE_HANDLER(AppCacheHostMsg_GetResourceList, OnGetResourceList) | 49 IPC_MESSAGE_HANDLER(AppCacheHostMsg_GetResourceList, OnGetResourceList) |
| 49 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCache, OnSelectCache) | 50 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCache, OnSelectCache) |
| 50 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForWorker, | 51 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForWorker, |
| 51 OnSelectCacheForWorker) | 52 OnSelectCacheForWorker) |
| 52 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForSharedWorker, | 53 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForSharedWorker, |
| 53 OnSelectCacheForSharedWorker) | 54 OnSelectCacheForSharedWorker) |
| 54 IPC_MESSAGE_HANDLER(AppCacheHostMsg_MarkAsForeignEntry, | 55 IPC_MESSAGE_HANDLER(AppCacheHostMsg_MarkAsForeignEntry, |
| 55 OnMarkAsForeignEntry) | 56 OnMarkAsForeignEntry) |
| 56 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_GetStatus, OnGetStatus) | 57 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_GetStatus, OnGetStatus) |
| 57 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_StartUpdate, OnStartUpdate) | 58 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_StartUpdate, OnStartUpdate) |
| 58 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_SwapCache, OnSwapCache) | 59 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_SwapCache, OnSwapCache) |
| 59 IPC_MESSAGE_UNHANDLED(handled = false) | 60 IPC_MESSAGE_UNHANDLED(handled = false) |
| 60 IPC_END_MESSAGE_MAP() | 61 IPC_END_MESSAGE_MAP() |
| 61 | 62 |
| 62 return handled; | 63 return handled; |
| 63 } | 64 } |
| 64 | 65 |
| 65 AppCacheDispatcherHost::~AppCacheDispatcherHost() {} | 66 AppCacheDispatcherHost::~AppCacheDispatcherHost() { |
| 67 } | |
| 68 | |
| 69 void AppCacheDispatcherHost::RegisterPrecreatedHost( | |
|
michaeln
2016/12/06 21:10:46
is this method needed given the code in OnRegister
ananta
2016/12/06 21:38:05
Done.
| |
| 70 std::unique_ptr<AppCacheHost> host) { | |
| 71 DCHECK(host.get()); | |
| 72 DCHECK(IsBrowserSideNavigationEnabled()); | |
| 73 backend_impl_.RegisterPrecreatedHost(std::move(host)); | |
| 74 } | |
| 66 | 75 |
| 67 void AppCacheDispatcherHost::OnRegisterHost(int host_id) { | 76 void AppCacheDispatcherHost::OnRegisterHost(int host_id) { |
| 68 if (appcache_service_.get()) { | 77 if (appcache_service_.get()) { |
| 78 // PlzNavigate | |
| 79 // The AppCacheHost could have been precreated in which case we want to | |
| 80 // register it with the backend here. | |
| 81 if (IsBrowserSideNavigationEnabled()) { | |
| 82 std::unique_ptr<AppCacheHost> host = | |
| 83 AppCacheNavigationHandleCore::GetPrecreatedHost(host_id); | |
| 84 if (host.get()) { | |
| 85 backend_impl_.RegisterPrecreatedHost(std::move(host)); | |
| 86 return; | |
| 87 } | |
|
michaeln
2016/12/06 21:10:46
i spent some time looking into this error conditio
ananta
2016/12/06 21:38:05
Acknowledged
| |
| 88 } | |
| 69 if (!backend_impl_.RegisterHost(host_id)) { | 89 if (!backend_impl_.RegisterHost(host_id)) { |
| 70 bad_message::ReceivedBadMessage(this, bad_message::ACDH_REGISTER); | 90 bad_message::ReceivedBadMessage(this, bad_message::ACDH_REGISTER); |
| 71 } | 91 } |
| 72 } | 92 } |
| 73 } | 93 } |
| 74 | 94 |
| 75 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { | 95 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { |
| 76 if (appcache_service_.get()) { | 96 if (appcache_service_.get()) { |
| 77 if (!backend_impl_.UnregisterHost(host_id)) { | 97 if (!backend_impl_.UnregisterHost(host_id)) { |
| 78 bad_message::ReceivedBadMessage(this, bad_message::ACDH_UNREGISTER); | 98 bad_message::ReceivedBadMessage(this, bad_message::ACDH_UNREGISTER); |
| 79 } | 99 } |
| 80 } | 100 } |
| 81 } | 101 } |
| 82 | 102 |
| 83 void AppCacheDispatcherHost::OnSetSpawningHostId( | 103 void AppCacheDispatcherHost::OnSetSpawningHostId( |
| 84 int host_id, int spawning_host_id) { | 104 int host_id, int spawning_host_id) { |
| 85 if (appcache_service_.get()) { | 105 if (appcache_service_.get()) { |
| 86 if (!backend_impl_.SetSpawningHostId(host_id, spawning_host_id)) | 106 if (!backend_impl_.SetSpawningHostId(host_id, spawning_host_id)) |
| 87 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SET_SPAWNING); | 107 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SET_SPAWNING); |
| 88 } | 108 } |
| 89 } | 109 } |
| 90 | 110 |
| 91 void AppCacheDispatcherHost::OnSelectCache( | 111 void AppCacheDispatcherHost::OnSelectCache( |
| 92 int host_id, | 112 int host_id, |
| 93 const GURL& document_url, | 113 const GURL& document_url, |
| 94 int64_t cache_document_was_loaded_from, | 114 int64_t cache_document_was_loaded_from, |
| 95 const GURL& opt_manifest_url) { | 115 const GURL& opt_manifest_url) { |
| 96 if (appcache_service_.get()) { | 116 if (appcache_service_.get()) { |
| 97 if (!backend_impl_.SelectCache(host_id, | 117 if (!backend_impl_.SelectCache(host_id, document_url, |
| 98 document_url, | |
| 99 cache_document_was_loaded_from, | 118 cache_document_was_loaded_from, |
| 100 opt_manifest_url)) { | 119 opt_manifest_url)) { |
| 101 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SELECT_CACHE); | 120 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SELECT_CACHE); |
| 102 } | 121 } |
| 103 } else { | 122 } else { |
| 104 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); | 123 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); |
| 105 } | 124 } |
| 106 } | 125 } |
| 107 | 126 |
| 108 void AppCacheDispatcherHost::OnSelectCacheForWorker( | 127 void AppCacheDispatcherHost::OnSelectCacheForWorker( |
| 109 int host_id, int parent_process_id, int parent_host_id) { | 128 int host_id, int parent_process_id, int parent_host_id) { |
| 110 if (appcache_service_.get()) { | 129 if (appcache_service_.get()) { |
| 111 if (!backend_impl_.SelectCacheForWorker( | 130 if (!backend_impl_.SelectCacheForWorker(host_id, parent_process_id, |
| 112 host_id, parent_process_id, parent_host_id)) { | 131 parent_host_id)) { |
| 113 bad_message::ReceivedBadMessage( | 132 bad_message::ReceivedBadMessage( |
| 114 this, bad_message::ACDH_SELECT_CACHE_FOR_WORKER); | 133 this, bad_message::ACDH_SELECT_CACHE_FOR_WORKER); |
| 115 } | 134 } |
| 116 } else { | 135 } else { |
| 117 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); | 136 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); |
| 118 } | 137 } |
| 119 } | 138 } |
| 120 | 139 |
| 121 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker(int host_id, | 140 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker(int host_id, |
| 122 int64_t appcache_id) { | 141 int64_t appcache_id) { |
| 123 if (appcache_service_.get()) { | 142 if (appcache_service_.get()) { |
| 124 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id)) | 143 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id)) |
| 125 bad_message::ReceivedBadMessage( | 144 bad_message::ReceivedBadMessage( |
| 126 this, bad_message::ACDH_SELECT_CACHE_FOR_SHARED_WORKER); | 145 this, bad_message::ACDH_SELECT_CACHE_FOR_SHARED_WORKER); |
| 127 } else { | 146 } else { |
| 128 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); | 147 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); |
| 129 } | 148 } |
| 130 } | 149 } |
| 131 | 150 |
| 132 void AppCacheDispatcherHost::OnMarkAsForeignEntry( | 151 void AppCacheDispatcherHost::OnMarkAsForeignEntry( |
| 133 int host_id, | 152 int host_id, |
| 134 const GURL& document_url, | 153 const GURL& document_url, |
| 135 int64_t cache_document_was_loaded_from) { | 154 int64_t cache_document_was_loaded_from) { |
| 136 if (appcache_service_.get()) { | 155 if (appcache_service_.get()) { |
| 137 if (!backend_impl_.MarkAsForeignEntry( | 156 if (!backend_impl_.MarkAsForeignEntry(host_id, document_url, |
| 138 host_id, document_url, cache_document_was_loaded_from)) { | 157 cache_document_was_loaded_from)) { |
| 139 bad_message::ReceivedBadMessage(this, | 158 bad_message::ReceivedBadMessage(this, |
| 140 bad_message::ACDH_MARK_AS_FOREIGN_ENTRY); | 159 bad_message::ACDH_MARK_AS_FOREIGN_ENTRY); |
| 141 } | 160 } |
| 142 } | 161 } |
| 143 } | 162 } |
| 144 | 163 |
| 145 void AppCacheDispatcherHost::OnGetResourceList( | 164 void AppCacheDispatcherHost::OnGetResourceList( |
| 146 int host_id, std::vector<AppCacheResourceInfo>* params) { | 165 int host_id, std::vector<AppCacheResourceInfo>* params) { |
| 147 if (appcache_service_.get()) | 166 if (appcache_service_.get()) |
| 148 backend_impl_.GetResourceList(host_id, params); | 167 backend_impl_.GetResourceList(host_id, params); |
| 149 } | 168 } |
| 150 | 169 |
| 151 void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) { | 170 void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) { |
| 152 if (pending_reply_msg_) { | 171 if (pending_reply_msg_) { |
| 153 bad_message::ReceivedBadMessage( | 172 bad_message::ReceivedBadMessage( |
| 154 this, bad_message::ACDH_PENDING_REPLY_IN_GET_STATUS); | 173 this, bad_message::ACDH_PENDING_REPLY_IN_GET_STATUS); |
| 155 delete reply_msg; | 174 delete reply_msg; |
| 156 return; | 175 return; |
| 157 } | 176 } |
| 158 | 177 |
| 159 pending_reply_msg_.reset(reply_msg); | 178 pending_reply_msg_.reset(reply_msg); |
| 160 if (appcache_service_.get()) { | 179 if (appcache_service_.get()) { |
| 161 if (!backend_impl_.GetStatusWithCallback( | 180 if (!backend_impl_.GetStatusWithCallback(host_id, get_status_callback_, |
| 162 host_id, get_status_callback_, reply_msg)) { | 181 reply_msg)) { |
| 163 bad_message::ReceivedBadMessage(this, bad_message::ACDH_GET_STATUS); | 182 bad_message::ReceivedBadMessage(this, bad_message::ACDH_GET_STATUS); |
| 164 } | 183 } |
| 165 return; | 184 return; |
| 166 } | 185 } |
| 167 | 186 |
| 168 GetStatusCallback(APPCACHE_STATUS_UNCACHED, reply_msg); | 187 GetStatusCallback(APPCACHE_STATUS_UNCACHED, reply_msg); |
| 169 } | 188 } |
| 170 | 189 |
| 171 void AppCacheDispatcherHost::OnStartUpdate(int host_id, | 190 void AppCacheDispatcherHost::OnStartUpdate(int host_id, |
| 172 IPC::Message* reply_msg) { | 191 IPC::Message* reply_msg) { |
| 173 if (pending_reply_msg_) { | 192 if (pending_reply_msg_) { |
| 174 bad_message::ReceivedBadMessage( | 193 bad_message::ReceivedBadMessage( |
| 175 this, bad_message::ACDH_PENDING_REPLY_IN_START_UPDATE); | 194 this, bad_message::ACDH_PENDING_REPLY_IN_START_UPDATE); |
| 176 delete reply_msg; | 195 delete reply_msg; |
| 177 return; | 196 return; |
| 178 } | 197 } |
| 179 | 198 |
| 180 pending_reply_msg_.reset(reply_msg); | 199 pending_reply_msg_.reset(reply_msg); |
| 181 if (appcache_service_.get()) { | 200 if (appcache_service_.get()) { |
| 182 if (!backend_impl_.StartUpdateWithCallback( | 201 if (!backend_impl_.StartUpdateWithCallback(host_id, start_update_callback_, |
| 183 host_id, start_update_callback_, reply_msg)) { | 202 reply_msg)) { |
| 184 bad_message::ReceivedBadMessage(this, bad_message::ACDH_START_UPDATE); | 203 bad_message::ReceivedBadMessage(this, bad_message::ACDH_START_UPDATE); |
| 185 } | 204 } |
| 186 return; | 205 return; |
| 187 } | 206 } |
| 188 | 207 |
| 189 StartUpdateCallback(false, reply_msg); | 208 StartUpdateCallback(false, reply_msg); |
| 190 } | 209 } |
| 191 | 210 |
| 192 void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) { | 211 void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) { |
| 193 if (pending_reply_msg_) { | 212 if (pending_reply_msg_) { |
| 194 bad_message::ReceivedBadMessage( | 213 bad_message::ReceivedBadMessage( |
| 195 this, bad_message::ACDH_PENDING_REPLY_IN_SWAP_CACHE); | 214 this, bad_message::ACDH_PENDING_REPLY_IN_SWAP_CACHE); |
| 196 delete reply_msg; | 215 delete reply_msg; |
| 197 return; | 216 return; |
| 198 } | 217 } |
| 199 | 218 |
| 200 pending_reply_msg_.reset(reply_msg); | 219 pending_reply_msg_.reset(reply_msg); |
| 201 if (appcache_service_.get()) { | 220 if (appcache_service_.get()) { |
| 202 if (!backend_impl_.SwapCacheWithCallback( | 221 if (!backend_impl_.SwapCacheWithCallback(host_id, swap_cache_callback_, |
| 203 host_id, swap_cache_callback_, reply_msg)) { | 222 reply_msg)) { |
| 204 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SWAP_CACHE); | 223 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SWAP_CACHE); |
| 205 } | 224 } |
| 206 return; | 225 return; |
| 207 } | 226 } |
| 208 | 227 |
| 209 SwapCacheCallback(false, reply_msg); | 228 SwapCacheCallback(false, reply_msg); |
| 210 } | 229 } |
| 211 | 230 |
| 212 void AppCacheDispatcherHost::GetStatusCallback( | 231 void AppCacheDispatcherHost::GetStatusCallback( |
| 213 AppCacheStatus status, void* param) { | 232 AppCacheStatus status, void* param) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 225 } | 244 } |
| 226 | 245 |
| 227 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { | 246 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { |
| 228 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); | 247 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); |
| 229 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); | 248 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); |
| 230 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result); | 249 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result); |
| 231 Send(pending_reply_msg_.release()); | 250 Send(pending_reply_msg_.release()); |
| 232 } | 251 } |
| 233 | 252 |
| 234 } // namespace content | 253 } // namespace content |
| OLD | NEW |