OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/indexed_db/indexed_db_context_impl.h" | 5 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "content/browser/indexed_db/indexed_db_quota_client.h" | 16 #include "content/browser/indexed_db/indexed_db_quota_client.h" |
17 #include "content/browser/indexed_db/webidbfactory_impl.h" | |
18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/indexed_db_info.h" | 18 #include "content/public/browser/indexed_db_info.h" |
20 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" |
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBDatabase.h" | 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBDatabase.h" |
23 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBFactory.h" | 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBFactory.h" |
24 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
25 #include "webkit/base/file_path_string_conversions.h" | 24 #include "webkit/base/file_path_string_conversions.h" |
26 #include "webkit/base/origin_url_conversions.h" | 25 #include "webkit/base/origin_url_conversions.h" |
27 #include "webkit/browser/database/database_util.h" | 26 #include "webkit/browser/database/database_util.h" |
28 #include "webkit/quota/quota_manager.h" | 27 #include "webkit/quota/quota_manager.h" |
29 #include "webkit/quota/special_storage_policy.h" | 28 #include "webkit/quota/special_storage_policy.h" |
30 | 29 |
31 using webkit_database::DatabaseUtil; | 30 using webkit_database::DatabaseUtil; |
32 using WebKit::WebIDBDatabase; | 31 using WebKit::WebIDBDatabase; |
33 using WebKit::WebIDBFactory; | 32 using WebKit::WebIDBFactory; |
34 | 33 |
35 namespace content { | 34 namespace content { |
36 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = | 35 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = |
37 FILE_PATH_LITERAL("IndexedDB"); | 36 FILE_PATH_LITERAL("IndexedDB"); |
38 | 37 |
39 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] = | 38 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] = |
40 FILE_PATH_LITERAL(".leveldb"); | 39 FILE_PATH_LITERAL(".leveldb"); |
41 | 40 |
42 namespace { | 41 namespace { |
43 | 42 |
44 void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path, | 43 void GetAllOriginsAndPaths( |
45 std::vector<GURL>* origins, | 44 const base::FilePath& indexeddb_path, |
46 std::vector<base::FilePath>* file_paths) { | 45 std::vector<GURL>* origins, |
| 46 std::vector<base::FilePath>* file_paths) { |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
48 if (indexeddb_path.empty()) | 48 if (indexeddb_path.empty()) |
49 return; | 49 return; |
50 file_util::FileEnumerator file_enumerator( | 50 file_util::FileEnumerator file_enumerator(indexeddb_path, |
51 indexeddb_path, false, file_util::FileEnumerator::DIRECTORIES); | 51 false, file_util::FileEnumerator::DIRECTORIES); |
52 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 52 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
53 file_path = file_enumerator.Next()) { | 53 file_path = file_enumerator.Next()) { |
54 if (file_path.Extension() == IndexedDBContextImpl::kIndexedDBExtension) { | 54 if (file_path.Extension() == IndexedDBContextImpl::kIndexedDBExtension) { |
55 WebKit::WebString origin_id_webstring = | 55 WebKit::WebString origin_id_webstring = |
56 webkit_base::FilePathToWebString(file_path.BaseName()); | 56 webkit_base::FilePathToWebString(file_path.BaseName()); |
57 origins->push_back( | 57 origins->push_back( |
58 webkit_base::GetOriginURLFromIdentifier(origin_id_webstring)); | 58 webkit_base::GetOriginURLFromIdentifier(origin_id_webstring)); |
59 if (file_paths) | 59 if (file_paths) |
60 file_paths->push_back(file_path); | 60 file_paths->push_back(file_path); |
61 } | 61 } |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 // Deletes session-only databases. | 65 // Deletes session-only databases. |
66 void ClearSessionOnlyOrigins( | 66 void ClearSessionOnlyOrigins( |
67 const base::FilePath& indexeddb_path, | 67 const base::FilePath& indexeddb_path, |
68 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { | 68 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
70 std::vector<GURL> origins; | 70 std::vector<GURL> origins; |
71 std::vector<base::FilePath> file_paths; | 71 std::vector<base::FilePath> file_paths; |
72 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); | 72 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); |
73 DCHECK_EQ(origins.size(), file_paths.size()); | 73 DCHECK_EQ(origins.size(), file_paths.size()); |
74 std::vector<base::FilePath>::const_iterator file_path_iter = | 74 std::vector<base::FilePath>::const_iterator file_path_iter = |
75 file_paths.begin(); | 75 file_paths.begin(); |
76 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 76 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
77 iter != origins.end(); | 77 iter != origins.end(); ++iter, ++file_path_iter) { |
78 ++iter, ++file_path_iter) { | |
79 if (!special_storage_policy->IsStorageSessionOnly(*iter)) | 78 if (!special_storage_policy->IsStorageSessionOnly(*iter)) |
80 continue; | 79 continue; |
81 if (special_storage_policy->IsStorageProtected(*iter)) | 80 if (special_storage_policy->IsStorageProtected(*iter)) |
82 continue; | 81 continue; |
83 file_util::Delete(*file_path_iter, true); | 82 file_util::Delete(*file_path_iter, true); |
84 } | 83 } |
85 } | 84 } |
86 | 85 |
87 } // namespace | 86 } // namespace |
88 | 87 |
(...skipping 13 matching lines...) Expand all Loading... |
102 new IndexedDBQuotaClient(webkit_thread_loop, this)); | 101 new IndexedDBQuotaClient(webkit_thread_loop, this)); |
103 } | 102 } |
104 } | 103 } |
105 | 104 |
106 WebIDBFactory* IndexedDBContextImpl::GetIDBFactory() { | 105 WebIDBFactory* IndexedDBContextImpl::GetIDBFactory() { |
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
108 if (!idb_factory_) { | 107 if (!idb_factory_) { |
109 // Prime our cache of origins with existing databases so we can | 108 // Prime our cache of origins with existing databases so we can |
110 // detect when dbs are newly created. | 109 // detect when dbs are newly created. |
111 GetOriginSet(); | 110 GetOriginSet(); |
112 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewIndexedDB)) | 111 idb_factory_.reset(WebIDBFactory::create()); |
113 idb_factory_.reset(new content::WebIDBFactoryImpl()); | |
114 else | |
115 idb_factory_.reset(WebIDBFactory::create()); | |
116 } | 112 } |
117 return idb_factory_.get(); | 113 return idb_factory_.get(); |
118 } | 114 } |
119 | 115 |
120 std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() { | 116 std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() { |
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
122 std::vector<GURL> origins; | 118 std::vector<GURL> origins; |
123 std::set<GURL>* origins_set = GetOriginSet(); | 119 std::set<GURL>* origins_set = GetOriginSet(); |
124 for (std::set<GURL>::const_iterator iter = origins_set->begin(); | 120 for (std::set<GURL>::const_iterator iter = origins_set->begin(); |
125 iter != origins_set->end(); | 121 iter != origins_set->end(); ++iter) { |
126 ++iter) { | |
127 origins.push_back(*iter); | 122 origins.push_back(*iter); |
128 } | 123 } |
129 return origins; | 124 return origins; |
130 } | 125 } |
131 | 126 |
132 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { | 127 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { |
133 std::vector<GURL> origins = GetAllOrigins(); | 128 std::vector<GURL> origins = GetAllOrigins(); |
134 std::vector<IndexedDBInfo> result; | 129 std::vector<IndexedDBInfo> result; |
135 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 130 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
136 iter != origins.end(); | 131 iter != origins.end(); ++iter) { |
137 ++iter) { | |
138 const GURL& origin_url = *iter; | 132 const GURL& origin_url = *iter; |
139 | 133 |
140 base::FilePath idb_directory = GetFilePath(origin_url); | 134 base::FilePath idb_directory = GetFilePath(origin_url); |
141 result.push_back(IndexedDBInfo(origin_url, | 135 result.push_back(IndexedDBInfo(origin_url, |
142 GetOriginDiskUsage(origin_url), | 136 GetOriginDiskUsage(origin_url), |
143 GetOriginLastModified(origin_url), | 137 GetOriginLastModified(origin_url), |
144 idb_directory)); | 138 idb_directory)); |
145 } | 139 } |
146 return result; | 140 return result; |
147 } | 141 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 195 } |
202 } | 196 } |
203 | 197 |
204 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { | 198 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { |
205 base::string16 origin_id = | 199 base::string16 origin_id = |
206 webkit_base::GetOriginIdentifierFromURL(origin_url); | 200 webkit_base::GetOriginIdentifierFromURL(origin_url); |
207 return GetIndexedDBFilePath(origin_id); | 201 return GetIndexedDBFilePath(origin_id); |
208 } | 202 } |
209 | 203 |
210 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 204 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
211 const string16& origin_id) const { | 205 const string16& origin_id) const { |
212 return GetIndexedDBFilePath(origin_id); | 206 return GetIndexedDBFilePath(origin_id); |
213 } | 207 } |
214 | 208 |
215 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, | 209 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, |
216 WebIDBDatabase* connection) { | 210 WebIDBDatabase* connection) { |
217 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); | 211 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); |
218 if (quota_manager_proxy()) { | 212 if (quota_manager_proxy()) { |
219 quota_manager_proxy()->NotifyStorageAccessed( | 213 quota_manager_proxy()->NotifyStorageAccessed( |
220 quota::QuotaClient::kIndexedDatabase, | 214 quota::QuotaClient::kIndexedDatabase, origin_url, |
221 origin_url, | |
222 quota::kStorageTypeTemporary); | 215 quota::kStorageTypeTemporary); |
223 } | 216 } |
224 connections_[origin_url].insert(connection); | 217 connections_[origin_url].insert(connection); |
225 if (AddToOriginSet(origin_url)) { | 218 if (AddToOriginSet(origin_url)) { |
226 // A newly created db, notify the quota system. | 219 // A newly created db, notify the quota system. |
227 QueryDiskAndUpdateQuotaUsage(origin_url); | 220 QueryDiskAndUpdateQuotaUsage(origin_url); |
228 } else { | 221 } else { |
229 EnsureDiskUsageCacheInitialized(origin_url); | 222 EnsureDiskUsageCacheInitialized(origin_url); |
230 } | 223 } |
231 QueryAvailableQuota(origin_url); | 224 QueryAvailableQuota(origin_url); |
232 } | 225 } |
233 | 226 |
234 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, | 227 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, |
235 WebIDBDatabase* connection) { | 228 WebIDBDatabase* connection) { |
236 // May not be in the map if connection was forced to close | 229 // May not be in the map if connection was forced to close |
237 if (connections_.find(origin_url) == connections_.end() || | 230 if (connections_.find(origin_url) == connections_.end() || |
238 connections_[origin_url].count(connection) != 1) | 231 connections_[origin_url].count(connection) != 1) |
239 return; | 232 return; |
240 if (quota_manager_proxy()) { | 233 if (quota_manager_proxy()) { |
241 quota_manager_proxy()->NotifyStorageAccessed( | 234 quota_manager_proxy()->NotifyStorageAccessed( |
242 quota::QuotaClient::kIndexedDatabase, | 235 quota::QuotaClient::kIndexedDatabase, origin_url, |
243 origin_url, | |
244 quota::kStorageTypeTemporary); | 236 quota::kStorageTypeTemporary); |
245 } | 237 } |
246 connections_[origin_url].erase(connection); | 238 connections_[origin_url].erase(connection); |
247 if (connections_[origin_url].size() == 0) { | 239 if (connections_[origin_url].size() == 0) { |
248 QueryDiskAndUpdateQuotaUsage(origin_url); | 240 QueryDiskAndUpdateQuotaUsage(origin_url); |
249 connections_.erase(origin_url); | 241 connections_.erase(origin_url); |
250 } | 242 } |
251 } | 243 } |
252 | 244 |
253 void IndexedDBContextImpl::TransactionComplete(const GURL& origin_url) { | 245 void IndexedDBContextImpl::TransactionComplete(const GURL& origin_url) { |
(...skipping 18 matching lines...) Expand all Loading... |
272 return WouldBeOverQuota(origin_url, kOneAdditionalByte); | 264 return WouldBeOverQuota(origin_url, kOneAdditionalByte); |
273 } | 265 } |
274 | 266 |
275 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() { | 267 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() { |
276 return quota_manager_proxy_; | 268 return quota_manager_proxy_; |
277 } | 269 } |
278 | 270 |
279 IndexedDBContextImpl::~IndexedDBContextImpl() { | 271 IndexedDBContextImpl::~IndexedDBContextImpl() { |
280 WebKit::WebIDBFactory* factory = idb_factory_.release(); | 272 WebKit::WebIDBFactory* factory = idb_factory_.release(); |
281 if (factory) { | 273 if (factory) { |
282 if (!BrowserThread::DeleteSoon( | 274 if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT_DEPRECATED, |
283 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, factory)) | 275 FROM_HERE, factory)) |
284 delete factory; | 276 delete factory; |
285 } | 277 } |
286 | 278 |
287 if (data_path_.empty()) | 279 if (data_path_.empty()) |
288 return; | 280 return; |
289 | 281 |
290 if (force_keep_session_state_) | 282 if (force_keep_session_state_) |
291 return; | 283 return; |
292 | 284 |
293 bool has_session_only_databases = | 285 bool has_session_only_databases = |
294 special_storage_policy_.get() && | 286 special_storage_policy_.get() && |
295 special_storage_policy_->HasSessionOnlyOrigins(); | 287 special_storage_policy_->HasSessionOnlyOrigins(); |
296 | 288 |
297 // Clearning only session-only databases, and there are none. | 289 // Clearning only session-only databases, and there are none. |
298 if (!has_session_only_databases) | 290 if (!has_session_only_databases) |
299 return; | 291 return; |
300 | 292 |
301 // No WEBKIT thread here means we are running in a unit test where no clean | 293 // No WEBKIT thread here means we are running in a unit test where no clean |
302 // up is needed. | 294 // up is needed. |
303 BrowserThread::PostTask( | 295 BrowserThread::PostTask( |
304 BrowserThread::WEBKIT_DEPRECATED, | 296 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
305 FROM_HERE, | 297 base::Bind(&ClearSessionOnlyOrigins, |
306 base::Bind( | 298 data_path_, |
307 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_)); | 299 special_storage_policy_)); |
308 } | 300 } |
309 | 301 |
310 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath( | 302 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath( |
311 const string16& origin_id) const { | 303 const string16& origin_id) const { |
312 DCHECK(!data_path_.empty()); | 304 DCHECK(!data_path_.empty()); |
313 base::FilePath::StringType id = webkit_base::WebStringToFilePathString( | 305 base::FilePath::StringType id = |
314 origin_id).append(FILE_PATH_LITERAL(".indexeddb")); | 306 webkit_base::WebStringToFilePathString(origin_id).append( |
| 307 FILE_PATH_LITERAL(".indexeddb")); |
315 return data_path_.Append(id.append(kIndexedDBExtension)); | 308 return data_path_.Append(id.append(kIndexedDBExtension)); |
316 } | 309 } |
317 | 310 |
318 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { | 311 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { |
319 if (data_path_.empty()) | 312 if (data_path_.empty()) |
320 return 0; | 313 return 0; |
321 base::string16 origin_id = | 314 base::string16 origin_id = |
322 webkit_base::GetOriginIdentifierFromURL(origin_url); | 315 webkit_base::GetOriginIdentifierFromURL(origin_url); |
323 base::FilePath file_path = GetIndexedDBFilePath(origin_id); | 316 base::FilePath file_path = GetIndexedDBFilePath(origin_id); |
324 return file_util::ComputeDirectorySize(file_path); | 317 return file_util::ComputeDirectorySize(file_path); |
325 } | 318 } |
326 | 319 |
327 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( | 320 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( |
328 const GURL& origin_url) { | 321 const GURL& origin_url) { |
329 if (origin_size_map_.find(origin_url) == origin_size_map_.end()) | 322 if (origin_size_map_.find(origin_url) == origin_size_map_.end()) |
330 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); | 323 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); |
331 } | 324 } |
332 | 325 |
333 void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage( | 326 void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage( |
334 const GURL& origin_url) { | 327 const GURL& origin_url) { |
335 int64 former_disk_usage = origin_size_map_[origin_url]; | 328 int64 former_disk_usage = origin_size_map_[origin_url]; |
336 int64 current_disk_usage = ReadUsageFromDisk(origin_url); | 329 int64 current_disk_usage = ReadUsageFromDisk(origin_url); |
337 int64 difference = current_disk_usage - former_disk_usage; | 330 int64 difference = current_disk_usage - former_disk_usage; |
338 if (difference) { | 331 if (difference) { |
339 origin_size_map_[origin_url] = current_disk_usage; | 332 origin_size_map_[origin_url] = current_disk_usage; |
340 // quota_manager_proxy() is NULL in unit tests. | 333 // quota_manager_proxy() is NULL in unit tests. |
341 if (quota_manager_proxy()) { | 334 if (quota_manager_proxy()) |
342 quota_manager_proxy()->NotifyStorageModified( | 335 quota_manager_proxy()->NotifyStorageModified( |
343 quota::QuotaClient::kIndexedDatabase, | 336 quota::QuotaClient::kIndexedDatabase, |
344 origin_url, | 337 origin_url, |
345 quota::kStorageTypeTemporary, | 338 quota::kStorageTypeTemporary, |
346 difference); | 339 difference); |
347 } | |
348 } | 340 } |
349 } | 341 } |
350 | 342 |
351 void IndexedDBContextImpl::GotUsageAndQuota(const GURL& origin_url, | 343 void IndexedDBContextImpl::GotUsageAndQuota(const GURL& origin_url, |
352 quota::QuotaStatusCode status, | 344 quota::QuotaStatusCode status, |
353 int64 usage, | 345 int64 usage, int64 quota) { |
354 int64 quota) { | |
355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
356 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort) | 347 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort) |
357 << "status was " << status; | 348 << "status was " << status; |
358 if (status == quota::kQuotaErrorAbort) { | 349 if (status == quota::kQuotaErrorAbort) { |
359 // We seem to no longer care to wait around for the answer. | 350 // We seem to no longer care to wait around for the answer. |
360 return; | 351 return; |
361 } | 352 } |
362 BrowserThread::PostTask(BrowserThread::WEBKIT_DEPRECATED, | 353 BrowserThread::PostTask( |
363 FROM_HERE, | 354 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
364 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota, | 355 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota, this, origin_url, |
365 this, | 356 usage, quota)); |
366 origin_url, | |
367 usage, | |
368 quota)); | |
369 } | 357 } |
370 | 358 |
371 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, | 359 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, int64 usage, |
372 int64 usage, | |
373 int64 quota) { | 360 int64 quota) { |
374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
375 space_available_map_[origin_url] = quota - usage; | 362 space_available_map_[origin_url] = quota - usage; |
376 } | 363 } |
377 | 364 |
378 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) { | 365 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) { |
379 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 366 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
381 if (quota_manager_proxy()) { | 368 if (quota_manager_proxy()) |
382 BrowserThread::PostTask( | 369 BrowserThread::PostTask( |
383 BrowserThread::IO, | 370 BrowserThread::IO, FROM_HERE, |
384 FROM_HERE, | 371 base::Bind(&IndexedDBContextImpl::QueryAvailableQuota, this, |
385 base::Bind( | 372 origin_url)); |
386 &IndexedDBContextImpl::QueryAvailableQuota, this, origin_url)); | |
387 } | |
388 return; | 373 return; |
389 } | 374 } |
390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
391 if (!quota_manager_proxy() || !quota_manager_proxy()->quota_manager()) | 376 if (!quota_manager_proxy() || !quota_manager_proxy()->quota_manager()) |
392 return; | 377 return; |
393 quota_manager_proxy()->quota_manager()->GetUsageAndQuota( | 378 quota_manager_proxy()->quota_manager()->GetUsageAndQuota( |
394 origin_url, | 379 origin_url, |
395 quota::kStorageTypeTemporary, | 380 quota::kStorageTypeTemporary, |
396 base::Bind(&IndexedDBContextImpl::GotUsageAndQuota, this, origin_url)); | 381 base::Bind(&IndexedDBContextImpl::GotUsageAndQuota, this, origin_url)); |
397 } | 382 } |
398 | 383 |
399 std::set<GURL>* IndexedDBContextImpl::GetOriginSet() { | 384 std::set<GURL>* IndexedDBContextImpl::GetOriginSet() { |
400 if (!origin_set_) { | 385 if (!origin_set_) { |
401 origin_set_.reset(new std::set<GURL>); | 386 origin_set_.reset(new std::set<GURL>); |
402 std::vector<GURL> origins; | 387 std::vector<GURL> origins; |
403 GetAllOriginsAndPaths(data_path_, &origins, NULL); | 388 GetAllOriginsAndPaths(data_path_, &origins, NULL); |
404 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 389 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
405 iter != origins.end(); | 390 iter != origins.end(); ++iter) { |
406 ++iter) { | |
407 origin_set_->insert(*iter); | 391 origin_set_->insert(*iter); |
408 } | 392 } |
409 } | 393 } |
410 return origin_set_.get(); | 394 return origin_set_.get(); |
411 } | 395 } |
412 | 396 |
413 void IndexedDBContextImpl::ResetCaches() { | 397 void IndexedDBContextImpl::ResetCaches() { |
414 origin_set_.reset(); | 398 origin_set_.reset(); |
415 origin_size_map_.clear(); | 399 origin_size_map_.clear(); |
416 space_available_map_.clear(); | 400 space_available_map_.clear(); |
417 } | 401 } |
418 | 402 |
419 } // namespace content | 403 } // namespace content |
OLD | NEW |