| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "content/browser/appcache/chrome_appcache_service.h" | 9 #include "content/browser/appcache/chrome_appcache_service.h" |
| 10 #include "content/browser/bad_message.h" |
| 10 #include "content/common/appcache_messages.h" | 11 #include "content/common/appcache_messages.h" |
| 11 #include "content/public/browser/user_metrics.h" | 12 #include "content/public/browser/user_metrics.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 15 AppCacheDispatcherHost::AppCacheDispatcherHost( | 16 AppCacheDispatcherHost::AppCacheDispatcherHost( |
| 16 ChromeAppCacheService* appcache_service, | 17 ChromeAppCacheService* appcache_service, |
| 17 int process_id) | 18 int process_id) |
| 18 : BrowserMessageFilter(AppCacheMsgStart), | 19 : BrowserMessageFilter(AppCacheMsgStart), |
| 19 appcache_service_(appcache_service), | 20 appcache_service_(appcache_service), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_StartUpdate, OnStartUpdate) | 56 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_StartUpdate, OnStartUpdate) |
| 56 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_SwapCache, OnSwapCache) | 57 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_SwapCache, OnSwapCache) |
| 57 IPC_MESSAGE_UNHANDLED(handled = false) | 58 IPC_MESSAGE_UNHANDLED(handled = false) |
| 58 IPC_END_MESSAGE_MAP() | 59 IPC_END_MESSAGE_MAP() |
| 59 | 60 |
| 60 return handled; | 61 return handled; |
| 61 } | 62 } |
| 62 | 63 |
| 63 AppCacheDispatcherHost::~AppCacheDispatcherHost() {} | 64 AppCacheDispatcherHost::~AppCacheDispatcherHost() {} |
| 64 | 65 |
| 65 void AppCacheDispatcherHost::BadMessageReceived() { | |
| 66 RecordAction(base::UserMetricsAction("BadMessageTerminate_ACDH")); | |
| 67 BrowserMessageFilter::BadMessageReceived(); | |
| 68 } | |
| 69 | |
| 70 void AppCacheDispatcherHost::OnRegisterHost(int host_id) { | 66 void AppCacheDispatcherHost::OnRegisterHost(int host_id) { |
| 71 if (appcache_service_.get()) { | 67 if (appcache_service_.get()) { |
| 72 if (!backend_impl_.RegisterHost(host_id)) { | 68 if (!backend_impl_.RegisterHost(host_id)) { |
| 73 BadMessageReceived(); | 69 bad_message::ReceivedBadMessage(this, bad_message::ACDH_REGISTER); |
| 74 } | 70 } |
| 75 } | 71 } |
| 76 } | 72 } |
| 77 | 73 |
| 78 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { | 74 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { |
| 79 if (appcache_service_.get()) { | 75 if (appcache_service_.get()) { |
| 80 if (!backend_impl_.UnregisterHost(host_id)) { | 76 if (!backend_impl_.UnregisterHost(host_id)) { |
| 81 BadMessageReceived(); | 77 bad_message::ReceivedBadMessage(this, bad_message::ACDH_UNREGISTER); |
| 82 } | 78 } |
| 83 } | 79 } |
| 84 } | 80 } |
| 85 | 81 |
| 86 void AppCacheDispatcherHost::OnSetSpawningHostId( | 82 void AppCacheDispatcherHost::OnSetSpawningHostId( |
| 87 int host_id, int spawning_host_id) { | 83 int host_id, int spawning_host_id) { |
| 88 if (appcache_service_.get()) { | 84 if (appcache_service_.get()) { |
| 89 if (!backend_impl_.SetSpawningHostId(host_id, spawning_host_id)) | 85 if (!backend_impl_.SetSpawningHostId(host_id, spawning_host_id)) |
| 90 BadMessageReceived(); | 86 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SET_SPAWNING); |
| 91 } | 87 } |
| 92 } | 88 } |
| 93 | 89 |
| 94 void AppCacheDispatcherHost::OnSelectCache( | 90 void AppCacheDispatcherHost::OnSelectCache( |
| 95 int host_id, const GURL& document_url, | 91 int host_id, const GURL& document_url, |
| 96 int64 cache_document_was_loaded_from, | 92 int64 cache_document_was_loaded_from, |
| 97 const GURL& opt_manifest_url) { | 93 const GURL& opt_manifest_url) { |
| 98 if (appcache_service_.get()) { | 94 if (appcache_service_.get()) { |
| 99 if (!backend_impl_.SelectCache(host_id, | 95 if (!backend_impl_.SelectCache(host_id, |
| 100 document_url, | 96 document_url, |
| 101 cache_document_was_loaded_from, | 97 cache_document_was_loaded_from, |
| 102 opt_manifest_url)) { | 98 opt_manifest_url)) { |
| 103 BadMessageReceived(); | 99 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SELECT_CACHE); |
| 104 } | 100 } |
| 105 } else { | 101 } else { |
| 106 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); | 102 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); |
| 107 } | 103 } |
| 108 } | 104 } |
| 109 | 105 |
| 110 void AppCacheDispatcherHost::OnSelectCacheForWorker( | 106 void AppCacheDispatcherHost::OnSelectCacheForWorker( |
| 111 int host_id, int parent_process_id, int parent_host_id) { | 107 int host_id, int parent_process_id, int parent_host_id) { |
| 112 if (appcache_service_.get()) { | 108 if (appcache_service_.get()) { |
| 113 if (!backend_impl_.SelectCacheForWorker( | 109 if (!backend_impl_.SelectCacheForWorker( |
| 114 host_id, parent_process_id, parent_host_id)) { | 110 host_id, parent_process_id, parent_host_id)) { |
| 115 BadMessageReceived(); | 111 bad_message::ReceivedBadMessage( |
| 112 this, bad_message::ACDH_SELECT_CACHE_FOR_WORKER); |
| 116 } | 113 } |
| 117 } else { | 114 } else { |
| 118 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); | 115 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); |
| 119 } | 116 } |
| 120 } | 117 } |
| 121 | 118 |
| 122 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker( | 119 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker( |
| 123 int host_id, int64 appcache_id) { | 120 int host_id, int64 appcache_id) { |
| 124 if (appcache_service_.get()) { | 121 if (appcache_service_.get()) { |
| 125 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id)) | 122 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id)) |
| 126 BadMessageReceived(); | 123 bad_message::ReceivedBadMessage( |
| 124 this, bad_message::ACDH_SELECT_CACHE_FOR_SHARED_WORKER); |
| 127 } else { | 125 } else { |
| 128 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); | 126 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); |
| 129 } | 127 } |
| 130 } | 128 } |
| 131 | 129 |
| 132 void AppCacheDispatcherHost::OnMarkAsForeignEntry( | 130 void AppCacheDispatcherHost::OnMarkAsForeignEntry( |
| 133 int host_id, const GURL& document_url, | 131 int host_id, const GURL& document_url, |
| 134 int64 cache_document_was_loaded_from) { | 132 int64 cache_document_was_loaded_from) { |
| 135 if (appcache_service_.get()) { | 133 if (appcache_service_.get()) { |
| 136 if (!backend_impl_.MarkAsForeignEntry( | 134 if (!backend_impl_.MarkAsForeignEntry( |
| 137 host_id, document_url, cache_document_was_loaded_from)) { | 135 host_id, document_url, cache_document_was_loaded_from)) { |
| 138 BadMessageReceived(); | 136 bad_message::ReceivedBadMessage(this, |
| 137 bad_message::ACDH_MARK_AS_FOREIGN_ENTRY); |
| 139 } | 138 } |
| 140 } | 139 } |
| 141 } | 140 } |
| 142 | 141 |
| 143 void AppCacheDispatcherHost::OnGetResourceList( | 142 void AppCacheDispatcherHost::OnGetResourceList( |
| 144 int host_id, std::vector<AppCacheResourceInfo>* params) { | 143 int host_id, std::vector<AppCacheResourceInfo>* params) { |
| 145 if (appcache_service_.get()) | 144 if (appcache_service_.get()) |
| 146 backend_impl_.GetResourceList(host_id, params); | 145 backend_impl_.GetResourceList(host_id, params); |
| 147 } | 146 } |
| 148 | 147 |
| 149 void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) { | 148 void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) { |
| 150 if (pending_reply_msg_) { | 149 if (pending_reply_msg_) { |
| 151 BadMessageReceived(); | 150 bad_message::ReceivedBadMessage( |
| 151 this, bad_message::ACDH_PENDING_REPLY_IN_GET_STATUS); |
| 152 delete reply_msg; | 152 delete reply_msg; |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 | 155 |
| 156 pending_reply_msg_.reset(reply_msg); | 156 pending_reply_msg_.reset(reply_msg); |
| 157 if (appcache_service_.get()) { | 157 if (appcache_service_.get()) { |
| 158 if (!backend_impl_.GetStatusWithCallback( | 158 if (!backend_impl_.GetStatusWithCallback( |
| 159 host_id, get_status_callback_, reply_msg)) { | 159 host_id, get_status_callback_, reply_msg)) { |
| 160 BadMessageReceived(); | 160 bad_message::ReceivedBadMessage(this, bad_message::ACDH_GET_STATUS); |
| 161 } | 161 } |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 | 164 |
| 165 GetStatusCallback(APPCACHE_STATUS_UNCACHED, reply_msg); | 165 GetStatusCallback(APPCACHE_STATUS_UNCACHED, reply_msg); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void AppCacheDispatcherHost::OnStartUpdate(int host_id, | 168 void AppCacheDispatcherHost::OnStartUpdate(int host_id, |
| 169 IPC::Message* reply_msg) { | 169 IPC::Message* reply_msg) { |
| 170 if (pending_reply_msg_) { | 170 if (pending_reply_msg_) { |
| 171 BadMessageReceived(); | 171 bad_message::ReceivedBadMessage( |
| 172 this, bad_message::ACDH_PENDING_REPLY_IN_START_UPDATE); |
| 172 delete reply_msg; | 173 delete reply_msg; |
| 173 return; | 174 return; |
| 174 } | 175 } |
| 175 | 176 |
| 176 pending_reply_msg_.reset(reply_msg); | 177 pending_reply_msg_.reset(reply_msg); |
| 177 if (appcache_service_.get()) { | 178 if (appcache_service_.get()) { |
| 178 if (!backend_impl_.StartUpdateWithCallback( | 179 if (!backend_impl_.StartUpdateWithCallback( |
| 179 host_id, start_update_callback_, reply_msg)) { | 180 host_id, start_update_callback_, reply_msg)) { |
| 180 BadMessageReceived(); | 181 bad_message::ReceivedBadMessage(this, bad_message::ACDH_START_UPDATE); |
| 181 } | 182 } |
| 182 return; | 183 return; |
| 183 } | 184 } |
| 184 | 185 |
| 185 StartUpdateCallback(false, reply_msg); | 186 StartUpdateCallback(false, reply_msg); |
| 186 } | 187 } |
| 187 | 188 |
| 188 void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) { | 189 void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) { |
| 189 if (pending_reply_msg_) { | 190 if (pending_reply_msg_) { |
| 190 BadMessageReceived(); | 191 bad_message::ReceivedBadMessage( |
| 192 this, bad_message::ACDH_PENDING_REPLY_IN_SWAP_CACHE); |
| 191 delete reply_msg; | 193 delete reply_msg; |
| 192 return; | 194 return; |
| 193 } | 195 } |
| 194 | 196 |
| 195 pending_reply_msg_.reset(reply_msg); | 197 pending_reply_msg_.reset(reply_msg); |
| 196 if (appcache_service_.get()) { | 198 if (appcache_service_.get()) { |
| 197 if (!backend_impl_.SwapCacheWithCallback( | 199 if (!backend_impl_.SwapCacheWithCallback( |
| 198 host_id, swap_cache_callback_, reply_msg)) { | 200 host_id, swap_cache_callback_, reply_msg)) { |
| 199 BadMessageReceived(); | 201 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SWAP_CACHE); |
| 200 } | 202 } |
| 201 return; | 203 return; |
| 202 } | 204 } |
| 203 | 205 |
| 204 SwapCacheCallback(false, reply_msg); | 206 SwapCacheCallback(false, reply_msg); |
| 205 } | 207 } |
| 206 | 208 |
| 207 void AppCacheDispatcherHost::GetStatusCallback( | 209 void AppCacheDispatcherHost::GetStatusCallback( |
| 208 AppCacheStatus status, void* param) { | 210 AppCacheStatus status, void* param) { |
| 209 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); | 211 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 220 } | 222 } |
| 221 | 223 |
| 222 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { | 224 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { |
| 223 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); | 225 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); |
| 224 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); | 226 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); |
| 225 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result); | 227 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result); |
| 226 Send(pending_reply_msg_.release()); | 228 Send(pending_reply_msg_.release()); |
| 227 } | 229 } |
| 228 | 230 |
| 229 } // namespace content | 231 } // namespace content |
| OLD | NEW |