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

Side by Side Diff: webkit/support/simple_database_system.cc

Issue 8510036: Take 2, base::Bind cleanup in SimpleDatabaseSystem (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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
« no previous file with comments | « webkit/support/simple_database_system.h ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 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 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 "webkit/support/simple_database_system.h" 5 #include "webkit/support/simple_database_system.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h"
9 #include "base/bind_helpers.h"
8 #include "base/file_util.h" 10 #include "base/file_util.h"
9 #include "base/message_loop.h" 11 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
11 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
12 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
13 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
14 #include "third_party/sqlite/sqlite3.h" 16 #include "third_party/sqlite/sqlite3.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
17 #include "webkit/database/database_util.h" 19 #include "webkit/database/database_util.h"
(...skipping 20 matching lines...) Expand all
38 CHECK(temp_dir_.CreateUniqueTempDir()); 40 CHECK(temp_dir_.CreateUniqueTempDir());
39 db_tracker_ = 41 db_tracker_ =
40 new DatabaseTracker(temp_dir_.path(), false, false, NULL, NULL, NULL); 42 new DatabaseTracker(temp_dir_.path(), false, false, NULL, NULL, NULL);
41 db_tracker_->AddObserver(this); 43 db_tracker_->AddObserver(this);
42 db_thread_.Start(); 44 db_thread_.Start();
43 db_thread_proxy_ = db_thread_.message_loop_proxy(); 45 db_thread_proxy_ = db_thread_.message_loop_proxy();
44 } 46 }
45 47
46 SimpleDatabaseSystem::~SimpleDatabaseSystem() { 48 SimpleDatabaseSystem::~SimpleDatabaseSystem() {
47 base::WaitableEvent done_event(false, false); 49 base::WaitableEvent done_event(false, false);
48 db_thread_proxy_->PostTask(FROM_HERE, 50 db_thread_proxy_->PostTask(
49 NewRunnableMethod(this, &SimpleDatabaseSystem::ThreadCleanup, 51 FROM_HERE,
50 &done_event)); 52 base::Bind(&SimpleDatabaseSystem::ThreadCleanup,
53 base::Unretained(this), &done_event));
51 done_event.Wait(); 54 done_event.Wait();
52 instance_ = NULL; 55 instance_ = NULL;
53 } 56 }
54 57
55 void SimpleDatabaseSystem::databaseOpened(const WebKit::WebDatabase& database) { 58 void SimpleDatabaseSystem::databaseOpened(const WebKit::WebDatabase& database) {
56 string16 origin_identifier = database.securityOrigin().databaseIdentifier(); 59 string16 origin_identifier = database.securityOrigin().databaseIdentifier();
57 string16 database_name = database.name(); 60 string16 database_name = database.name();
58 open_connections_->AddOpenConnection(origin_identifier, database_name); 61 open_connections_->AddOpenConnection(origin_identifier, database_name);
59 db_thread_proxy_->PostTask(FROM_HERE, 62 db_thread_proxy_->PostTask(
60 NewRunnableMethod(this, &SimpleDatabaseSystem::DatabaseOpened, 63 FROM_HERE,
61 origin_identifier, 64 base::Bind(&SimpleDatabaseSystem::DatabaseOpened,
62 database_name, database.displayName(), 65 base::Unretained(this),
63 database.estimatedSize())); 66 origin_identifier,
67 database_name, database.displayName(),
68 database.estimatedSize()));
64 } 69 }
65 70
66 void SimpleDatabaseSystem::databaseModified( 71 void SimpleDatabaseSystem::databaseModified(
67 const WebKit::WebDatabase& database) { 72 const WebKit::WebDatabase& database) {
68 db_thread_proxy_->PostTask(FROM_HERE, 73 db_thread_proxy_->PostTask(
69 NewRunnableMethod(this, &SimpleDatabaseSystem::DatabaseModified, 74 FROM_HERE,
70 database.securityOrigin().databaseIdentifier(), 75 base::Bind(&SimpleDatabaseSystem::DatabaseModified,
71 database.name())); 76 base::Unretained(this),
77 database.securityOrigin().databaseIdentifier(),
78 database.name()));
72 } 79 }
73 80
74 void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) { 81 void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) {
75 string16 origin_identifier = database.securityOrigin().databaseIdentifier(); 82 string16 origin_identifier = database.securityOrigin().databaseIdentifier();
76 string16 database_name = database.name(); 83 string16 database_name = database.name();
77 db_thread_proxy_->PostTask(FROM_HERE, 84 db_thread_proxy_->PostTask(
78 NewRunnableMethod(this, &SimpleDatabaseSystem::DatabaseClosed, 85 FROM_HERE,
79 origin_identifier, database_name)); 86 base::Bind(&SimpleDatabaseSystem::DatabaseClosed,
87 base::Unretained(this), origin_identifier, database_name));
80 } 88 }
81 89
82 base::PlatformFile SimpleDatabaseSystem::OpenFile( 90 base::PlatformFile SimpleDatabaseSystem::OpenFile(
83 const string16& vfs_file_name, int desired_flags) { 91 const string16& vfs_file_name, int desired_flags) {
84 base::PlatformFile result = base::kInvalidPlatformFileValue; 92 base::PlatformFile result = base::kInvalidPlatformFileValue;
85 base::WaitableEvent done_event(false, false); 93 base::WaitableEvent done_event(false, false);
86 db_thread_proxy_->PostTask(FROM_HERE, 94 db_thread_proxy_->PostTask(
87 NewRunnableMethod(this, &SimpleDatabaseSystem::VfsOpenFile, 95 FROM_HERE,
88 vfs_file_name, desired_flags, 96 base::Bind(&SimpleDatabaseSystem::VfsOpenFile,
89 &result, &done_event)); 97 base::Unretained(this),
98 vfs_file_name, desired_flags,
99 &result, &done_event));
90 done_event.Wait(); 100 done_event.Wait();
91 return result; 101 return result;
92 } 102 }
93 103
94 int SimpleDatabaseSystem::DeleteFile( 104 int SimpleDatabaseSystem::DeleteFile(
95 const string16& vfs_file_name, bool sync_dir) { 105 const string16& vfs_file_name, bool sync_dir) {
96 int result = SQLITE_OK; 106 int result = SQLITE_OK;
97 base::WaitableEvent done_event(false, false); 107 base::WaitableEvent done_event(false, false);
98 db_thread_proxy_->PostTask(FROM_HERE, 108 db_thread_proxy_->PostTask(
99 NewRunnableMethod(this, &SimpleDatabaseSystem::VfsDeleteFile, 109 FROM_HERE,
100 vfs_file_name, sync_dir, 110 base::Bind(&SimpleDatabaseSystem::VfsDeleteFile,
101 &result, &done_event)); 111 base::Unretained(this),
112 vfs_file_name, sync_dir,
113 &result, &done_event));
102 done_event.Wait(); 114 done_event.Wait();
103 return result; 115 return result;
104 } 116 }
105 117
106 uint32 SimpleDatabaseSystem::GetFileAttributes(const string16& vfs_file_name) { 118 uint32 SimpleDatabaseSystem::GetFileAttributes(const string16& vfs_file_name) {
107 uint32 result = 0; 119 uint32 result = 0;
108 base::WaitableEvent done_event(false, false); 120 base::WaitableEvent done_event(false, false);
109 db_thread_proxy_->PostTask(FROM_HERE, 121 db_thread_proxy_->PostTask(
110 NewRunnableMethod(this, &SimpleDatabaseSystem::VfsGetFileAttributes, 122 FROM_HERE,
111 vfs_file_name, &result, &done_event)); 123 base::Bind(&SimpleDatabaseSystem::VfsGetFileAttributes,
124 base::Unretained(this), vfs_file_name, &result, &done_event));
112 done_event.Wait(); 125 done_event.Wait();
113 return result; 126 return result;
114 } 127 }
115 128
116 int64 SimpleDatabaseSystem::GetFileSize(const string16& vfs_file_name) { 129 int64 SimpleDatabaseSystem::GetFileSize(const string16& vfs_file_name) {
117 int64 result = 0; 130 int64 result = 0;
118 base::WaitableEvent done_event(false, false); 131 base::WaitableEvent done_event(false, false);
119 db_thread_proxy_->PostTask(FROM_HERE, 132 db_thread_proxy_->PostTask(
120 NewRunnableMethod(this, &SimpleDatabaseSystem::VfsGetFileSize, 133 FROM_HERE,
121 vfs_file_name, &result, &done_event)); 134 base::Bind(&SimpleDatabaseSystem::VfsGetFileSize,
135 base::Unretained(this), vfs_file_name, &result, &done_event));
122 done_event.Wait(); 136 done_event.Wait();
123 return result; 137 return result;
124 } 138 }
125 139
126 int64 SimpleDatabaseSystem::GetSpaceAvailable( 140 int64 SimpleDatabaseSystem::GetSpaceAvailable(
127 const string16& origin_identifier) { 141 const string16& origin_identifier) {
128 int64 result = 0; 142 int64 result = 0;
129 base::WaitableEvent done_event(false, false); 143 base::WaitableEvent done_event(false, false);
130 db_thread_proxy_->PostTask(FROM_HERE, 144 db_thread_proxy_->PostTask(
131 NewRunnableMethod(this, &SimpleDatabaseSystem::VfsGetSpaceAvailable, 145 FROM_HERE,
132 origin_identifier, &result, &done_event)); 146 base::Bind(&SimpleDatabaseSystem::VfsGetSpaceAvailable,
147 base::Unretained(this), origin_identifier,
148 &result, &done_event));
133 done_event.Wait(); 149 done_event.Wait();
134 return result; 150 return result;
135 } 151 }
136 152
137 void SimpleDatabaseSystem::ClearAllDatabases() { 153 void SimpleDatabaseSystem::ClearAllDatabases() {
138 open_connections_->WaitForAllDatabasesToClose(); 154 open_connections_->WaitForAllDatabasesToClose();
139 db_thread_proxy_->PostTask(FROM_HERE, 155 db_thread_proxy_->PostTask(
140 NewRunnableMethod(this, &SimpleDatabaseSystem::ResetTracker)); 156 FROM_HERE,
157 base::Bind(&SimpleDatabaseSystem::ResetTracker, base::Unretained(this)));
141 } 158 }
142 159
143 void SimpleDatabaseSystem::SetDatabaseQuota(int64 quota) { 160 void SimpleDatabaseSystem::SetDatabaseQuota(int64 quota) {
144 if (!db_thread_proxy_->BelongsToCurrentThread()) { 161 if (!db_thread_proxy_->BelongsToCurrentThread()) {
145 db_thread_proxy_->PostTask(FROM_HERE, 162 db_thread_proxy_->PostTask(
146 NewRunnableMethod(this, &SimpleDatabaseSystem::SetDatabaseQuota, 163 FROM_HERE,
147 quota)); 164 base::Bind(&SimpleDatabaseSystem::SetDatabaseQuota,
165 base::Unretained(this), quota));
148 return; 166 return;
149 } 167 }
150 quota_per_origin_ = quota; 168 quota_per_origin_ = quota;
151 } 169 }
152 170
153 void SimpleDatabaseSystem::DatabaseOpened(const string16& origin_identifier, 171 void SimpleDatabaseSystem::DatabaseOpened(const string16& origin_identifier,
154 const string16& database_name, 172 const string16& database_name,
155 const string16& description, 173 const string16& description,
156 int64 estimated_size) { 174 int64 estimated_size) {
157 DCHECK(db_thread_proxy_->BelongsToCurrentThread()); 175 DCHECK(db_thread_proxy_->BelongsToCurrentThread());
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 file_util::Delete(db_tracker_->DatabaseDirectory(), true); 300 file_util::Delete(db_tracker_->DatabaseDirectory(), true);
283 } 301 }
284 302
285 void SimpleDatabaseSystem::ThreadCleanup(base::WaitableEvent* done_event) { 303 void SimpleDatabaseSystem::ThreadCleanup(base::WaitableEvent* done_event) {
286 ResetTracker(); 304 ResetTracker();
287 db_tracker_->RemoveObserver(this); 305 db_tracker_->RemoveObserver(this);
288 db_tracker_ = NULL; 306 db_tracker_ = NULL;
289 done_event->Signal(); 307 done_event->Signal();
290 } 308 }
291 309
OLDNEW
« no previous file with comments | « webkit/support/simple_database_system.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698