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

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

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

Powered by Google App Engine
This is Rietveld 408576698