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

Side by Side Diff: chrome/common/database_util.cc

Issue 1601005: Allow synchronous messages to be sent from threads other than the main thread... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 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
« no previous file with comments | « chrome/common/child_thread.cc ('k') | chrome/common/db_message_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/common/database_util.h" 5 #include "chrome/common/database_util.h"
6 6
7 #if defined(USE_SYSTEM_SQLITE) 7 #if defined(USE_SYSTEM_SQLITE)
8 #include <sqlite3.h> 8 #include <sqlite3.h>
9 #else 9 #else
10 #include "third_party/sqlite/preprocessed/sqlite3.h" 10 #include "third_party/sqlite/preprocessed/sqlite3.h"
11 #endif 11 #endif
12 12
13 #include "chrome/common/db_message_filter.h" 13 #include "chrome/common/child_thread.h"
14 #include "chrome/common/render_messages.h" 14 #include "chrome/common/render_messages.h"
15 #include "ipc/ipc_sync_message_filter.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" 16 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
16 17
17 using WebKit::WebKitClient; 18 using WebKit::WebKitClient;
18 using WebKit::WebString; 19 using WebKit::WebString;
19 20
20 WebKitClient::FileHandle DatabaseUtil::databaseOpenFile( 21 WebKitClient::FileHandle DatabaseUtil::databaseOpenFile(
21 const WebString& vfs_file_name, int desired_flags, 22 const WebString& vfs_file_name, int desired_flags,
22 WebKitClient::FileHandle* dir_handle) { 23 WebKitClient::FileHandle* dir_handle) {
23 DBMessageFilter* db_message_filter = DBMessageFilter::GetInstance(); 24 IPC::PlatformFileForTransit file_handle;
24 int message_id = db_message_filter->GetUniqueID(); 25 #if defined(OS_WIN)
26 file_handle = base::kInvalidPlatformFileValue;
27 #elif defined(OS_POSIX)
28 file_handle =
29 base::FileDescriptor(base::kInvalidPlatformFileValue, true);
30 base::FileDescriptor dir_handle_rv =
31 base::FileDescriptor(base::kInvalidPlatformFileValue, true);
32 #endif
33
34 scoped_refptr<IPC::SyncMessageFilter> filter =
35 ChildThread::current()->sync_message_filter();
36
37 filter->Send(new ViewHostMsg_DatabaseOpenFile(
38 vfs_file_name,
39 desired_flags,
40 &file_handle
41 #if defined(OS_POSIX)
42 , &dir_handle_rv
43 #endif
44 ));
25 45
26 #if defined(OS_WIN) 46 #if defined(OS_WIN)
27 ViewMsg_DatabaseOpenFileResponse_Params default_response = 47 return file_handle;
28 { base::kInvalidPlatformFileValue };
29 #elif defined(OS_POSIX)
30 ViewMsg_DatabaseOpenFileResponse_Params default_response =
31 { base::FileDescriptor(base::kInvalidPlatformFileValue, true),
32 base::FileDescriptor(base::kInvalidPlatformFileValue, true) };
33 #endif
34
35 ViewMsg_DatabaseOpenFileResponse_Params result =
36 db_message_filter->SendAndWait(
37 new ViewHostMsg_DatabaseOpenFile(
38 vfs_file_name, desired_flags, message_id),
39 message_id, default_response);
40
41 #if defined(OS_WIN)
42 if (dir_handle)
43 *dir_handle = base::kInvalidPlatformFileValue;
44 return result.file_handle;
45 #elif defined(OS_POSIX) 48 #elif defined(OS_POSIX)
46 if (dir_handle) 49 if (dir_handle)
47 *dir_handle = result.dir_handle.fd; 50 *dir_handle = dir_handle_rv.fd;
48 return result.file_handle.fd; 51 return file_handle.fd;
49 #endif 52 #endif
50 } 53 }
51 54
52 int DatabaseUtil::databaseDeleteFile( 55 int DatabaseUtil::databaseDeleteFile(
53 const WebString& vfs_file_name, bool sync_dir) { 56 const WebString& vfs_file_name, bool sync_dir) {
54 DBMessageFilter* db_message_filter = DBMessageFilter::GetInstance(); 57 int rv = SQLITE_IOERR_DELETE;
55 int message_id = db_message_filter->GetUniqueID(); 58 scoped_refptr<IPC::SyncMessageFilter> filter =
56 return db_message_filter->SendAndWait( 59 ChildThread::current()->sync_message_filter();
57 new ViewHostMsg_DatabaseDeleteFile(vfs_file_name, sync_dir, message_id), 60 filter->Send(new ViewHostMsg_DatabaseDeleteFile(
58 message_id, SQLITE_IOERR_DELETE); 61 vfs_file_name, sync_dir, &rv));
62 return rv;
59 } 63 }
60 64
61 long DatabaseUtil::databaseGetFileAttributes( 65 long DatabaseUtil::databaseGetFileAttributes(const WebString& vfs_file_name) {
62 const WebString& vfs_file_name) { 66 int32 rv = -1;
63 DBMessageFilter* db_message_filter = DBMessageFilter::GetInstance(); 67 scoped_refptr<IPC::SyncMessageFilter> filter =
64 int message_id = db_message_filter->GetUniqueID(); 68 ChildThread::current()->sync_message_filter();
65 return db_message_filter->SendAndWait( 69 filter->Send(new ViewHostMsg_DatabaseGetFileAttributes(vfs_file_name, &rv));
66 new ViewHostMsg_DatabaseGetFileAttributes(vfs_file_name, message_id), 70 return rv;
67 message_id, -1L);
68 } 71 }
69 72
70 long long DatabaseUtil::databaseGetFileSize( 73 long long DatabaseUtil::databaseGetFileSize(const WebString& vfs_file_name) {
71 const WebString& vfs_file_name) { 74 int64 rv = 0LL;
72 DBMessageFilter* db_message_filter = DBMessageFilter::GetInstance(); 75 scoped_refptr<IPC::SyncMessageFilter> filter =
73 int message_id = db_message_filter->GetUniqueID(); 76 ChildThread::current()->sync_message_filter();
74 return db_message_filter->SendAndWait( 77 filter->Send(new ViewHostMsg_DatabaseGetFileSize(vfs_file_name, &rv));
75 new ViewHostMsg_DatabaseGetFileSize(vfs_file_name, message_id), 78 return rv;
76 message_id, 0LL);
77 } 79 }
OLDNEW
« no previous file with comments | « chrome/common/child_thread.cc ('k') | chrome/common/db_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698