| 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/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "content/browser/browser_main_loop.h" | 18 #include "content/browser/browser_main_loop.h" |
| 19 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 19 #include "content/browser/indexed_db/indexed_db_factory.h" | 20 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 20 #include "content/browser/indexed_db/indexed_db_quota_client.h" | 21 #include "content/browser/indexed_db/indexed_db_quota_client.h" |
| 21 #include "content/browser/indexed_db/webidbdatabase_impl.h" | |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/indexed_db_info.h" | 23 #include "content/public/browser/indexed_db_info.h" |
| 24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 25 #include "webkit/browser/database/database_util.h" | 25 #include "webkit/browser/database/database_util.h" |
| 26 #include "webkit/browser/quota/quota_manager.h" | 26 #include "webkit/browser/quota/quota_manager.h" |
| 27 #include "webkit/browser/quota/special_storage_policy.h" | 27 #include "webkit/browser/quota/special_storage_policy.h" |
| 28 #include "webkit/common/database/database_identifier.h" | 28 #include "webkit/common/database/database_identifier.h" |
| 29 | 29 |
| 30 using webkit_database::DatabaseUtil; | 30 using webkit_database::DatabaseUtil; |
| 31 | 31 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 void IndexedDBContextImpl::ForceClose(const GURL& origin_url) { | 188 void IndexedDBContextImpl::ForceClose(const GURL& origin_url) { |
| 189 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 189 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 190 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 190 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 191 return; | 191 return; |
| 192 | 192 |
| 193 if (connections_.find(origin_url) != connections_.end()) { | 193 if (connections_.find(origin_url) != connections_.end()) { |
| 194 ConnectionSet& connections = connections_[origin_url]; | 194 ConnectionSet& connections = connections_[origin_url]; |
| 195 ConnectionSet::iterator it = connections.begin(); | 195 ConnectionSet::iterator it = connections.begin(); |
| 196 while (it != connections.end()) { | 196 while (it != connections.end()) { |
| 197 // Remove before closing so callbacks don't double-erase | 197 // Remove before closing so callbacks don't double-erase |
| 198 WebIDBDatabaseImpl* db = *it; | 198 IndexedDBConnection* connection = *it; |
| 199 connections.erase(it++); | 199 connections.erase(it++); |
| 200 db->forceClose(); | 200 connection->ForceClose(); |
| 201 } | 201 } |
| 202 DCHECK_EQ(connections_[origin_url].size(), 0UL); | 202 DCHECK_EQ(connections_[origin_url].size(), 0UL); |
| 203 connections_.erase(origin_url); | 203 connections_.erase(origin_url); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { | 207 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { |
| 208 std::string origin_id = | 208 std::string origin_id = |
| 209 webkit_database::GetIdentifierFromOrigin(origin_url); | 209 webkit_database::GetIdentifierFromOrigin(origin_url); |
| 210 return GetIndexedDBFilePath(origin_id); | 210 return GetIndexedDBFilePath(origin_id); |
| 211 } | 211 } |
| 212 | 212 |
| 213 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 213 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
| 214 const std::string& origin_id) const { | 214 const std::string& origin_id) const { |
| 215 return GetIndexedDBFilePath(origin_id); | 215 return GetIndexedDBFilePath(origin_id); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void IndexedDBContextImpl::SetTaskRunnerForTesting( | 218 void IndexedDBContextImpl::SetTaskRunnerForTesting( |
| 219 base::SequencedTaskRunner* task_runner) { | 219 base::SequencedTaskRunner* task_runner) { |
| 220 DCHECK(!task_runner_); | 220 DCHECK(!task_runner_); |
| 221 task_runner_ = task_runner; | 221 task_runner_ = task_runner; |
| 222 } | 222 } |
| 223 | 223 |
| 224 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, | 224 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, |
| 225 WebIDBDatabaseImpl* connection) { | 225 IndexedDBConnection* connection) { |
| 226 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 226 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 227 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); | 227 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); |
| 228 if (quota_manager_proxy()) { | 228 if (quota_manager_proxy()) { |
| 229 quota_manager_proxy()->NotifyStorageAccessed( | 229 quota_manager_proxy()->NotifyStorageAccessed( |
| 230 quota::QuotaClient::kIndexedDatabase, | 230 quota::QuotaClient::kIndexedDatabase, |
| 231 origin_url, | 231 origin_url, |
| 232 quota::kStorageTypeTemporary); | 232 quota::kStorageTypeTemporary); |
| 233 } | 233 } |
| 234 connections_[origin_url].insert(connection); | 234 connections_[origin_url].insert(connection); |
| 235 if (AddToOriginSet(origin_url)) { | 235 if (AddToOriginSet(origin_url)) { |
| 236 // A newly created db, notify the quota system. | 236 // A newly created db, notify the quota system. |
| 237 QueryDiskAndUpdateQuotaUsage(origin_url); | 237 QueryDiskAndUpdateQuotaUsage(origin_url); |
| 238 } else { | 238 } else { |
| 239 EnsureDiskUsageCacheInitialized(origin_url); | 239 EnsureDiskUsageCacheInitialized(origin_url); |
| 240 } | 240 } |
| 241 QueryAvailableQuota(origin_url); | 241 QueryAvailableQuota(origin_url); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, | 244 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, |
| 245 WebIDBDatabaseImpl* connection) { | 245 IndexedDBConnection* connection) { |
| 246 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 246 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 247 // May not be in the map if connection was forced to close | 247 // May not be in the map if connection was forced to close |
| 248 if (connections_.find(origin_url) == connections_.end() || | 248 if (connections_.find(origin_url) == connections_.end() || |
| 249 connections_[origin_url].count(connection) != 1) | 249 connections_[origin_url].count(connection) != 1) |
| 250 return; | 250 return; |
| 251 if (quota_manager_proxy()) { | 251 if (quota_manager_proxy()) { |
| 252 quota_manager_proxy()->NotifyStorageAccessed( | 252 quota_manager_proxy()->NotifyStorageAccessed( |
| 253 quota::QuotaClient::kIndexedDatabase, | 253 quota::QuotaClient::kIndexedDatabase, |
| 254 origin_url, | 254 origin_url, |
| 255 quota::kStorageTypeTemporary); | 255 quota::kStorageTypeTemporary); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 origin_set_.reset(); | 424 origin_set_.reset(); |
| 425 origin_size_map_.clear(); | 425 origin_size_map_.clear(); |
| 426 space_available_map_.clear(); | 426 space_available_map_.clear(); |
| 427 } | 427 } |
| 428 | 428 |
| 429 base::TaskRunner* IndexedDBContextImpl::TaskRunner() const { | 429 base::TaskRunner* IndexedDBContextImpl::TaskRunner() const { |
| 430 return task_runner_; | 430 return task_runner_; |
| 431 } | 431 } |
| 432 | 432 |
| 433 } // namespace content | 433 } // namespace content |
| OLD | NEW |