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

Side by Side Diff: third_party/WebKit/Source/modules/webdatabase/DatabaseTracker.cpp

Issue 2099093002: Remove an ExecutionContextTask subclass in DatabaseTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ECT_TaskName
Patch Set: Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/Source/modules/webdatabase/DatabaseTracker.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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "modules/webdatabase/DatabaseTracker.h" 31 #include "modules/webdatabase/DatabaseTracker.h"
32 32
33 #include "core/dom/CrossThreadTask.h"
33 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
34 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
35 #include "core/dom/ExecutionContextTask.h" 36 #include "core/dom/ExecutionContextTask.h"
36 #include "modules/webdatabase/Database.h" 37 #include "modules/webdatabase/Database.h"
37 #include "modules/webdatabase/DatabaseClient.h" 38 #include "modules/webdatabase/DatabaseClient.h"
38 #include "modules/webdatabase/DatabaseContext.h" 39 #include "modules/webdatabase/DatabaseContext.h"
39 #include "modules/webdatabase/QuotaTracker.h" 40 #include "modules/webdatabase/QuotaTracker.h"
40 #include "modules/webdatabase/sqlite/SQLiteFileSystem.h" 41 #include "modules/webdatabase/sqlite/SQLiteFileSystem.h"
41 #include "platform/weborigin/SecurityOrigin.h" 42 #include "platform/weborigin/SecurityOrigin.h"
42 #include "platform/weborigin/SecurityOriginHash.h" 43 #include "platform/weborigin/SecurityOriginHash.h"
43 #include "public/platform/Platform.h" 44 #include "public/platform/Platform.h"
44 #include "public/platform/WebDatabaseObserver.h" 45 #include "public/platform/WebDatabaseObserver.h"
45 #include "public/platform/WebSecurityOrigin.h" 46 #include "public/platform/WebSecurityOrigin.h"
46 #include "public/platform/WebTraceLocation.h" 47 #include "public/platform/WebTraceLocation.h"
47 #include "wtf/Assertions.h" 48 #include "wtf/Assertions.h"
49 #include "wtf/Functional.h"
48 #include "wtf/PtrUtil.h" 50 #include "wtf/PtrUtil.h"
49 #include "wtf/StdLibExtras.h" 51 #include "wtf/StdLibExtras.h"
50 52
51 namespace blink { 53 namespace blink {
52 54
53 static void databaseClosed(Database* database) 55 static void databaseClosed(Database* database)
54 { 56 {
55 if (Platform::current()->databaseObserver()) { 57 if (Platform::current()->databaseObserver()) {
56 Platform::current()->databaseObserver()->databaseClosed( 58 Platform::current()->databaseObserver()->databaseClosed(
57 WebSecurityOrigin(database->getSecurityOrigin()), 59 WebSecurityOrigin(database->getSecurityOrigin()),
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 unsigned long long DatabaseTracker::getMaxSizeForDatabase(const Database* databa se) 161 unsigned long long DatabaseTracker::getMaxSizeForDatabase(const Database* databa se)
160 { 162 {
161 unsigned long long spaceAvailable = 0; 163 unsigned long long spaceAvailable = 0;
162 unsigned long long databaseSize = 0; 164 unsigned long long databaseSize = 0;
163 QuotaTracker::instance().getDatabaseSizeAndSpaceAvailableToOrigin( 165 QuotaTracker::instance().getDatabaseSizeAndSpaceAvailableToOrigin(
164 database->getSecurityOrigin(), 166 database->getSecurityOrigin(),
165 database->stringIdentifier(), &databaseSize, &spaceAvailable); 167 database->stringIdentifier(), &databaseSize, &spaceAvailable);
166 return databaseSize + spaceAvailable; 168 return databaseSize + spaceAvailable;
167 } 169 }
168 170
169 class DatabaseTracker::CloseOneDatabaseImmediatelyTask final : public ExecutionC ontextTask {
170 public:
171 static std::unique_ptr<CloseOneDatabaseImmediatelyTask> create(const String& originString, const String& name, Database* database)
172 {
173 return wrapUnique(new CloseOneDatabaseImmediatelyTask(originString, name , database));
174 }
175
176 void performTask(ExecutionContext*) override
177 {
178 DatabaseTracker::tracker().closeOneDatabaseImmediately(m_originString, m _name, m_database);
179 }
180
181 private:
182 CloseOneDatabaseImmediatelyTask(const String& originString, const String& na me, Database* database)
183 : m_originString(originString.isolatedCopy())
184 , m_name(name.isolatedCopy())
185 , m_database(database)
186 {
187 }
188
189 String m_originString;
190 String m_name;
191 CrossThreadPersistent<Database> m_database;
192 };
193
194 void DatabaseTracker::closeDatabasesImmediately(SecurityOrigin* origin, const St ring& name) 171 void DatabaseTracker::closeDatabasesImmediately(SecurityOrigin* origin, const St ring& name)
195 { 172 {
196 String originString = origin->toRawString(); 173 String originString = origin->toRawString();
197 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); 174 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard);
198 if (!m_openDatabaseMap) 175 if (!m_openDatabaseMap)
199 return; 176 return;
200 177
201 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originString); 178 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originString);
202 if (!nameMap) 179 if (!nameMap)
203 return; 180 return;
204 181
205 DatabaseSet* databaseSet = nameMap->get(name); 182 DatabaseSet* databaseSet = nameMap->get(name);
206 if (!databaseSet) 183 if (!databaseSet)
207 return; 184 return;
208 185
209 // We have to call closeImmediately() on the context thread. 186 // We have to call closeImmediately() on the context thread.
210 for (DatabaseSet::iterator it = databaseSet->begin(); it != databaseSet->end (); ++it) 187 for (DatabaseSet::iterator it = databaseSet->begin(); it != databaseSet->end (); ++it)
211 (*it)->getDatabaseContext()->getExecutionContext()->postTask(BLINK_FROM_ HERE, CloseOneDatabaseImmediatelyTask::create(originString, name, *it)); 188 (*it)->getDatabaseContext()->getExecutionContext()->postTask(BLINK_FROM_ HERE, createCrossThreadTask(&DatabaseTracker::closeOneDatabaseImmediately, cross ThreadUnretained(this), originString, name, *it));
hiroshige 2016/06/26 10:51:02 This CL passes |this| across thread, instead of ca
haraken 2016/06/27 01:13:52 Why don't you use wrapCrossThreadPersistent?
hiroshige 2016/06/27 07:20:06 Because DatabaseTracker is not GCed type.
212 } 189 }
213 190
214 void DatabaseTracker::forEachOpenDatabaseInPage(Page* page, std::unique_ptr<Data baseCallback> callback) 191 void DatabaseTracker::forEachOpenDatabaseInPage(Page* page, std::unique_ptr<Data baseCallback> callback)
215 { 192 {
216 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); 193 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard);
217 if (!m_openDatabaseMap) 194 if (!m_openDatabaseMap)
218 return; 195 return;
219 for (auto& originMap : *m_openDatabaseMap) { 196 for (auto& originMap : *m_openDatabaseMap) {
220 for (auto& nameDatabaseSet : *originMap.value) { 197 for (auto& nameDatabaseSet : *originMap.value) {
221 for (Database* database : *nameDatabaseSet.value) { 198 for (Database* database : *nameDatabaseSet.value) {
(...skipping 25 matching lines...) Expand all
247 DatabaseSet::iterator found = databaseSet->find(database); 224 DatabaseSet::iterator found = databaseSet->find(database);
248 if (found == databaseSet->end()) 225 if (found == databaseSet->end())
249 return; 226 return;
250 } 227 }
251 228
252 // And we have to call closeImmediately() without our collection lock being held. 229 // And we have to call closeImmediately() without our collection lock being held.
253 database->closeImmediately(); 230 database->closeImmediately();
254 } 231 }
255 232
256 } // namespace blink 233 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webdatabase/DatabaseTracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698