| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 8 #include "content/browser/appcache/chrome_appcache_service.h" | 9 #include "content/browser/appcache/chrome_appcache_service.h" |
| 9 #include "content/browser/user_metrics.h" | 10 #include "content/browser/user_metrics.h" |
| 10 #include "content/common/appcache_messages.h" | 11 #include "content/common/appcache_messages.h" |
| 11 | 12 |
| 12 AppCacheDispatcherHost::AppCacheDispatcherHost( | 13 AppCacheDispatcherHost::AppCacheDispatcherHost( |
| 13 ChromeAppCacheService* appcache_service, | 14 ChromeAppCacheService* appcache_service, |
| 14 int process_id) | 15 int process_id) |
| 15 : appcache_service_(appcache_service), | 16 : appcache_service_(appcache_service), |
| 16 ALLOW_THIS_IN_INITIALIZER_LIST(frontend_proxy_(this)), | 17 ALLOW_THIS_IN_INITIALIZER_LIST(frontend_proxy_(this)), |
| 17 process_id_(process_id) { | 18 process_id_(process_id) { |
| 18 } | 19 } |
| 19 | 20 |
| 20 AppCacheDispatcherHost::~AppCacheDispatcherHost() {} | 21 AppCacheDispatcherHost::~AppCacheDispatcherHost() {} |
| 21 | 22 |
| 22 void AppCacheDispatcherHost::OnChannelConnected(int32 peer_pid) { | 23 void AppCacheDispatcherHost::OnChannelConnected(int32 peer_pid) { |
| 23 BrowserMessageFilter::OnChannelConnected(peer_pid); | 24 BrowserMessageFilter::OnChannelConnected(peer_pid); |
| 24 if (appcache_service_.get()) { | 25 if (appcache_service_.get()) { |
| 25 backend_impl_.Initialize( | 26 backend_impl_.Initialize( |
| 26 appcache_service_.get(), &frontend_proxy_, process_id_); | 27 appcache_service_.get(), &frontend_proxy_, process_id_); |
| 27 get_status_callback_.reset( | 28 get_status_callback_ = |
| 28 NewCallback(this, &AppCacheDispatcherHost::GetStatusCallback)); | 29 base::Bind(&AppCacheDispatcherHost::GetStatusCallback, |
| 29 start_update_callback_.reset( | 30 base::Unretained(this)); |
| 30 NewCallback(this, &AppCacheDispatcherHost::StartUpdateCallback)); | 31 start_update_callback_ = |
| 31 swap_cache_callback_.reset( | 32 base::Bind(&AppCacheDispatcherHost::StartUpdateCallback, |
| 32 NewCallback(this, &AppCacheDispatcherHost::SwapCacheCallback)); | 33 base::Unretained(this)); |
| 34 swap_cache_callback_ = |
| 35 base::Bind(&AppCacheDispatcherHost::SwapCacheCallback, |
| 36 base::Unretained(this)); |
| 33 } | 37 } |
| 34 } | 38 } |
| 35 | 39 |
| 36 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message, | 40 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message, |
| 37 bool* message_was_ok) { | 41 bool* message_was_ok) { |
| 38 bool handled = true; | 42 bool handled = true; |
| 39 IPC_BEGIN_MESSAGE_MAP_EX(AppCacheDispatcherHost, message, *message_was_ok) | 43 IPC_BEGIN_MESSAGE_MAP_EX(AppCacheDispatcherHost, message, *message_was_ok) |
| 40 IPC_MESSAGE_HANDLER(AppCacheHostMsg_RegisterHost, OnRegisterHost) | 44 IPC_MESSAGE_HANDLER(AppCacheHostMsg_RegisterHost, OnRegisterHost) |
| 41 IPC_MESSAGE_HANDLER(AppCacheHostMsg_UnregisterHost, OnUnregisterHost) | 45 IPC_MESSAGE_HANDLER(AppCacheHostMsg_UnregisterHost, OnUnregisterHost) |
| 42 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SetSpawningHostId, OnSetSpawningHostId) | 46 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SetSpawningHostId, OnSetSpawningHostId) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 137 } |
| 134 } | 138 } |
| 135 } | 139 } |
| 136 | 140 |
| 137 void AppCacheDispatcherHost::OnGetResourceList( | 141 void AppCacheDispatcherHost::OnGetResourceList( |
| 138 int host_id, std::vector<appcache::AppCacheResourceInfo>* params) { | 142 int host_id, std::vector<appcache::AppCacheResourceInfo>* params) { |
| 139 if (appcache_service_.get()) | 143 if (appcache_service_.get()) |
| 140 backend_impl_.GetResourceList(host_id, params); | 144 backend_impl_.GetResourceList(host_id, params); |
| 141 } | 145 } |
| 142 | 146 |
| 143 void AppCacheDispatcherHost::OnGetStatus(int host_id, | 147 void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) { |
| 144 IPC::Message* reply_msg) { | |
| 145 if (pending_reply_msg_.get()) { | 148 if (pending_reply_msg_.get()) { |
| 146 BadMessageReceived(); | 149 BadMessageReceived(); |
| 147 delete reply_msg; | 150 delete reply_msg; |
| 148 return; | 151 return; |
| 149 } | 152 } |
| 150 | 153 |
| 151 pending_reply_msg_.reset(reply_msg); | 154 pending_reply_msg_.reset(reply_msg); |
| 152 if (appcache_service_.get()) { | 155 if (appcache_service_.get()) { |
| 153 if (!backend_impl_.GetStatusWithCallback( | 156 if (!backend_impl_.GetStatusWithCallback(host_id, get_status_callback_, |
| 154 host_id, get_status_callback_.get(), reply_msg)) { | 157 reply_msg)) { |
| 155 BadMessageReceived(); | 158 BadMessageReceived(); |
| 156 } | 159 } |
| 157 return; | 160 return; |
| 158 } | 161 } |
| 159 | 162 |
| 160 GetStatusCallback(appcache::UNCACHED, reply_msg); | 163 GetStatusCallback(appcache::UNCACHED, reply_msg); |
| 161 } | 164 } |
| 162 | 165 |
| 163 void AppCacheDispatcherHost::OnStartUpdate(int host_id, | 166 void AppCacheDispatcherHost::OnStartUpdate(int host_id, |
| 164 IPC::Message* reply_msg) { | 167 IPC::Message* reply_msg) { |
| 165 if (pending_reply_msg_.get()) { | 168 if (pending_reply_msg_.get()) { |
| 166 BadMessageReceived(); | 169 BadMessageReceived(); |
| 167 delete reply_msg; | 170 delete reply_msg; |
| 168 return; | 171 return; |
| 169 } | 172 } |
| 170 | 173 |
| 171 pending_reply_msg_.reset(reply_msg); | 174 pending_reply_msg_.reset(reply_msg); |
| 172 if (appcache_service_.get()) { | 175 if (appcache_service_.get()) { |
| 173 if (!backend_impl_.StartUpdateWithCallback( | 176 if (!backend_impl_.StartUpdateWithCallback(host_id, start_update_callback_, |
| 174 host_id, start_update_callback_.get(), reply_msg)) { | 177 reply_msg)) { |
| 175 BadMessageReceived(); | 178 BadMessageReceived(); |
| 176 } | 179 } |
| 177 return; | 180 return; |
| 178 } | 181 } |
| 179 | 182 |
| 180 StartUpdateCallback(false, reply_msg); | 183 StartUpdateCallback(false, reply_msg); |
| 181 } | 184 } |
| 182 | 185 |
| 183 void AppCacheDispatcherHost::OnSwapCache(int host_id, | 186 void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) { |
| 184 IPC::Message* reply_msg) { | |
| 185 if (pending_reply_msg_.get()) { | 187 if (pending_reply_msg_.get()) { |
| 186 BadMessageReceived(); | 188 BadMessageReceived(); |
| 187 delete reply_msg; | 189 delete reply_msg; |
| 188 return; | 190 return; |
| 189 } | 191 } |
| 190 | 192 |
| 191 pending_reply_msg_.reset(reply_msg); | 193 pending_reply_msg_.reset(reply_msg); |
| 192 if (appcache_service_.get()) { | 194 if (appcache_service_.get()) { |
| 193 if (!backend_impl_.SwapCacheWithCallback( | 195 if (!backend_impl_.SwapCacheWithCallback(host_id, swap_cache_callback_, |
| 194 host_id, swap_cache_callback_.get(), reply_msg)) { | 196 reply_msg)) { |
| 195 BadMessageReceived(); | 197 BadMessageReceived(); |
| 196 } | 198 } |
| 197 return; | 199 return; |
| 198 } | 200 } |
| 199 | 201 |
| 200 SwapCacheCallback(false, reply_msg); | 202 SwapCacheCallback(false, reply_msg); |
| 201 } | 203 } |
| 202 | 204 |
| 203 void AppCacheDispatcherHost::GetStatusCallback( | 205 void AppCacheDispatcherHost::GetStatusCallback( |
| 204 appcache::Status status, void* param) { | 206 appcache::Status status, void* param) { |
| 205 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); | 207 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); |
| 206 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); | 208 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); |
| 207 AppCacheHostMsg_GetStatus::WriteReplyParams(reply_msg, status); | 209 AppCacheHostMsg_GetStatus::WriteReplyParams(reply_msg, status); |
| 208 Send(pending_reply_msg_.release()); | 210 Send(pending_reply_msg_.release()); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void AppCacheDispatcherHost::StartUpdateCallback(bool result, void* param) { | 213 void AppCacheDispatcherHost::StartUpdateCallback(bool result, void* param) { |
| 212 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); | 214 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); |
| 213 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); | 215 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); |
| 214 AppCacheHostMsg_StartUpdate::WriteReplyParams(reply_msg, result); | 216 AppCacheHostMsg_StartUpdate::WriteReplyParams(reply_msg, result); |
| 215 Send(pending_reply_msg_.release()); | 217 Send(pending_reply_msg_.release()); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { | 220 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { |
| 219 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); | 221 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); |
| 220 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); | 222 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); |
| 221 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result); | 223 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result); |
| 222 Send(pending_reply_msg_.release()); | 224 Send(pending_reply_msg_.release()); |
| 223 } | 225 } |
| OLD | NEW |