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

Side by Side Diff: chrome/browser/renderer_host/database_dispatcher_host.cc

Issue 353015: Last patch in removing MessageLoop* caching. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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/renderer_host/database_dispatcher_host.h" 5 #include "chrome/browser/renderer_host/database_dispatcher_host.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
11 #if defined(USE_SYSTEM_SQLITE) 11 #if defined(USE_SYSTEM_SQLITE)
12 #include <sqlite3.h> 12 #include <sqlite3.h>
13 #else 13 #else
14 #include "third_party/sqlite/preprocessed/sqlite3.h" 14 #include "third_party/sqlite/preprocessed/sqlite3.h"
15 #endif 15 #endif
16 16
17 #include "base/thread.h" 17 #include "chrome/browser/chrome_thread.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/renderer_host/resource_message_filter.h" 18 #include "chrome/browser/renderer_host/resource_message_filter.h"
20 #include "chrome/common/render_messages.h" 19 #include "chrome/common/render_messages.h"
21 #include "webkit/database/vfs_backend.h" 20 #include "webkit/database/vfs_backend.h"
22 21
23 #if defined(OS_POSIX) 22 #if defined(OS_POSIX)
24 #include "base/file_descriptor_posix.h" 23 #include "base/file_descriptor_posix.h"
25 #endif 24 #endif
26 25
27 using webkit_database::VfsBackend; 26 using webkit_database::VfsBackend;
28 27
(...skipping 25 matching lines...) Expand all
54 // message filterto make sure it doesn't get destroyed before we have 53 // message filterto make sure it doesn't get destroyed before we have
55 // a chance to send the reply back. So we need to Release() is here 54 // a chance to send the reply back. So we need to Release() is here
56 // and allow it to be destroyed if needed. 55 // and allow it to be destroyed if needed.
57 sender->Release(); 56 sender->Release();
58 } 57 }
59 58
60 // Scheduled by the IO thread on the file thread. 59 // Scheduled by the IO thread on the file thread.
61 // Opens the given database file, then schedules 60 // Opens the given database file, then schedules
62 // a task on the IO thread's message loop to send an IPC back to 61 // a task on the IO thread's message loop to send an IPC back to
63 // corresponding renderer process with the file handle. 62 // corresponding renderer process with the file handle.
64 static void DatabaseOpenFile(MessageLoop* io_thread_message_loop, 63 static void DatabaseOpenFile(const OpenFileParams& params,
65 const OpenFileParams& params,
66 int32 message_id, 64 int32 message_id,
67 ResourceMessageFilter* sender) { 65 ResourceMessageFilter* sender) {
68 base::PlatformFile target_handle = base::kInvalidPlatformFileValue; 66 base::PlatformFile target_handle = base::kInvalidPlatformFileValue;
69 base::PlatformFile target_dir_handle = base::kInvalidPlatformFileValue; 67 base::PlatformFile target_dir_handle = base::kInvalidPlatformFileValue;
70 VfsBackend::OpenFile(params.file_name, params.db_dir, params.desired_flags, 68 VfsBackend::OpenFile(params.file_name, params.db_dir, params.desired_flags,
71 params.handle, &target_handle, &target_dir_handle); 69 params.handle, &target_handle, &target_dir_handle);
72 70
73 ViewMsg_DatabaseOpenFileResponse_Params response_params; 71 ViewMsg_DatabaseOpenFileResponse_Params response_params;
74 #if defined(OS_WIN) 72 #if defined(OS_WIN)
75 response_params.file_handle = target_handle; 73 response_params.file_handle = target_handle;
76 #elif defined(OS_POSIX) 74 #elif defined(OS_POSIX)
77 response_params.file_handle = base::FileDescriptor(target_handle, true); 75 response_params.file_handle = base::FileDescriptor(target_handle, true);
78 response_params.dir_handle = base::FileDescriptor(target_dir_handle, true); 76 response_params.dir_handle = base::FileDescriptor(target_dir_handle, true);
79 #endif 77 #endif
80 io_thread_message_loop->PostTask(FROM_HERE, 78 ChromeThread::PostTask(
79 ChromeThread::IO, FROM_HERE,
81 NewRunnableFunction(SendMessage, sender, 80 NewRunnableFunction(SendMessage, sender,
82 new ViewMsg_DatabaseOpenFileResponse(message_id, response_params))); 81 new ViewMsg_DatabaseOpenFileResponse(message_id, response_params)));
83 } 82 }
84 83
85 // Scheduled by the IO thread on the file thread. 84 // Scheduled by the IO thread on the file thread.
86 // Deletes the given database file, then schedules 85 // Deletes the given database file, then schedules
87 // a task on the IO thread's message loop to send an IPC back to 86 // a task on the IO thread's message loop to send an IPC back to
88 // corresponding renderer process with the error code. 87 // corresponding renderer process with the error code.
89 static void DatabaseDeleteFile(MessageLoop* io_thread_message_loop, 88 static void DatabaseDeleteFile(const DeleteFileParams& params,
90 const DeleteFileParams& params,
91 int32 message_id, 89 int32 message_id,
92 int reschedule_count, 90 int reschedule_count,
93 ResourceMessageFilter* sender) { 91 ResourceMessageFilter* sender) {
94 // Return an error if the file could not be deleted 92 // Return an error if the file could not be deleted
95 // after kNumDeleteRetries times. 93 // after kNumDeleteRetries times.
96 if (!reschedule_count) { 94 if (!reschedule_count) {
97 io_thread_message_loop->PostTask(FROM_HERE, 95 ChromeThread::PostTask(
96 ChromeThread::IO, FROM_HERE,
98 NewRunnableFunction(SendMessage, sender, 97 NewRunnableFunction(SendMessage, sender,
99 new ViewMsg_DatabaseDeleteFileResponse(message_id, 98 new ViewMsg_DatabaseDeleteFileResponse(message_id,
100 SQLITE_IOERR_DELETE))); 99 SQLITE_IOERR_DELETE)));
101 return; 100 return;
102 } 101 }
103 102
104 int error_code = 103 int error_code =
105 VfsBackend::DeleteFile(params.file_name, params.db_dir, params.sync_dir); 104 VfsBackend::DeleteFile(params.file_name, params.db_dir, params.sync_dir);
106 if (error_code == SQLITE_IOERR_DELETE) { 105 if (error_code == SQLITE_IOERR_DELETE) {
107 // If the file could not be deleted, try again. 106 // If the file could not be deleted, try again.
108 MessageLoop::current()->PostDelayedTask(FROM_HERE, 107 MessageLoop::current()->PostDelayedTask(FROM_HERE,
109 NewRunnableFunction(DatabaseDeleteFile, io_thread_message_loop, 108 NewRunnableFunction(DatabaseDeleteFile, params, message_id,
110 params, message_id, reschedule_count - 1, sender), 109 reschedule_count - 1, sender),
111 kDelayDeleteRetryMs); 110 kDelayDeleteRetryMs);
112 return; 111 return;
113 } 112 }
114 113
115 io_thread_message_loop->PostTask(FROM_HERE, 114 ChromeThread::PostTask(
115 ChromeThread::IO, FROM_HERE,
116 NewRunnableFunction(SendMessage, sender, 116 NewRunnableFunction(SendMessage, sender,
117 new ViewMsg_DatabaseDeleteFileResponse(message_id, error_code))); 117 new ViewMsg_DatabaseDeleteFileResponse(message_id, error_code)));
118 } 118 }
119 119
120 // Scheduled by the IO thread on the file thread. 120 // Scheduled by the IO thread on the file thread.
121 // Gets the attributes of the given database file, then schedules 121 // Gets the attributes of the given database file, then schedules
122 // a task on the IO thread's message loop to send an IPC back to 122 // a task on the IO thread's message loop to send an IPC back to
123 // corresponding renderer process. 123 // corresponding renderer process.
124 static void DatabaseGetFileAttributes(MessageLoop* io_thread_message_loop, 124 static void DatabaseGetFileAttributes(const FilePath& file_name,
125 const FilePath& file_name,
126 int32 message_id, 125 int32 message_id,
127 ResourceMessageFilter* sender) { 126 ResourceMessageFilter* sender) {
128 uint32 attributes = VfsBackend::GetFileAttributes(file_name); 127 uint32 attributes = VfsBackend::GetFileAttributes(file_name);
129 io_thread_message_loop->PostTask(FROM_HERE, 128 ChromeThread::PostTask(
129 ChromeThread::IO, FROM_HERE,
130 NewRunnableFunction(SendMessage, sender, 130 NewRunnableFunction(SendMessage, sender,
131 new ViewMsg_DatabaseGetFileAttributesResponse( 131 new ViewMsg_DatabaseGetFileAttributesResponse(
132 message_id, attributes))); 132 message_id, attributes)));
133 } 133 }
134 134
135 // Scheduled by the IO thread on the file thread. 135 // Scheduled by the IO thread on the file thread.
136 // Gets the size of the given file, then schedules a task 136 // Gets the size of the given file, then schedules a task
137 // on the IO thread's message loop to send an IPC back to 137 // on the IO thread's message loop to send an IPC back to
138 // the corresponding renderer process. 138 // the corresponding renderer process.
139 static void DatabaseGetFileSize(MessageLoop* io_thread_message_loop, 139 static void DatabaseGetFileSize(const FilePath& file_name,
140 const FilePath& file_name,
141 int32 message_id, 140 int32 message_id,
142 ResourceMessageFilter* sender) { 141 ResourceMessageFilter* sender) {
143 int64 size = VfsBackend::GetFileSize(file_name); 142 int64 size = VfsBackend::GetFileSize(file_name);
144 io_thread_message_loop->PostTask(FROM_HERE, 143 ChromeThread::PostTask(
144 ChromeThread::IO, FROM_HERE,
145 NewRunnableFunction(SendMessage, sender, 145 NewRunnableFunction(SendMessage, sender,
146 new ViewMsg_DatabaseGetFileSizeResponse(message_id, size))); 146 new ViewMsg_DatabaseGetFileSizeResponse(message_id, size)));
147 } 147 }
148 148
149 } // namespace 149 } // namespace
150 150
151 DatabaseDispatcherHost::DatabaseDispatcherHost( 151 DatabaseDispatcherHost::DatabaseDispatcherHost(
152 const FilePath& profile_path, 152 const FilePath& profile_path,
153 ResourceMessageFilter* resource_message_filter) 153 ResourceMessageFilter* resource_message_filter)
154 : profile_path_(profile_path), 154 : profile_path_(profile_path),
155 resource_message_filter_(resource_message_filter), 155 resource_message_filter_(resource_message_filter) {
156 file_thread_message_loop_(
157 g_browser_process->file_thread()->message_loop()) {
158 }
159
160
161 bool DatabaseDispatcherHost::IsDBMessage(const IPC::Message& message) {
162 switch (message.type()) {
163 case ViewHostMsg_DatabaseOpenFile::ID:
164 case ViewHostMsg_DatabaseDeleteFile::ID:
165 case ViewHostMsg_DatabaseGetFileAttributes::ID:
166 case ViewHostMsg_DatabaseGetFileSize::ID:
167 return true;
168 default:
169 return false;
170 }
171 } 156 }
172 157
173 bool DatabaseDispatcherHost::OnMessageReceived( 158 bool DatabaseDispatcherHost::OnMessageReceived(
174 const IPC::Message& message, bool* message_was_ok) { 159 const IPC::Message& message, bool* message_was_ok) {
175 if (!IsDBMessage(message))
176 return false;
177 *message_was_ok = true; 160 *message_was_ok = true;
178 161
179 bool handled = true; 162 bool handled = true;
180 IPC_BEGIN_MESSAGE_MAP_EX(DatabaseDispatcherHost, message, *message_was_ok) 163 IPC_BEGIN_MESSAGE_MAP_EX(DatabaseDispatcherHost, message, *message_was_ok)
181 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseOpenFile, OnDatabaseOpenFile); 164 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseOpenFile, OnDatabaseOpenFile);
182 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseDeleteFile, OnDatabaseDeleteFile); 165 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseDeleteFile, OnDatabaseDeleteFile);
183 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseGetFileAttributes, 166 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseGetFileAttributes,
184 OnDatabaseGetFileAttributes); 167 OnDatabaseGetFileAttributes);
185 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseGetFileSize, 168 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseGetFileSize,
186 OnDatabaseGetFileSize); 169 OnDatabaseGetFileSize);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 message_id, response_params)); 206 message_id, response_params));
224 return; 207 return;
225 } 208 }
226 209
227 OpenFileParams params; 210 OpenFileParams params;
228 params.db_dir = GetDBDir(); 211 params.db_dir = GetDBDir();
229 params.file_name = db_file_name; 212 params.file_name = db_file_name;
230 params.desired_flags = desired_flags; 213 params.desired_flags = desired_flags;
231 params.handle = resource_message_filter_->handle(); 214 params.handle = resource_message_filter_->handle();
232 resource_message_filter_->AddRef(); 215 resource_message_filter_->AddRef();
233 file_thread_message_loop_->PostTask(FROM_HERE, 216 ChromeThread::PostTask(
234 NewRunnableFunction(DatabaseOpenFile, MessageLoop::current(), 217 ChromeThread::FILE, FROM_HERE,
235 params, message_id, resource_message_filter_)); 218 NewRunnableFunction(
219 DatabaseOpenFile, params, message_id, resource_message_filter_));
236 } 220 }
237 221
238 void DatabaseDispatcherHost::OnDatabaseDeleteFile( 222 void DatabaseDispatcherHost::OnDatabaseDeleteFile(
239 const FilePath& file_name, const bool& sync_dir, int32 message_id) { 223 const FilePath& file_name, const bool& sync_dir, int32 message_id) {
240 FilePath db_file_name = GetDBFileFullPath(file_name); 224 FilePath db_file_name = GetDBFileFullPath(file_name);
241 if (db_file_name.empty()) { 225 if (db_file_name.empty()) {
242 resource_message_filter_->Send(new ViewMsg_DatabaseDeleteFileResponse( 226 resource_message_filter_->Send(new ViewMsg_DatabaseDeleteFileResponse(
243 message_id, SQLITE_IOERR_DELETE)); 227 message_id, SQLITE_IOERR_DELETE));
244 return; 228 return;
245 } 229 }
246 230
247 DeleteFileParams params; 231 DeleteFileParams params;
248 params.db_dir = GetDBDir(); 232 params.db_dir = GetDBDir();
249 params.file_name = db_file_name; 233 params.file_name = db_file_name;
250 params.sync_dir = sync_dir; 234 params.sync_dir = sync_dir;
251 resource_message_filter_->AddRef(); 235 resource_message_filter_->AddRef();
252 file_thread_message_loop_->PostTask(FROM_HERE, 236 ChromeThread::PostTask(
253 NewRunnableFunction(DatabaseDeleteFile, MessageLoop::current(), 237 ChromeThread::FILE, FROM_HERE,
254 params, message_id, kNumDeleteRetries, 238 NewRunnableFunction(
255 resource_message_filter_)); 239 DatabaseDeleteFile, params, message_id, kNumDeleteRetries,
240 resource_message_filter_));
256 } 241 }
257 242
258 void DatabaseDispatcherHost::OnDatabaseGetFileAttributes( 243 void DatabaseDispatcherHost::OnDatabaseGetFileAttributes(
259 const FilePath& file_name, int32 message_id) { 244 const FilePath& file_name, int32 message_id) {
260 FilePath db_file_name = GetDBFileFullPath(file_name); 245 FilePath db_file_name = GetDBFileFullPath(file_name);
261 if (db_file_name.empty()) { 246 if (db_file_name.empty()) {
262 resource_message_filter_->Send( 247 resource_message_filter_->Send(
263 new ViewMsg_DatabaseGetFileAttributesResponse(message_id, -1)); 248 new ViewMsg_DatabaseGetFileAttributesResponse(message_id, -1));
264 return; 249 return;
265 } 250 }
266 251
267 resource_message_filter_->AddRef(); 252 resource_message_filter_->AddRef();
268 file_thread_message_loop_->PostTask(FROM_HERE, 253 ChromeThread::PostTask(
269 NewRunnableFunction(DatabaseGetFileAttributes, MessageLoop::current(), 254 ChromeThread::FILE, FROM_HERE,
270 db_file_name, message_id, resource_message_filter_)); 255 NewRunnableFunction(
256 DatabaseGetFileAttributes, db_file_name, message_id,
257 resource_message_filter_));
271 } 258 }
272 259
273 void DatabaseDispatcherHost::OnDatabaseGetFileSize( 260 void DatabaseDispatcherHost::OnDatabaseGetFileSize(
274 const FilePath& file_name, int32 message_id) { 261 const FilePath& file_name, int32 message_id) {
275 FilePath db_file_name = GetDBFileFullPath(file_name); 262 FilePath db_file_name = GetDBFileFullPath(file_name);
276 if (db_file_name.empty()) { 263 if (db_file_name.empty()) {
277 resource_message_filter_->Send(new ViewMsg_DatabaseGetFileSizeResponse( 264 resource_message_filter_->Send(new ViewMsg_DatabaseGetFileSizeResponse(
278 message_id, 0)); 265 message_id, 0));
279 return; 266 return;
280 } 267 }
281 268
282 resource_message_filter_->AddRef(); 269 resource_message_filter_->AddRef();
283 file_thread_message_loop_->PostTask(FROM_HERE, 270 ChromeThread::PostTask(
284 NewRunnableFunction(DatabaseGetFileSize, MessageLoop::current(), 271 ChromeThread::FILE, FROM_HERE,
285 db_file_name, message_id, resource_message_filter_)); 272 NewRunnableFunction(
273 DatabaseGetFileSize, db_file_name, message_id,
274 resource_message_filter_));
286 } 275 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/database_dispatcher_host.h ('k') | chrome/browser/renderer_host/resource_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698