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

Side by Side Diff: chrome/common/db_message_filter.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/db_message_filter.h ('k') | chrome/common/render_messages.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) 2009 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/db_message_filter.h" 5 #include "chrome/common/db_message_filter.h"
6 6
7 #include "chrome/common/child_process.h"
8 #include "chrome/common/render_messages.h" 7 #include "chrome/common/render_messages.h"
9 #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" 8 #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h"
10 9
11 DBMessageFilter* DBMessageFilter::instance_ = NULL; 10 DBMessageFilter::DBMessageFilter() {
12
13 DBMessageFilter::DBMessageFilter()
14 : io_thread_message_loop_(ChildProcess::current()->io_message_loop()),
15 channel_(NULL),
16 shutdown_event_(ChildProcess::current()->GetShutDownEvent()),
17 messages_awaiting_replies_(new IDMap<DBMessageState>()),
18 unique_id_generator_(new base::AtomicSequenceNumber()) {
19 DCHECK(!instance_);
20 instance_ = this;
21 }
22
23 int DBMessageFilter::GetUniqueID() {
24 return unique_id_generator_->GetNext();
25 }
26
27 static void SendMessageOnIOThread(IPC::Message* message,
28 IPC::Channel* channel,
29 Lock* channel_lock) {
30 AutoLock channel_auto_lock(*channel_lock);
31 if (channel)
32 channel->Send(message);
33 else
34 delete message;
35 }
36
37 void DBMessageFilter::Send(IPC::Message* message) {
38 io_thread_message_loop_->PostTask(FROM_HERE,
39 NewRunnableFunction(SendMessageOnIOThread, message, channel_,
40 &channel_lock_));
41 }
42
43 void DBMessageFilter::OnFilterAdded(IPC::Channel* channel) {
44 AutoLock channel_auto_lock(channel_lock_);
45 channel_ = channel;
46 }
47
48 void DBMessageFilter::OnChannelError() {
49 AutoLock channel_auto_lock(channel_lock_);
50 channel_ = NULL;
51 }
52
53 void DBMessageFilter::OnChannelClosing() {
54 AutoLock channel_auto_lock(channel_lock_);
55 channel_ = NULL;
56 } 11 }
57 12
58 bool DBMessageFilter::OnMessageReceived(const IPC::Message& message) { 13 bool DBMessageFilter::OnMessageReceived(const IPC::Message& message) {
59 bool handled = true; 14 bool handled = true;
60 IPC_BEGIN_MESSAGE_MAP(DBMessageFilter, message) 15 IPC_BEGIN_MESSAGE_MAP(DBMessageFilter, message)
61 IPC_MESSAGE_HANDLER(ViewMsg_DatabaseOpenFileResponse,
62 OnResponse<ViewMsg_DatabaseOpenFileResponse_Params>)
63 IPC_MESSAGE_HANDLER(ViewMsg_DatabaseDeleteFileResponse, OnResponse<int>)
64 IPC_MESSAGE_HANDLER(ViewMsg_DatabaseGetFileAttributesResponse,
65 OnResponse<uint32>)
66 IPC_MESSAGE_HANDLER(ViewMsg_DatabaseGetFileSizeResponse, OnResponse<int64>)
67 IPC_MESSAGE_HANDLER(ViewMsg_DatabaseUpdateSize, OnDatabaseUpdateSize) 16 IPC_MESSAGE_HANDLER(ViewMsg_DatabaseUpdateSize, OnDatabaseUpdateSize)
68 IPC_MESSAGE_HANDLER(ViewMsg_DatabaseCloseImmediately, 17 IPC_MESSAGE_HANDLER(ViewMsg_DatabaseCloseImmediately,
69 OnDatabaseCloseImmediately) 18 OnDatabaseCloseImmediately)
70 IPC_MESSAGE_UNHANDLED(handled = false) 19 IPC_MESSAGE_UNHANDLED(handled = false)
71 IPC_END_MESSAGE_MAP() 20 IPC_END_MESSAGE_MAP()
72 return handled; 21 return handled;
73 } 22 }
74 23
75 void DBMessageFilter::OnDatabaseUpdateSize(const string16& origin_identifier, 24 void DBMessageFilter::OnDatabaseUpdateSize(const string16& origin_identifier,
76 const string16& database_name, 25 const string16& database_name,
77 int64 database_size, 26 int64 database_size,
78 int64 space_available) { 27 int64 space_available) {
79 WebKit::WebDatabase::updateDatabaseSize( 28 WebKit::WebDatabase::updateDatabaseSize(
80 origin_identifier, database_name, database_size, space_available); 29 origin_identifier, database_name, database_size, space_available);
81 } 30 }
82 31
83 void DBMessageFilter::OnDatabaseCloseImmediately( 32 void DBMessageFilter::OnDatabaseCloseImmediately(
84 const string16& origin_identifier, 33 const string16& origin_identifier,
85 const string16& database_name) { 34 const string16& database_name) {
86 WebKit::WebDatabase::closeDatabaseImmediately( 35 WebKit::WebDatabase::closeDatabaseImmediately(
87 origin_identifier, database_name); 36 origin_identifier, database_name);
88 } 37 }
OLDNEW
« no previous file with comments | « chrome/common/db_message_filter.h ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698