| 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/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "content/browser/indexed_db/indexed_db_quota_client.h" | 17 #include "content/browser/indexed_db/indexed_db_quota_client.h" |
| 18 #include "content/browser/indexed_db/webidbdatabase_impl.h" |
| 18 #include "content/browser/indexed_db/webidbfactory_impl.h" | 19 #include "content/browser/indexed_db/webidbfactory_impl.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/indexed_db_info.h" | 21 #include "content/public/browser/indexed_db_info.h" |
| 21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 22 #include "third_party/WebKit/public/platform/WebCString.h" | 23 #include "third_party/WebKit/public/platform/WebCString.h" |
| 23 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" | 24 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" |
| 24 #include "third_party/WebKit/public/platform/WebIDBFactory.h" | |
| 25 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
| 26 #include "webkit/base/file_path_string_conversions.h" | 26 #include "webkit/base/file_path_string_conversions.h" |
| 27 #include "webkit/base/origin_url_conversions.h" | 27 #include "webkit/base/origin_url_conversions.h" |
| 28 #include "webkit/browser/database/database_util.h" | 28 #include "webkit/browser/database/database_util.h" |
| 29 #include "webkit/browser/quota/quota_manager.h" | 29 #include "webkit/browser/quota/quota_manager.h" |
| 30 #include "webkit/browser/quota/special_storage_policy.h" | 30 #include "webkit/browser/quota/special_storage_policy.h" |
| 31 | 31 |
| 32 using webkit_database::DatabaseUtil; | 32 using webkit_database::DatabaseUtil; |
| 33 using WebKit::WebIDBDatabase; | |
| 34 using WebKit::WebIDBFactory; | |
| 35 | 33 |
| 36 namespace content { | 34 namespace content { |
| 37 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = | 35 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = |
| 38 FILE_PATH_LITERAL("IndexedDB"); | 36 FILE_PATH_LITERAL("IndexedDB"); |
| 39 | 37 |
| 40 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] = | 38 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] = |
| 41 FILE_PATH_LITERAL(".leveldb"); | 39 FILE_PATH_LITERAL(".leveldb"); |
| 42 | 40 |
| 43 namespace { | 41 namespace { |
| 44 | 42 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 quota_manager_proxy_(quota_manager_proxy) { | 95 quota_manager_proxy_(quota_manager_proxy) { |
| 98 if (!data_path.empty()) | 96 if (!data_path.empty()) |
| 99 data_path_ = data_path.Append(kIndexedDBDirectory); | 97 data_path_ = data_path.Append(kIndexedDBDirectory); |
| 100 if (quota_manager_proxy && | 98 if (quota_manager_proxy && |
| 101 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { | 99 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { |
| 102 quota_manager_proxy->RegisterClient( | 100 quota_manager_proxy->RegisterClient( |
| 103 new IndexedDBQuotaClient(webkit_thread_loop, this)); | 101 new IndexedDBQuotaClient(webkit_thread_loop, this)); |
| 104 } | 102 } |
| 105 } | 103 } |
| 106 | 104 |
| 107 WebIDBFactory* IndexedDBContextImpl::GetIDBFactory() { | 105 WebIDBFactoryImpl* IndexedDBContextImpl::GetIDBFactory() { |
| 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
| 109 if (!idb_factory_) { | 107 if (!idb_factory_) { |
| 110 // Prime our cache of origins with existing databases so we can | 108 // Prime our cache of origins with existing databases so we can |
| 111 // detect when dbs are newly created. | 109 // detect when dbs are newly created. |
| 112 GetOriginSet(); | 110 GetOriginSet(); |
| 113 idb_factory_.reset(new content::WebIDBFactoryImpl()); | 111 idb_factory_.reset(new content::WebIDBFactoryImpl()); |
| 114 } | 112 } |
| 115 return idb_factory_.get(); | 113 return idb_factory_.get(); |
| 116 } | 114 } |
| 117 | 115 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 void IndexedDBContextImpl::ForceClose(const GURL& origin_url) { | 181 void IndexedDBContextImpl::ForceClose(const GURL& origin_url) { |
| 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
| 185 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 183 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 186 return; | 184 return; |
| 187 | 185 |
| 188 if (connections_.find(origin_url) != connections_.end()) { | 186 if (connections_.find(origin_url) != connections_.end()) { |
| 189 ConnectionSet& connections = connections_[origin_url]; | 187 ConnectionSet& connections = connections_[origin_url]; |
| 190 ConnectionSet::iterator it = connections.begin(); | 188 ConnectionSet::iterator it = connections.begin(); |
| 191 while (it != connections.end()) { | 189 while (it != connections.end()) { |
| 192 // Remove before closing so callbacks don't double-erase | 190 // Remove before closing so callbacks don't double-erase |
| 193 WebKit::WebIDBDatabase* db = *it; | 191 WebIDBDatabaseImpl* db = *it; |
| 194 connections.erase(it++); | 192 connections.erase(it++); |
| 195 db->forceClose(); | 193 db->forceClose(); |
| 196 } | 194 } |
| 197 DCHECK_EQ(connections_[origin_url].size(), 0UL); | 195 DCHECK_EQ(connections_[origin_url].size(), 0UL); |
| 198 connections_.erase(origin_url); | 196 connections_.erase(origin_url); |
| 199 } | 197 } |
| 200 } | 198 } |
| 201 | 199 |
| 202 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { | 200 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { |
| 203 base::string16 origin_id = | 201 base::string16 origin_id = |
| 204 webkit_base::GetOriginIdentifierFromURL(origin_url); | 202 webkit_base::GetOriginIdentifierFromURL(origin_url); |
| 205 return GetIndexedDBFilePath(origin_id); | 203 return GetIndexedDBFilePath(origin_id); |
| 206 } | 204 } |
| 207 | 205 |
| 208 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 206 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
| 209 const string16& origin_id) const { | 207 const string16& origin_id) const { |
| 210 return GetIndexedDBFilePath(origin_id); | 208 return GetIndexedDBFilePath(origin_id); |
| 211 } | 209 } |
| 212 | 210 |
| 213 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, | 211 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, |
| 214 WebIDBDatabase* connection) { | 212 WebIDBDatabaseImpl* connection) { |
| 215 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); | 213 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); |
| 216 if (quota_manager_proxy()) { | 214 if (quota_manager_proxy()) { |
| 217 quota_manager_proxy()->NotifyStorageAccessed( | 215 quota_manager_proxy()->NotifyStorageAccessed( |
| 218 quota::QuotaClient::kIndexedDatabase, | 216 quota::QuotaClient::kIndexedDatabase, |
| 219 origin_url, | 217 origin_url, |
| 220 quota::kStorageTypeTemporary); | 218 quota::kStorageTypeTemporary); |
| 221 } | 219 } |
| 222 connections_[origin_url].insert(connection); | 220 connections_[origin_url].insert(connection); |
| 223 if (AddToOriginSet(origin_url)) { | 221 if (AddToOriginSet(origin_url)) { |
| 224 // A newly created db, notify the quota system. | 222 // A newly created db, notify the quota system. |
| 225 QueryDiskAndUpdateQuotaUsage(origin_url); | 223 QueryDiskAndUpdateQuotaUsage(origin_url); |
| 226 } else { | 224 } else { |
| 227 EnsureDiskUsageCacheInitialized(origin_url); | 225 EnsureDiskUsageCacheInitialized(origin_url); |
| 228 } | 226 } |
| 229 QueryAvailableQuota(origin_url); | 227 QueryAvailableQuota(origin_url); |
| 230 } | 228 } |
| 231 | 229 |
| 232 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, | 230 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, |
| 233 WebIDBDatabase* connection) { | 231 WebIDBDatabaseImpl* connection) { |
| 234 // May not be in the map if connection was forced to close | 232 // May not be in the map if connection was forced to close |
| 235 if (connections_.find(origin_url) == connections_.end() || | 233 if (connections_.find(origin_url) == connections_.end() || |
| 236 connections_[origin_url].count(connection) != 1) | 234 connections_[origin_url].count(connection) != 1) |
| 237 return; | 235 return; |
| 238 if (quota_manager_proxy()) { | 236 if (quota_manager_proxy()) { |
| 239 quota_manager_proxy()->NotifyStorageAccessed( | 237 quota_manager_proxy()->NotifyStorageAccessed( |
| 240 quota::QuotaClient::kIndexedDatabase, | 238 quota::QuotaClient::kIndexedDatabase, |
| 241 origin_url, | 239 origin_url, |
| 242 quota::kStorageTypeTemporary); | 240 quota::kStorageTypeTemporary); |
| 243 } | 241 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 268 bool IndexedDBContextImpl::IsOverQuota(const GURL& origin_url) { | 266 bool IndexedDBContextImpl::IsOverQuota(const GURL& origin_url) { |
| 269 const int kOneAdditionalByte = 1; | 267 const int kOneAdditionalByte = 1; |
| 270 return WouldBeOverQuota(origin_url, kOneAdditionalByte); | 268 return WouldBeOverQuota(origin_url, kOneAdditionalByte); |
| 271 } | 269 } |
| 272 | 270 |
| 273 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() { | 271 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() { |
| 274 return quota_manager_proxy_.get(); | 272 return quota_manager_proxy_.get(); |
| 275 } | 273 } |
| 276 | 274 |
| 277 IndexedDBContextImpl::~IndexedDBContextImpl() { | 275 IndexedDBContextImpl::~IndexedDBContextImpl() { |
| 278 WebKit::WebIDBFactory* factory = idb_factory_.release(); | 276 WebIDBFactoryImpl* factory = idb_factory_.release(); |
| 279 if (factory) { | 277 if (factory) { |
| 280 if (!BrowserThread::DeleteSoon( | 278 if (!BrowserThread::DeleteSoon( |
| 281 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, factory)) | 279 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, factory)) |
| 282 delete factory; | 280 delete factory; |
| 283 } | 281 } |
| 284 | 282 |
| 285 if (data_path_.empty()) | 283 if (data_path_.empty()) |
| 286 return; | 284 return; |
| 287 | 285 |
| 288 if (force_keep_session_state_) | 286 if (force_keep_session_state_) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 return origin_set_.get(); | 406 return origin_set_.get(); |
| 409 } | 407 } |
| 410 | 408 |
| 411 void IndexedDBContextImpl::ResetCaches() { | 409 void IndexedDBContextImpl::ResetCaches() { |
| 412 origin_set_.reset(); | 410 origin_set_.reset(); |
| 413 origin_size_map_.clear(); | 411 origin_size_map_.clear(); |
| 414 space_available_map_.clear(); | 412 space_available_map_.clear(); |
| 415 } | 413 } |
| 416 | 414 |
| 417 } // namespace content | 415 } // namespace content |
| OLD | NEW |