| 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/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" |
| 18 #include "content/browser/browser_main_loop.h" |
| 17 #include "content/browser/indexed_db/indexed_db_quota_client.h" | 19 #include "content/browser/indexed_db/indexed_db_quota_client.h" |
| 18 #include "content/browser/indexed_db/webidbdatabase_impl.h" | 20 #include "content/browser/indexed_db/webidbdatabase_impl.h" |
| 19 #include "content/browser/indexed_db/webidbfactory_impl.h" | 21 #include "content/browser/indexed_db/webidbfactory_impl.h" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/indexed_db_info.h" | 23 #include "content/public/browser/indexed_db_info.h" |
| 22 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 23 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
| 24 #include "webkit/base/file_path_string_conversions.h" | 26 #include "webkit/base/file_path_string_conversions.h" |
| 25 #include "webkit/browser/database/database_util.h" | 27 #include "webkit/browser/database/database_util.h" |
| 26 #include "webkit/browser/quota/quota_manager.h" | 28 #include "webkit/browser/quota/quota_manager.h" |
| 27 #include "webkit/browser/quota/special_storage_policy.h" | 29 #include "webkit/browser/quota/special_storage_policy.h" |
| 28 #include "webkit/common/database/database_identifier.h" | 30 #include "webkit/common/database/database_identifier.h" |
| 29 | 31 |
| 30 using webkit_database::DatabaseUtil; | 32 using webkit_database::DatabaseUtil; |
| 31 | 33 |
| 32 namespace content { | 34 namespace content { |
| 33 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = | 35 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = |
| 34 FILE_PATH_LITERAL("IndexedDB"); | 36 FILE_PATH_LITERAL("IndexedDB"); |
| 35 | 37 |
| 36 static const base::FilePath::CharType kIndexedDBExtension[] = | 38 static const base::FilePath::CharType kIndexedDBExtension[] = |
| 37 FILE_PATH_LITERAL(".indexeddb"); | 39 FILE_PATH_LITERAL(".indexeddb"); |
| 38 | 40 |
| 39 static const base::FilePath::CharType kLevelDBExtension[] = | 41 static const base::FilePath::CharType kLevelDBExtension[] = |
| 40 FILE_PATH_LITERAL(".leveldb"); | 42 FILE_PATH_LITERAL(".leveldb"); |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 46 // This may be called after the IndexedDBContext is destroyed. |
| 44 void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path, | 47 void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path, |
| 45 std::vector<GURL>* origins, | 48 std::vector<GURL>* origins, |
| 46 std::vector<base::FilePath>* file_paths) { | 49 std::vector<base::FilePath>* file_paths) { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 50 // TODO(jsbell): DCHECK that this is running on an IndexedDB thread, |
| 51 // if a global handle to it is ever available. |
| 48 if (indexeddb_path.empty()) | 52 if (indexeddb_path.empty()) |
| 49 return; | 53 return; |
| 50 base::FileEnumerator file_enumerator( | 54 base::FileEnumerator file_enumerator( |
| 51 indexeddb_path, false, base::FileEnumerator::DIRECTORIES); | 55 indexeddb_path, false, base::FileEnumerator::DIRECTORIES); |
| 52 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 56 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| 53 file_path = file_enumerator.Next()) { | 57 file_path = file_enumerator.Next()) { |
| 54 if (file_path.Extension() == kLevelDBExtension && | 58 if (file_path.Extension() == kLevelDBExtension && |
| 55 file_path.RemoveExtension().Extension() == kIndexedDBExtension) { | 59 file_path.RemoveExtension().Extension() == kIndexedDBExtension) { |
| 56 std::string origin_id = file_path.BaseName().RemoveExtension() | 60 std::string origin_id = file_path.BaseName().RemoveExtension() |
| 57 .RemoveExtension().MaybeAsASCII(); | 61 .RemoveExtension().MaybeAsASCII(); |
| 58 origins->push_back(webkit_database::GetOriginFromIdentifier(origin_id)); | 62 origins->push_back(webkit_database::GetOriginFromIdentifier(origin_id)); |
| 59 if (file_paths) | 63 if (file_paths) |
| 60 file_paths->push_back(file_path); | 64 file_paths->push_back(file_path); |
| 61 } | 65 } |
| 62 } | 66 } |
| 63 } | 67 } |
| 64 | 68 |
| 65 // Deletes session-only databases. | 69 // This will be called after the IndexedDBContext is destroyed. |
| 66 void ClearSessionOnlyOrigins( | 70 void ClearSessionOnlyOrigins( |
| 67 const base::FilePath& indexeddb_path, | 71 const base::FilePath& indexeddb_path, |
| 68 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { | 72 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 73 // TODO(jsbell): DCHECK that this is running on an IndexedDB thread, |
| 74 // if a global handle to it is ever available. |
| 70 std::vector<GURL> origins; | 75 std::vector<GURL> origins; |
| 71 std::vector<base::FilePath> file_paths; | 76 std::vector<base::FilePath> file_paths; |
| 72 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); | 77 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); |
| 73 DCHECK_EQ(origins.size(), file_paths.size()); | 78 DCHECK_EQ(origins.size(), file_paths.size()); |
| 74 std::vector<base::FilePath>::const_iterator file_path_iter = | 79 std::vector<base::FilePath>::const_iterator file_path_iter = |
| 75 file_paths.begin(); | 80 file_paths.begin(); |
| 76 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 81 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
| 77 iter != origins.end(); | 82 iter != origins.end(); |
| 78 ++iter, ++file_path_iter) { | 83 ++iter, ++file_path_iter) { |
| 79 if (!special_storage_policy->IsStorageSessionOnly(*iter)) | 84 if (!special_storage_policy->IsStorageSessionOnly(*iter)) |
| 80 continue; | 85 continue; |
| 81 if (special_storage_policy->IsStorageProtected(*iter)) | 86 if (special_storage_policy->IsStorageProtected(*iter)) |
| 82 continue; | 87 continue; |
| 83 file_util::Delete(*file_path_iter, true); | 88 file_util::Delete(*file_path_iter, true); |
| 84 } | 89 } |
| 85 } | 90 } |
| 86 | 91 |
| 87 } // namespace | 92 } // namespace |
| 88 | 93 |
| 89 IndexedDBContextImpl::IndexedDBContextImpl( | 94 IndexedDBContextImpl::IndexedDBContextImpl( |
| 90 const base::FilePath& data_path, | 95 const base::FilePath& data_path, |
| 91 quota::SpecialStoragePolicy* special_storage_policy, | 96 quota::SpecialStoragePolicy* special_storage_policy, |
| 92 quota::QuotaManagerProxy* quota_manager_proxy, | 97 quota::QuotaManagerProxy* quota_manager_proxy, |
| 93 base::MessageLoopProxy* webkit_thread_loop) | 98 base::SequencedTaskRunner* task_runner) |
| 94 : force_keep_session_state_(false), | 99 : force_keep_session_state_(false), |
| 95 special_storage_policy_(special_storage_policy), | 100 special_storage_policy_(special_storage_policy), |
| 96 quota_manager_proxy_(quota_manager_proxy) { | 101 quota_manager_proxy_(quota_manager_proxy), |
| 102 task_runner_(task_runner) { |
| 97 if (!data_path.empty()) | 103 if (!data_path.empty()) |
| 98 data_path_ = data_path.Append(kIndexedDBDirectory); | 104 data_path_ = data_path.Append(kIndexedDBDirectory); |
| 99 if (quota_manager_proxy && | 105 if (quota_manager_proxy && |
| 100 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { | 106 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { |
| 101 quota_manager_proxy->RegisterClient( | 107 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this)); |
| 102 new IndexedDBQuotaClient(webkit_thread_loop, this)); | |
| 103 } | 108 } |
| 104 } | 109 } |
| 105 | 110 |
| 106 WebIDBFactoryImpl* IndexedDBContextImpl::GetIDBFactory() { | 111 WebIDBFactoryImpl* IndexedDBContextImpl::GetIDBFactory() { |
| 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 112 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 108 if (!idb_factory_) { | 113 if (!idb_factory_) { |
| 109 // Prime our cache of origins with existing databases so we can | 114 // Prime our cache of origins with existing databases so we can |
| 110 // detect when dbs are newly created. | 115 // detect when dbs are newly created. |
| 111 GetOriginSet(); | 116 GetOriginSet(); |
| 112 idb_factory_.reset(new content::WebIDBFactoryImpl()); | 117 idb_factory_.reset(new content::WebIDBFactoryImpl()); |
| 113 } | 118 } |
| 114 return idb_factory_.get(); | 119 return idb_factory_.get(); |
| 115 } | 120 } |
| 116 | 121 |
| 117 std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() { | 122 std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() { |
| 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 123 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 119 std::vector<GURL> origins; | 124 std::vector<GURL> origins; |
| 120 std::set<GURL>* origins_set = GetOriginSet(); | 125 std::set<GURL>* origins_set = GetOriginSet(); |
| 121 for (std::set<GURL>::const_iterator iter = origins_set->begin(); | 126 for (std::set<GURL>::const_iterator iter = origins_set->begin(); |
| 122 iter != origins_set->end(); | 127 iter != origins_set->end(); |
| 123 ++iter) { | 128 ++iter) { |
| 124 origins.push_back(*iter); | 129 origins.push_back(*iter); |
| 125 } | 130 } |
| 126 return origins; | 131 return origins; |
| 127 } | 132 } |
| 128 | 133 |
| 129 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { | 134 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { |
| 135 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 130 std::vector<GURL> origins = GetAllOrigins(); | 136 std::vector<GURL> origins = GetAllOrigins(); |
| 131 std::vector<IndexedDBInfo> result; | 137 std::vector<IndexedDBInfo> result; |
| 132 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 138 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
| 133 iter != origins.end(); | 139 iter != origins.end(); |
| 134 ++iter) { | 140 ++iter) { |
| 135 const GURL& origin_url = *iter; | 141 const GURL& origin_url = *iter; |
| 136 | 142 |
| 137 base::FilePath idb_directory = GetFilePath(origin_url); | 143 base::FilePath idb_directory = GetFilePath(origin_url); |
| 138 result.push_back(IndexedDBInfo(origin_url, | 144 result.push_back(IndexedDBInfo(origin_url, |
| 139 GetOriginDiskUsage(origin_url), | 145 GetOriginDiskUsage(origin_url), |
| 140 GetOriginLastModified(origin_url), | 146 GetOriginLastModified(origin_url), |
| 141 idb_directory)); | 147 idb_directory)); |
| 142 } | 148 } |
| 143 return result; | 149 return result; |
| 144 } | 150 } |
| 145 | 151 |
| 146 int64 IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) { | 152 int64 IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) { |
| 153 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 147 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 154 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 148 return 0; | 155 return 0; |
| 149 EnsureDiskUsageCacheInitialized(origin_url); | 156 EnsureDiskUsageCacheInitialized(origin_url); |
| 150 return origin_size_map_[origin_url]; | 157 return origin_size_map_[origin_url]; |
| 151 } | 158 } |
| 152 | 159 |
| 153 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) { | 160 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) { |
| 161 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 154 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 162 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 155 return base::Time(); | 163 return base::Time(); |
| 156 base::FilePath idb_directory = GetFilePath(origin_url); | 164 base::FilePath idb_directory = GetFilePath(origin_url); |
| 157 base::PlatformFileInfo file_info; | 165 base::PlatformFileInfo file_info; |
| 158 if (!file_util::GetFileInfo(idb_directory, &file_info)) | 166 if (!file_util::GetFileInfo(idb_directory, &file_info)) |
| 159 return base::Time(); | 167 return base::Time(); |
| 160 return file_info.last_modified; | 168 return file_info.last_modified; |
| 161 } | 169 } |
| 162 | 170 |
| 163 void IndexedDBContextImpl::DeleteForOrigin(const GURL& origin_url) { | 171 void IndexedDBContextImpl::DeleteForOrigin(const GURL& origin_url) { |
| 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 172 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 165 ForceClose(origin_url); | 173 ForceClose(origin_url); |
| 166 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 174 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 167 return; | 175 return; |
| 168 | 176 |
| 169 base::FilePath idb_directory = GetFilePath(origin_url); | 177 base::FilePath idb_directory = GetFilePath(origin_url); |
| 170 EnsureDiskUsageCacheInitialized(origin_url); | 178 EnsureDiskUsageCacheInitialized(origin_url); |
| 171 const bool recursive = true; | 179 const bool recursive = true; |
| 172 bool deleted = file_util::Delete(idb_directory, recursive); | 180 bool deleted = file_util::Delete(idb_directory, recursive); |
| 173 | 181 |
| 174 QueryDiskAndUpdateQuotaUsage(origin_url); | 182 QueryDiskAndUpdateQuotaUsage(origin_url); |
| 175 if (deleted) { | 183 if (deleted) { |
| 176 RemoveFromOriginSet(origin_url); | 184 RemoveFromOriginSet(origin_url); |
| 177 origin_size_map_.erase(origin_url); | 185 origin_size_map_.erase(origin_url); |
| 178 space_available_map_.erase(origin_url); | 186 space_available_map_.erase(origin_url); |
| 179 } | 187 } |
| 180 } | 188 } |
| 181 | 189 |
| 182 void IndexedDBContextImpl::ForceClose(const GURL& origin_url) { | 190 void IndexedDBContextImpl::ForceClose(const GURL& origin_url) { |
| 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 191 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 184 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 192 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 185 return; | 193 return; |
| 186 | 194 |
| 187 if (connections_.find(origin_url) != connections_.end()) { | 195 if (connections_.find(origin_url) != connections_.end()) { |
| 188 ConnectionSet& connections = connections_[origin_url]; | 196 ConnectionSet& connections = connections_[origin_url]; |
| 189 ConnectionSet::iterator it = connections.begin(); | 197 ConnectionSet::iterator it = connections.begin(); |
| 190 while (it != connections.end()) { | 198 while (it != connections.end()) { |
| 191 // Remove before closing so callbacks don't double-erase | 199 // Remove before closing so callbacks don't double-erase |
| 192 WebIDBDatabaseImpl* db = *it; | 200 WebIDBDatabaseImpl* db = *it; |
| 193 connections.erase(it++); | 201 connections.erase(it++); |
| 194 db->forceClose(); | 202 db->forceClose(); |
| 195 } | 203 } |
| 196 DCHECK_EQ(connections_[origin_url].size(), 0UL); | 204 DCHECK_EQ(connections_[origin_url].size(), 0UL); |
| 197 connections_.erase(origin_url); | 205 connections_.erase(origin_url); |
| 198 } | 206 } |
| 199 } | 207 } |
| 200 | 208 |
| 201 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { | 209 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { |
| 202 std::string origin_id = | 210 std::string origin_id = |
| 203 webkit_database::GetIdentifierFromOrigin(origin_url); | 211 webkit_database::GetIdentifierFromOrigin(origin_url); |
| 204 return GetIndexedDBFilePath(origin_id); | 212 return GetIndexedDBFilePath(origin_id); |
| 205 } | 213 } |
| 206 | 214 |
| 207 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 215 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
| 208 const std::string& origin_id) const { | 216 const std::string& origin_id) const { |
| 209 return GetIndexedDBFilePath(origin_id); | 217 return GetIndexedDBFilePath(origin_id); |
| 210 } | 218 } |
| 211 | 219 |
| 220 void IndexedDBContextImpl::SetTaskRunnerForTesting( |
| 221 base::SequencedTaskRunner* task_runner) { |
| 222 DCHECK(!task_runner_); |
| 223 task_runner_ = task_runner; |
| 224 } |
| 225 |
| 212 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, | 226 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, |
| 213 WebIDBDatabaseImpl* connection) { | 227 WebIDBDatabaseImpl* connection) { |
| 228 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 214 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); | 229 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); |
| 215 if (quota_manager_proxy()) { | 230 if (quota_manager_proxy()) { |
| 216 quota_manager_proxy()->NotifyStorageAccessed( | 231 quota_manager_proxy()->NotifyStorageAccessed( |
| 217 quota::QuotaClient::kIndexedDatabase, | 232 quota::QuotaClient::kIndexedDatabase, |
| 218 origin_url, | 233 origin_url, |
| 219 quota::kStorageTypeTemporary); | 234 quota::kStorageTypeTemporary); |
| 220 } | 235 } |
| 221 connections_[origin_url].insert(connection); | 236 connections_[origin_url].insert(connection); |
| 222 if (AddToOriginSet(origin_url)) { | 237 if (AddToOriginSet(origin_url)) { |
| 223 // A newly created db, notify the quota system. | 238 // A newly created db, notify the quota system. |
| 224 QueryDiskAndUpdateQuotaUsage(origin_url); | 239 QueryDiskAndUpdateQuotaUsage(origin_url); |
| 225 } else { | 240 } else { |
| 226 EnsureDiskUsageCacheInitialized(origin_url); | 241 EnsureDiskUsageCacheInitialized(origin_url); |
| 227 } | 242 } |
| 228 QueryAvailableQuota(origin_url); | 243 QueryAvailableQuota(origin_url); |
| 229 } | 244 } |
| 230 | 245 |
| 231 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, | 246 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, |
| 232 WebIDBDatabaseImpl* connection) { | 247 WebIDBDatabaseImpl* connection) { |
| 248 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 233 // May not be in the map if connection was forced to close | 249 // May not be in the map if connection was forced to close |
| 234 if (connections_.find(origin_url) == connections_.end() || | 250 if (connections_.find(origin_url) == connections_.end() || |
| 235 connections_[origin_url].count(connection) != 1) | 251 connections_[origin_url].count(connection) != 1) |
| 236 return; | 252 return; |
| 237 if (quota_manager_proxy()) { | 253 if (quota_manager_proxy()) { |
| 238 quota_manager_proxy()->NotifyStorageAccessed( | 254 quota_manager_proxy()->NotifyStorageAccessed( |
| 239 quota::QuotaClient::kIndexedDatabase, | 255 quota::QuotaClient::kIndexedDatabase, |
| 240 origin_url, | 256 origin_url, |
| 241 quota::kStorageTypeTemporary); | 257 quota::kStorageTypeTemporary); |
| 242 } | 258 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 269 return WouldBeOverQuota(origin_url, kOneAdditionalByte); | 285 return WouldBeOverQuota(origin_url, kOneAdditionalByte); |
| 270 } | 286 } |
| 271 | 287 |
| 272 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() { | 288 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() { |
| 273 return quota_manager_proxy_.get(); | 289 return quota_manager_proxy_.get(); |
| 274 } | 290 } |
| 275 | 291 |
| 276 IndexedDBContextImpl::~IndexedDBContextImpl() { | 292 IndexedDBContextImpl::~IndexedDBContextImpl() { |
| 277 WebIDBFactoryImpl* factory = idb_factory_.release(); | 293 WebIDBFactoryImpl* factory = idb_factory_.release(); |
| 278 if (factory) { | 294 if (factory) { |
| 279 if (!BrowserThread::DeleteSoon( | 295 if (!task_runner_->DeleteSoon(FROM_HERE, factory)) |
| 280 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, factory)) | |
| 281 delete factory; | 296 delete factory; |
| 282 } | 297 } |
| 283 | 298 |
| 284 if (data_path_.empty()) | 299 if (data_path_.empty()) |
| 285 return; | 300 return; |
| 286 | 301 |
| 287 if (force_keep_session_state_) | 302 if (force_keep_session_state_) |
| 288 return; | 303 return; |
| 289 | 304 |
| 290 bool has_session_only_databases = | 305 bool has_session_only_databases = |
| 291 special_storage_policy_.get() && | 306 special_storage_policy_.get() && |
| 292 special_storage_policy_->HasSessionOnlyOrigins(); | 307 special_storage_policy_->HasSessionOnlyOrigins(); |
| 293 | 308 |
| 294 // Clearning only session-only databases, and there are none. | 309 // Clearning only session-only databases, and there are none. |
| 295 if (!has_session_only_databases) | 310 if (!has_session_only_databases) |
| 296 return; | 311 return; |
| 297 | 312 |
| 298 // No WEBKIT thread here means we are running in a unit test where no clean | 313 TaskRunner()->PostTask( |
| 299 // up is needed. | |
| 300 BrowserThread::PostTask( | |
| 301 BrowserThread::WEBKIT_DEPRECATED, | |
| 302 FROM_HERE, | 314 FROM_HERE, |
| 303 base::Bind( | 315 base::Bind( |
| 304 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_)); | 316 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_)); |
| 305 } | 317 } |
| 306 | 318 |
| 307 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath( | 319 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath( |
| 308 const std::string& origin_id) const { | 320 const std::string& origin_id) const { |
| 309 DCHECK(!data_path_.empty()); | 321 DCHECK(!data_path_.empty()); |
| 310 return data_path_.AppendASCII(origin_id). | 322 return data_path_.AppendASCII(origin_id). |
| 311 AddExtension(kIndexedDBExtension). | 323 AddExtension(kIndexedDBExtension). |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 quota::QuotaStatusCode status, | 361 quota::QuotaStatusCode status, |
| 350 int64 usage, | 362 int64 usage, |
| 351 int64 quota) { | 363 int64 quota) { |
| 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 353 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort) | 365 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort) |
| 354 << "status was " << status; | 366 << "status was " << status; |
| 355 if (status == quota::kQuotaErrorAbort) { | 367 if (status == quota::kQuotaErrorAbort) { |
| 356 // We seem to no longer care to wait around for the answer. | 368 // We seem to no longer care to wait around for the answer. |
| 357 return; | 369 return; |
| 358 } | 370 } |
| 359 BrowserThread::PostTask(BrowserThread::WEBKIT_DEPRECATED, | 371 TaskRunner()->PostTask( |
| 360 FROM_HERE, | 372 FROM_HERE, |
| 361 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota, | 373 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota, |
| 362 this, | 374 this, |
| 363 origin_url, | 375 origin_url, |
| 364 usage, | 376 usage, |
| 365 quota)); | 377 quota)); |
| 366 } | 378 } |
| 367 | 379 |
| 368 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, | 380 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, |
| 369 int64 usage, | 381 int64 usage, |
| 370 int64 quota) { | 382 int64 quota) { |
| 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 383 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 372 space_available_map_[origin_url] = quota - usage; | 384 space_available_map_[origin_url] = quota - usage; |
| 373 } | 385 } |
| 374 | 386 |
| 375 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) { | 387 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) { |
| 376 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 388 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 389 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 378 if (quota_manager_proxy()) { | 390 if (quota_manager_proxy()) { |
| 379 BrowserThread::PostTask( | 391 BrowserThread::PostTask( |
| 380 BrowserThread::IO, | 392 BrowserThread::IO, |
| 381 FROM_HERE, | 393 FROM_HERE, |
| 382 base::Bind( | 394 base::Bind( |
| 383 &IndexedDBContextImpl::QueryAvailableQuota, this, origin_url)); | 395 &IndexedDBContextImpl::QueryAvailableQuota, this, origin_url)); |
| 384 } | 396 } |
| 385 return; | 397 return; |
| 386 } | 398 } |
| 387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 406 } | 418 } |
| 407 return origin_set_.get(); | 419 return origin_set_.get(); |
| 408 } | 420 } |
| 409 | 421 |
| 410 void IndexedDBContextImpl::ResetCaches() { | 422 void IndexedDBContextImpl::ResetCaches() { |
| 411 origin_set_.reset(); | 423 origin_set_.reset(); |
| 412 origin_size_map_.clear(); | 424 origin_size_map_.clear(); |
| 413 space_available_map_.clear(); | 425 space_available_map_.clear(); |
| 414 } | 426 } |
| 415 | 427 |
| 428 base::TaskRunner* IndexedDBContextImpl::TaskRunner() const { |
| 429 return task_runner_; |
| 430 } |
| 431 |
| 416 } // namespace content | 432 } // namespace content |
| OLD | NEW |