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

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

Issue 1779413002: Remove Blink's DatabaseIdentifier implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unneeded include Created 4 years, 9 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
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 19 matching lines...) Expand all
30 30
31 #include "modules/webdatabase/DatabaseTracker.h" 31 #include "modules/webdatabase/DatabaseTracker.h"
32 32
33 #include "core/dom/ExecutionContext.h" 33 #include "core/dom/ExecutionContext.h"
34 #include "core/dom/ExecutionContextTask.h" 34 #include "core/dom/ExecutionContextTask.h"
35 #include "modules/webdatabase/Database.h" 35 #include "modules/webdatabase/Database.h"
36 #include "modules/webdatabase/DatabaseClient.h" 36 #include "modules/webdatabase/DatabaseClient.h"
37 #include "modules/webdatabase/DatabaseContext.h" 37 #include "modules/webdatabase/DatabaseContext.h"
38 #include "modules/webdatabase/QuotaTracker.h" 38 #include "modules/webdatabase/QuotaTracker.h"
39 #include "modules/webdatabase/sqlite/SQLiteFileSystem.h" 39 #include "modules/webdatabase/sqlite/SQLiteFileSystem.h"
40 #include "platform/weborigin/DatabaseIdentifier.h"
41 #include "platform/weborigin/SecurityOrigin.h" 40 #include "platform/weborigin/SecurityOrigin.h"
42 #include "platform/weborigin/SecurityOriginHash.h" 41 #include "platform/weborigin/SecurityOriginHash.h"
43 #include "public/platform/Platform.h" 42 #include "public/platform/Platform.h"
44 #include "public/platform/WebDatabaseObserver.h" 43 #include "public/platform/WebDatabaseObserver.h"
44 #include "public/platform/WebSecurityOrigin.h"
45 #include "public/platform/WebTraceLocation.h" 45 #include "public/platform/WebTraceLocation.h"
46 #include "wtf/Assertions.h" 46 #include "wtf/Assertions.h"
47 #include "wtf/StdLibExtras.h" 47 #include "wtf/StdLibExtras.h"
48 48
49 namespace blink { 49 namespace blink {
50 50
51 static void databaseClosed(Database* database) 51 static void databaseClosed(Database* database)
52 { 52 {
53 if (Platform::current()->databaseObserver()) { 53 if (Platform::current()->databaseObserver()) {
54 Platform::current()->databaseObserver()->databaseClosed( 54 Platform::current()->databaseObserver()->databaseClosed(
55 createDatabaseIdentifierFromSecurityOrigin(database->getSecurityOrig in()), 55 WebSecurityOrigin(database->getSecurityOrigin()),
56 database->stringIdentifier()); 56 database->stringIdentifier());
57 } 57 }
58 } 58 }
59 59
60 DatabaseTracker& DatabaseTracker::tracker() 60 DatabaseTracker& DatabaseTracker::tracker()
61 { 61 {
62 DEFINE_THREAD_SAFE_STATIC_LOCAL(DatabaseTracker, tracker, new DatabaseTracke r); 62 DEFINE_THREAD_SAFE_STATIC_LOCAL(DatabaseTracker, tracker, new DatabaseTracke r);
63 return tracker; 63 return tracker;
64 } 64 }
65 65
66 DatabaseTracker::DatabaseTracker() 66 DatabaseTracker::DatabaseTracker()
67 { 67 {
68 SQLiteFileSystem::registerSQLiteVFS(); 68 SQLiteFileSystem::registerSQLiteVFS();
69 } 69 }
70 70
71 bool DatabaseTracker::canEstablishDatabase(DatabaseContext* databaseContext, con st String& name, const String& displayName, unsigned long estimatedSize, Databas eError& error) 71 bool DatabaseTracker::canEstablishDatabase(DatabaseContext* databaseContext, con st String& name, const String& displayName, unsigned long estimatedSize, Databas eError& error)
72 { 72 {
73 ExecutionContext* executionContext = databaseContext->getExecutionContext(); 73 ExecutionContext* executionContext = databaseContext->getExecutionContext();
74 bool success = DatabaseClient::from(executionContext)->allowDatabase(executi onContext, name, displayName, estimatedSize); 74 bool success = DatabaseClient::from(executionContext)->allowDatabase(executi onContext, name, displayName, estimatedSize);
75 if (!success) 75 if (!success)
76 error = DatabaseError::GenericSecurityError; 76 error = DatabaseError::GenericSecurityError;
77 return success; 77 return success;
78 } 78 }
79 79
80 String DatabaseTracker::fullPathForDatabase(SecurityOrigin* origin, const String & name, bool) 80 String DatabaseTracker::fullPathForDatabase(SecurityOrigin* origin, const String & name, bool)
81 { 81 {
82 return createDatabaseIdentifierFromSecurityOrigin(origin) + "/" + name + "#" ; 82 return String(Platform::current()->databaseCreateOriginIdentifier(WebSecurit yOrigin(origin))) + "/" + name + "#";
83 } 83 }
84 84
85 void DatabaseTracker::addOpenDatabase(Database* database) 85 void DatabaseTracker::addOpenDatabase(Database* database)
86 { 86 {
87 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); 87 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard);
88 if (!m_openDatabaseMap) 88 if (!m_openDatabaseMap)
89 m_openDatabaseMap = adoptPtr(new DatabaseOriginMap); 89 m_openDatabaseMap = adoptPtr(new DatabaseOriginMap);
90 90
91 String originIdentifier = createDatabaseIdentifierFromSecurityOrigin(databas e->getSecurityOrigin()); 91 String originString = database->getSecurityOrigin()->toString();
92 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier); 92 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originString);
93 if (!nameMap) { 93 if (!nameMap) {
94 nameMap = new DatabaseNameMap(); 94 nameMap = new DatabaseNameMap();
95 m_openDatabaseMap->set(originIdentifier, nameMap); 95 m_openDatabaseMap->set(originString, nameMap);
96 } 96 }
97 97
98 String name(database->stringIdentifier()); 98 String name(database->stringIdentifier());
99 DatabaseSet* databaseSet = nameMap->get(name); 99 DatabaseSet* databaseSet = nameMap->get(name);
100 if (!databaseSet) { 100 if (!databaseSet) {
101 databaseSet = new DatabaseSet(); 101 databaseSet = new DatabaseSet();
102 nameMap->set(name, databaseSet); 102 nameMap->set(name, databaseSet);
103 } 103 }
104 104
105 databaseSet->add(database); 105 databaseSet->add(database);
106 } 106 }
107 107
108 void DatabaseTracker::removeOpenDatabase(Database* database) 108 void DatabaseTracker::removeOpenDatabase(Database* database)
109 { 109 {
110 { 110 {
111 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); 111 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard);
112 String originIdentifier = createDatabaseIdentifierFromSecurityOrigin(dat abase->getSecurityOrigin()); 112 String originString = database->getSecurityOrigin()->toString();
113 ASSERT(m_openDatabaseMap); 113 ASSERT(m_openDatabaseMap);
114 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier); 114 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originString);
115 if (!nameMap) 115 if (!nameMap)
116 return; 116 return;
117 117
118 String name(database->stringIdentifier()); 118 String name(database->stringIdentifier());
119 DatabaseSet* databaseSet = nameMap->get(name); 119 DatabaseSet* databaseSet = nameMap->get(name);
120 if (!databaseSet) 120 if (!databaseSet)
121 return; 121 return;
122 122
123 DatabaseSet::iterator found = databaseSet->find(database); 123 DatabaseSet::iterator found = databaseSet->find(database);
124 if (found == databaseSet->end()) 124 if (found == databaseSet->end())
125 return; 125 return;
126 126
127 databaseSet->remove(found); 127 databaseSet->remove(found);
128 if (databaseSet->isEmpty()) { 128 if (databaseSet->isEmpty()) {
129 nameMap->remove(name); 129 nameMap->remove(name);
130 delete databaseSet; 130 delete databaseSet;
131 if (nameMap->isEmpty()) { 131 if (nameMap->isEmpty()) {
132 m_openDatabaseMap->remove(originIdentifier); 132 m_openDatabaseMap->remove(originString);
133 delete nameMap; 133 delete nameMap;
134 } 134 }
135 } 135 }
136 } 136 }
137 databaseClosed(database); 137 databaseClosed(database);
138 } 138 }
139 139
140 void DatabaseTracker::prepareToOpenDatabase(Database* database) 140 void DatabaseTracker::prepareToOpenDatabase(Database* database)
141 { 141 {
142 ASSERT(database->getDatabaseContext()->getExecutionContext()->isContextThrea d()); 142 ASSERT(database->getDatabaseContext()->getExecutionContext()->isContextThrea d());
143 if (Platform::current()->databaseObserver()) { 143 if (Platform::current()->databaseObserver()) {
144 Platform::current()->databaseObserver()->databaseOpened( 144 Platform::current()->databaseObserver()->databaseOpened(
145 createDatabaseIdentifierFromSecurityOrigin(database->getSecurityOrig in()), 145 WebSecurityOrigin(database->getSecurityOrigin()),
146 database->stringIdentifier(), 146 database->stringIdentifier(),
147 database->displayName(), 147 database->displayName(),
148 database->estimatedSize()); 148 database->estimatedSize());
149 } 149 }
150 } 150 }
151 151
152 void DatabaseTracker::failedToOpenDatabase(Database* database) 152 void DatabaseTracker::failedToOpenDatabase(Database* database)
153 { 153 {
154 databaseClosed(database); 154 databaseClosed(database);
155 } 155 }
156 156
157 unsigned long long DatabaseTracker::getMaxSizeForDatabase(const Database* databa se) 157 unsigned long long DatabaseTracker::getMaxSizeForDatabase(const Database* databa se)
158 { 158 {
159 unsigned long long spaceAvailable = 0; 159 unsigned long long spaceAvailable = 0;
160 unsigned long long databaseSize = 0; 160 unsigned long long databaseSize = 0;
161 QuotaTracker::instance().getDatabaseSizeAndSpaceAvailableToOrigin( 161 QuotaTracker::instance().getDatabaseSizeAndSpaceAvailableToOrigin(
162 createDatabaseIdentifierFromSecurityOrigin(database->getSecurityOrigin() ), 162 database->getSecurityOrigin(),
163 database->stringIdentifier(), &databaseSize, &spaceAvailable); 163 database->stringIdentifier(), &databaseSize, &spaceAvailable);
164 return databaseSize + spaceAvailable; 164 return databaseSize + spaceAvailable;
165 } 165 }
166 166
167 class DatabaseTracker::CloseOneDatabaseImmediatelyTask final : public ExecutionC ontextTask { 167 class DatabaseTracker::CloseOneDatabaseImmediatelyTask final : public ExecutionC ontextTask {
168 public: 168 public:
169 static PassOwnPtr<CloseOneDatabaseImmediatelyTask> create(const String& orig inIdentifier, const String& name, Database* database) 169 static PassOwnPtr<CloseOneDatabaseImmediatelyTask> create(const String& orig inString, const String& name, Database* database)
170 { 170 {
171 return adoptPtr(new CloseOneDatabaseImmediatelyTask(originIdentifier, na me, database)); 171 return adoptPtr(new CloseOneDatabaseImmediatelyTask(originString, name, database));
172 } 172 }
173 173
174 void performTask(ExecutionContext*) override 174 void performTask(ExecutionContext*) override
175 { 175 {
176 DatabaseTracker::tracker().closeOneDatabaseImmediately(m_originIdentifie r, m_name, m_database); 176 DatabaseTracker::tracker().closeOneDatabaseImmediately(m_originString, m _name, m_database);
177 } 177 }
178 178
179 private: 179 private:
180 CloseOneDatabaseImmediatelyTask(const String& originIdentifier, const String & name, Database* database) 180 CloseOneDatabaseImmediatelyTask(const String& originString, const String& na me, Database* database)
181 : m_originIdentifier(originIdentifier.isolatedCopy()) 181 : m_originString(originString.isolatedCopy())
182 , m_name(name.isolatedCopy()) 182 , m_name(name.isolatedCopy())
183 , m_database(database) 183 , m_database(database)
184 { 184 {
185 } 185 }
186 186
187 String m_originIdentifier; 187 String m_originString;
188 String m_name; 188 String m_name;
189 CrossThreadPersistent<Database> m_database; 189 CrossThreadPersistent<Database> m_database;
190 }; 190 };
191 191
192 void DatabaseTracker::closeDatabasesImmediately(const String& originIdentifier, const String& name) 192 void DatabaseTracker::closeDatabasesImmediately(SecurityOrigin* origin, const St ring& name)
193 { 193 {
194 String originString = origin->toString();
194 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); 195 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard);
195 if (!m_openDatabaseMap) 196 if (!m_openDatabaseMap)
196 return; 197 return;
197 198
198 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier); 199 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originString);
199 if (!nameMap) 200 if (!nameMap)
200 return; 201 return;
201 202
202 DatabaseSet* databaseSet = nameMap->get(name); 203 DatabaseSet* databaseSet = nameMap->get(name);
203 if (!databaseSet) 204 if (!databaseSet)
204 return; 205 return;
205 206
206 // We have to call closeImmediately() on the context thread. 207 // We have to call closeImmediately() on the context thread.
207 for (DatabaseSet::iterator it = databaseSet->begin(); it != databaseSet->end (); ++it) 208 for (DatabaseSet::iterator it = databaseSet->begin(); it != databaseSet->end (); ++it)
208 (*it)->getDatabaseContext()->getExecutionContext()->postTask(BLINK_FROM_ HERE, CloseOneDatabaseImmediatelyTask::create(originIdentifier, name, *it)); 209 (*it)->getDatabaseContext()->getExecutionContext()->postTask(BLINK_FROM_ HERE, CloseOneDatabaseImmediatelyTask::create(originString, name, *it));
209 } 210 }
210 211
211 void DatabaseTracker::closeOneDatabaseImmediately(const String& originIdentifier , const String& name, Database* database) 212 void DatabaseTracker::closeOneDatabaseImmediately(const String& originString, co nst String& name, Database* database)
212 { 213 {
213 // First we have to confirm the 'database' is still in our collection. 214 // First we have to confirm the 'database' is still in our collection.
214 { 215 {
215 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); 216 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard);
216 if (!m_openDatabaseMap) 217 if (!m_openDatabaseMap)
217 return; 218 return;
218 219
219 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier); 220 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originString);
220 if (!nameMap) 221 if (!nameMap)
221 return; 222 return;
222 223
223 DatabaseSet* databaseSet = nameMap->get(name); 224 DatabaseSet* databaseSet = nameMap->get(name);
224 if (!databaseSet) 225 if (!databaseSet)
225 return; 226 return;
226 227
227 DatabaseSet::iterator found = databaseSet->find(database); 228 DatabaseSet::iterator found = databaseSet->find(database);
228 if (found == databaseSet->end()) 229 if (found == databaseSet->end())
229 return; 230 return;
230 } 231 }
231 232
232 // And we have to call closeImmediately() without our collection lock being held. 233 // And we have to call closeImmediately() without our collection lock being held.
233 database->closeImmediately(); 234 database->closeImmediately();
234 } 235 }
235 236
236 } // namespace blink 237 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698