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

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

Issue 5625003: Make the AppCacheDispatcherHost be a MessageFilter so that ResourceMessageFil... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix dependency issue in AppCacheDispatcherHost Created 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/appcache/appcache_dispatcher_host.h" 5 #include "chrome/browser/appcache/appcache_dispatcher_host.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "chrome/browser/appcache/chrome_appcache_service.h" 8 #include "chrome/browser/appcache/chrome_appcache_service.h"
9 #include "chrome/browser/renderer_host/browser_render_process_host.h" 9 #include "chrome/browser/renderer_host/browser_render_process_host.h"
10 #include "chrome/browser/net/chrome_url_request_context.h" 10 #include "chrome/browser/net/chrome_url_request_context.h"
11 #include "chrome/common/render_messages.h" 11 #include "chrome/common/render_messages.h"
12 12
13 AppCacheDispatcherHost::AppCacheDispatcherHost( 13 AppCacheDispatcherHost::AppCacheDispatcherHost(
14 URLRequestContext* request_context) 14 URLRequestContext* request_context,
15 : request_context_(request_context), 15 int process_id)
16 receiver_(NULL) { 16 : ALLOW_THIS_IN_INITIALIZER_LIST(frontend_proxy_(this)),
17 request_context_(request_context),
18 process_id_(process_id) {
17 DCHECK(request_context_.get()); 19 DCHECK(request_context_.get());
18 } 20 }
19 21
20 AppCacheDispatcherHost::AppCacheDispatcherHost( 22 AppCacheDispatcherHost::AppCacheDispatcherHost(
21 URLRequestContextGetter* request_context_getter) 23 URLRequestContextGetter* request_context_getter,
22 : request_context_getter_(request_context_getter), 24 int process_id)
23 receiver_(NULL) { 25 : ALLOW_THIS_IN_INITIALIZER_LIST(frontend_proxy_(this)),
26 request_context_getter_(request_context_getter),
27 process_id_(process_id) {
24 DCHECK(request_context_getter_.get()); 28 DCHECK(request_context_getter_.get());
25 } 29 }
26 30
27 AppCacheDispatcherHost::~AppCacheDispatcherHost() {} 31 AppCacheDispatcherHost::~AppCacheDispatcherHost() {}
28 32
29 void AppCacheDispatcherHost::Initialize( 33 void AppCacheDispatcherHost::OnChannelConnected(int32 peer_pid) {
30 ResourceDispatcherHost::Receiver* receiver) { 34 BrowserIOMessageFilter::OnChannelConnected(peer_pid);
31 DCHECK(receiver && !receiver_); 35
32 DCHECK(request_context_.get() || request_context_getter_.get()); 36 DCHECK(request_context_.get() || request_context_getter_.get());
33 37
34 receiver_ = receiver;
35
36 // Get the AppCacheService (it can only be accessed from IO thread). 38 // Get the AppCacheService (it can only be accessed from IO thread).
37 URLRequestContext* context = request_context_.get(); 39 URLRequestContext* context = request_context_.get();
38 if (!context) 40 if (!context)
39 context = request_context_getter_->GetURLRequestContext(); 41 context = request_context_getter_->GetURLRequestContext();
40 appcache_service_ = 42 appcache_service_ =
41 static_cast<ChromeURLRequestContext*>(context)->appcache_service(); 43 static_cast<ChromeURLRequestContext*>(context)->appcache_service();
42 request_context_ = NULL; 44 request_context_ = NULL;
43 request_context_getter_ = NULL; 45 request_context_getter_ = NULL;
44 46
45 frontend_proxy_.set_sender(receiver);
46 if (appcache_service_.get()) { 47 if (appcache_service_.get()) {
47 backend_impl_.Initialize( 48 backend_impl_.Initialize(
48 appcache_service_.get(), &frontend_proxy_, receiver->id()); 49 appcache_service_.get(), &frontend_proxy_, process_id_);
49 get_status_callback_.reset( 50 get_status_callback_.reset(
50 NewCallback(this, &AppCacheDispatcherHost::GetStatusCallback)); 51 NewCallback(this, &AppCacheDispatcherHost::GetStatusCallback));
51 start_update_callback_.reset( 52 start_update_callback_.reset(
52 NewCallback(this, &AppCacheDispatcherHost::StartUpdateCallback)); 53 NewCallback(this, &AppCacheDispatcherHost::StartUpdateCallback));
53 swap_cache_callback_.reset( 54 swap_cache_callback_.reset(
54 NewCallback(this, &AppCacheDispatcherHost::SwapCacheCallback)); 55 NewCallback(this, &AppCacheDispatcherHost::SwapCacheCallback));
55 } 56 }
56 } 57 }
57 58
58 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& msg, 59 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) {
59 bool *msg_ok) {
60 DCHECK(receiver_);
61 *msg_ok = true;
62 bool handled = true; 60 bool handled = true;
63 IPC_BEGIN_MESSAGE_MAP_EX(AppCacheDispatcherHost, msg, *msg_ok) 61 bool message_was_ok = true;
62
63 IPC_BEGIN_MESSAGE_MAP_EX(AppCacheDispatcherHost, message, message_was_ok)
64 IPC_MESSAGE_HANDLER(AppCacheMsg_RegisterHost, OnRegisterHost); 64 IPC_MESSAGE_HANDLER(AppCacheMsg_RegisterHost, OnRegisterHost);
65 IPC_MESSAGE_HANDLER(AppCacheMsg_UnregisterHost, OnUnregisterHost); 65 IPC_MESSAGE_HANDLER(AppCacheMsg_UnregisterHost, OnUnregisterHost);
66 IPC_MESSAGE_HANDLER(AppCacheMsg_GetResourceList, OnGetResourceList); 66 IPC_MESSAGE_HANDLER(AppCacheMsg_GetResourceList, OnGetResourceList);
67 IPC_MESSAGE_HANDLER(AppCacheMsg_SelectCache, OnSelectCache); 67 IPC_MESSAGE_HANDLER(AppCacheMsg_SelectCache, OnSelectCache);
68 IPC_MESSAGE_HANDLER(AppCacheMsg_SelectCacheForWorker, 68 IPC_MESSAGE_HANDLER(AppCacheMsg_SelectCacheForWorker,
69 OnSelectCacheForWorker); 69 OnSelectCacheForWorker);
70 IPC_MESSAGE_HANDLER(AppCacheMsg_SelectCacheForSharedWorker, 70 IPC_MESSAGE_HANDLER(AppCacheMsg_SelectCacheForSharedWorker,
71 OnSelectCacheForSharedWorker); 71 OnSelectCacheForSharedWorker);
72 IPC_MESSAGE_HANDLER(AppCacheMsg_MarkAsForeignEntry, OnMarkAsForeignEntry); 72 IPC_MESSAGE_HANDLER(AppCacheMsg_MarkAsForeignEntry, OnMarkAsForeignEntry);
73 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_GetStatus, OnGetStatus); 73 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_GetStatus, OnGetStatus);
74 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_StartUpdate, OnStartUpdate); 74 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_StartUpdate, OnStartUpdate);
75 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_SwapCache, OnSwapCache); 75 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_SwapCache, OnSwapCache);
76 IPC_MESSAGE_UNHANDLED(handled = false) 76 IPC_MESSAGE_UNHANDLED(handled = false)
77 IPC_END_MESSAGE_MAP_EX() 77 IPC_END_MESSAGE_MAP_EX()
78
79 if (!message_was_ok)
80 BadMessageReceived(message.type());
81
78 return handled; 82 return handled;
79 } 83 }
80 84
81 void AppCacheDispatcherHost::OnRegisterHost(int host_id) { 85 void AppCacheDispatcherHost::OnRegisterHost(int host_id) {
82 if (appcache_service_.get()) { 86 if (appcache_service_.get()) {
83 if (!backend_impl_.RegisterHost(host_id)) { 87 if (!backend_impl_.RegisterHost(host_id)) {
84 ReceivedBadMessage(AppCacheMsg_RegisterHost::ID); 88 BadMessageReceived(AppCacheMsg_RegisterHost::ID);
85 } 89 }
86 } 90 }
87 } 91 }
88 92
89 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { 93 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) {
90 if (appcache_service_.get()) { 94 if (appcache_service_.get()) {
91 if (!backend_impl_.UnregisterHost(host_id)) { 95 if (!backend_impl_.UnregisterHost(host_id)) {
92 ReceivedBadMessage(AppCacheMsg_UnregisterHost::ID); 96 BadMessageReceived(AppCacheMsg_UnregisterHost::ID);
93 } 97 }
94 } 98 }
95 } 99 }
96 100
97 void AppCacheDispatcherHost::OnSelectCache( 101 void AppCacheDispatcherHost::OnSelectCache(
98 int host_id, const GURL& document_url, 102 int host_id, const GURL& document_url,
99 int64 cache_document_was_loaded_from, 103 int64 cache_document_was_loaded_from,
100 const GURL& opt_manifest_url) { 104 const GURL& opt_manifest_url) {
101 if (appcache_service_.get()) { 105 if (appcache_service_.get()) {
102 if (!backend_impl_.SelectCache(host_id, document_url, 106 if (!backend_impl_.SelectCache(host_id, document_url,
103 cache_document_was_loaded_from, 107 cache_document_was_loaded_from,
104 opt_manifest_url)) { 108 opt_manifest_url)) {
105 ReceivedBadMessage(AppCacheMsg_SelectCache::ID); 109 BadMessageReceived(AppCacheMsg_SelectCache::ID);
106 } 110 }
107 } else { 111 } else {
108 frontend_proxy_.OnCacheSelected(host_id, appcache::AppCacheInfo()); 112 frontend_proxy_.OnCacheSelected(host_id, appcache::AppCacheInfo());
109 } 113 }
110 } 114 }
111 115
112 void AppCacheDispatcherHost::OnSelectCacheForWorker( 116 void AppCacheDispatcherHost::OnSelectCacheForWorker(
113 int host_id, int parent_process_id, int parent_host_id) { 117 int host_id, int parent_process_id, int parent_host_id) {
114 if (appcache_service_.get()) { 118 if (appcache_service_.get()) {
115 if (!backend_impl_.SelectCacheForWorker( 119 if (!backend_impl_.SelectCacheForWorker(
116 host_id, parent_process_id, parent_host_id)) { 120 host_id, parent_process_id, parent_host_id)) {
117 ReceivedBadMessage(AppCacheMsg_SelectCacheForWorker::ID); 121 BadMessageReceived(AppCacheMsg_SelectCacheForWorker::ID);
118 } 122 }
119 } else { 123 } else {
120 frontend_proxy_.OnCacheSelected(host_id, appcache::AppCacheInfo()); 124 frontend_proxy_.OnCacheSelected(host_id, appcache::AppCacheInfo());
121 } 125 }
122 } 126 }
123 127
124 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker( 128 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker(
125 int host_id, int64 appcache_id) { 129 int host_id, int64 appcache_id) {
126 if (appcache_service_.get()) { 130 if (appcache_service_.get()) {
127 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id)) 131 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id))
128 ReceivedBadMessage(AppCacheMsg_SelectCacheForSharedWorker::ID); 132 BadMessageReceived(AppCacheMsg_SelectCacheForSharedWorker::ID);
129 } else { 133 } else {
130 frontend_proxy_.OnCacheSelected(host_id, appcache::AppCacheInfo()); 134 frontend_proxy_.OnCacheSelected(host_id, appcache::AppCacheInfo());
131 } 135 }
132 } 136 }
133 137
134 void AppCacheDispatcherHost::OnMarkAsForeignEntry( 138 void AppCacheDispatcherHost::OnMarkAsForeignEntry(
135 int host_id, const GURL& document_url, 139 int host_id, const GURL& document_url,
136 int64 cache_document_was_loaded_from) { 140 int64 cache_document_was_loaded_from) {
137 if (appcache_service_.get()) { 141 if (appcache_service_.get()) {
138 if (!backend_impl_.MarkAsForeignEntry(host_id, document_url, 142 if (!backend_impl_.MarkAsForeignEntry(host_id, document_url,
139 cache_document_was_loaded_from)) { 143 cache_document_was_loaded_from)) {
140 ReceivedBadMessage(AppCacheMsg_MarkAsForeignEntry::ID); 144 BadMessageReceived(AppCacheMsg_MarkAsForeignEntry::ID);
141 } 145 }
142 } 146 }
143 } 147 }
144 148
145 void AppCacheDispatcherHost::OnGetResourceList( 149 void AppCacheDispatcherHost::OnGetResourceList(
146 int host_id, std::vector<appcache::AppCacheResourceInfo>* params) { 150 int host_id, std::vector<appcache::AppCacheResourceInfo>* params) {
147 if (appcache_service_.get()) 151 if (appcache_service_.get())
148 backend_impl_.GetResourceList(host_id, params); 152 backend_impl_.GetResourceList(host_id, params);
149 } 153 }
150 154
151 void AppCacheDispatcherHost::OnGetStatus(int host_id, 155 void AppCacheDispatcherHost::OnGetStatus(int host_id,
152 IPC::Message* reply_msg) { 156 IPC::Message* reply_msg) {
153 if (pending_reply_msg_.get()) { 157 if (pending_reply_msg_.get()) {
154 ReceivedBadMessage(AppCacheMsg_GetStatus::ID); 158 BadMessageReceived(AppCacheMsg_GetStatus::ID);
155 delete reply_msg; 159 delete reply_msg;
156 return; 160 return;
157 } 161 }
158 162
159 pending_reply_msg_.reset(reply_msg); 163 pending_reply_msg_.reset(reply_msg);
160 if (appcache_service_.get()) { 164 if (appcache_service_.get()) {
161 if (!backend_impl_.GetStatusWithCallback( 165 if (!backend_impl_.GetStatusWithCallback(
162 host_id, get_status_callback_.get(), reply_msg)) { 166 host_id, get_status_callback_.get(), reply_msg)) {
163 ReceivedBadMessage(AppCacheMsg_GetStatus::ID); 167 BadMessageReceived(AppCacheMsg_GetStatus::ID);
164 } 168 }
165 return; 169 return;
166 } 170 }
167 171
168 GetStatusCallback(appcache::UNCACHED, reply_msg); 172 GetStatusCallback(appcache::UNCACHED, reply_msg);
169 } 173 }
170 174
171 void AppCacheDispatcherHost::OnStartUpdate(int host_id, 175 void AppCacheDispatcherHost::OnStartUpdate(int host_id,
172 IPC::Message* reply_msg) { 176 IPC::Message* reply_msg) {
173 if (pending_reply_msg_.get()) { 177 if (pending_reply_msg_.get()) {
174 ReceivedBadMessage(AppCacheMsg_StartUpdate::ID); 178 BadMessageReceived(AppCacheMsg_StartUpdate::ID);
175 delete reply_msg; 179 delete reply_msg;
176 return; 180 return;
177 } 181 }
178 182
179 pending_reply_msg_.reset(reply_msg); 183 pending_reply_msg_.reset(reply_msg);
180 if (appcache_service_.get()) { 184 if (appcache_service_.get()) {
181 if (!backend_impl_.StartUpdateWithCallback( 185 if (!backend_impl_.StartUpdateWithCallback(
182 host_id, start_update_callback_.get(), reply_msg)) { 186 host_id, start_update_callback_.get(), reply_msg)) {
183 ReceivedBadMessage(AppCacheMsg_StartUpdate::ID); 187 BadMessageReceived(AppCacheMsg_StartUpdate::ID);
184 } 188 }
185 return; 189 return;
186 } 190 }
187 191
188 StartUpdateCallback(false, reply_msg); 192 StartUpdateCallback(false, reply_msg);
189 } 193 }
190 194
191 void AppCacheDispatcherHost::OnSwapCache(int host_id, 195 void AppCacheDispatcherHost::OnSwapCache(int host_id,
192 IPC::Message* reply_msg) { 196 IPC::Message* reply_msg) {
193 if (pending_reply_msg_.get()) { 197 if (pending_reply_msg_.get()) {
194 ReceivedBadMessage(AppCacheMsg_SwapCache::ID); 198 BadMessageReceived(AppCacheMsg_SwapCache::ID);
195 delete reply_msg; 199 delete reply_msg;
196 return; 200 return;
197 } 201 }
198 202
199 pending_reply_msg_.reset(reply_msg); 203 pending_reply_msg_.reset(reply_msg);
200 if (appcache_service_.get()) { 204 if (appcache_service_.get()) {
201 if (!backend_impl_.SwapCacheWithCallback( 205 if (!backend_impl_.SwapCacheWithCallback(
202 host_id, swap_cache_callback_.get(), reply_msg)) { 206 host_id, swap_cache_callback_.get(), reply_msg)) {
203 ReceivedBadMessage(AppCacheMsg_SwapCache::ID); 207 BadMessageReceived(AppCacheMsg_SwapCache::ID);
204 } 208 }
205 return; 209 return;
206 } 210 }
207 211
208 SwapCacheCallback(false, reply_msg); 212 SwapCacheCallback(false, reply_msg);
209 } 213 }
210 214
211 void AppCacheDispatcherHost::GetStatusCallback( 215 void AppCacheDispatcherHost::GetStatusCallback(
212 appcache::Status status, void* param) { 216 appcache::Status status, void* param) {
213 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); 217 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param);
214 DCHECK(reply_msg == pending_reply_msg_.get()); 218 DCHECK(reply_msg == pending_reply_msg_.get());
215 AppCacheMsg_GetStatus::WriteReplyParams(reply_msg, status); 219 AppCacheMsg_GetStatus::WriteReplyParams(reply_msg, status);
216 frontend_proxy_.sender()->Send(pending_reply_msg_.release()); 220 Send(pending_reply_msg_.release());
217 } 221 }
218 222
219 void AppCacheDispatcherHost::StartUpdateCallback(bool result, void* param) { 223 void AppCacheDispatcherHost::StartUpdateCallback(bool result, void* param) {
220 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); 224 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param);
221 DCHECK(reply_msg == pending_reply_msg_.get()); 225 DCHECK(reply_msg == pending_reply_msg_.get());
222 AppCacheMsg_StartUpdate::WriteReplyParams(reply_msg, result); 226 AppCacheMsg_StartUpdate::WriteReplyParams(reply_msg, result);
223 frontend_proxy_.sender()->Send(pending_reply_msg_.release()); 227 Send(pending_reply_msg_.release());
224 } 228 }
225 229
226 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { 230 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) {
227 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); 231 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param);
228 DCHECK(reply_msg == pending_reply_msg_.get()); 232 DCHECK(reply_msg == pending_reply_msg_.get());
229 AppCacheMsg_SwapCache::WriteReplyParams(reply_msg, result); 233 AppCacheMsg_SwapCache::WriteReplyParams(reply_msg, result);
230 frontend_proxy_.sender()->Send(pending_reply_msg_.release()); 234 Send(pending_reply_msg_.release());
231 } 235 }
232
233 void AppCacheDispatcherHost::ReceivedBadMessage(uint32 msg_type) {
234 // TODO(michaeln): Consider gathering UMA stats
235 // http://code.google.com/p/chromium/issues/detail?id=24634
236 BrowserRenderProcessHost::BadMessageTerminateProcess(
237 msg_type, receiver_->handle());
238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698