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