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