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