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_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/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/webidbfactory_impl.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/indexed_db_info.h" | 19 #include "content/public/browser/indexed_db_info.h" |
19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
20 #include "third_party/WebKit/public/platform/WebCString.h" | 21 #include "third_party/WebKit/public/platform/WebCString.h" |
21 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" | 22 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" |
22 #include "third_party/WebKit/public/platform/WebIDBFactory.h" | 23 #include "third_party/WebKit/public/platform/WebIDBFactory.h" |
23 #include "third_party/WebKit/public/platform/WebString.h" | 24 #include "third_party/WebKit/public/platform/WebString.h" |
24 #include "webkit/base/file_path_string_conversions.h" | 25 #include "webkit/base/file_path_string_conversions.h" |
25 #include "webkit/base/origin_url_conversions.h" | 26 #include "webkit/base/origin_url_conversions.h" |
26 #include "webkit/browser/database/database_util.h" | 27 #include "webkit/browser/database/database_util.h" |
27 #include "webkit/browser/quota/quota_manager.h" | 28 #include "webkit/browser/quota/quota_manager.h" |
28 #include "webkit/browser/quota/special_storage_policy.h" | 29 #include "webkit/browser/quota/special_storage_policy.h" |
29 | 30 |
30 using webkit_database::DatabaseUtil; | 31 using webkit_database::DatabaseUtil; |
31 using WebKit::WebIDBDatabase; | 32 using WebKit::WebIDBDatabase; |
32 using WebKit::WebIDBFactory; | 33 using WebKit::WebIDBFactory; |
33 | 34 |
34 namespace content { | 35 namespace content { |
35 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = | 36 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = |
36 FILE_PATH_LITERAL("IndexedDB"); | 37 FILE_PATH_LITERAL("IndexedDB"); |
37 | 38 |
38 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] = | 39 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] = |
39 FILE_PATH_LITERAL(".leveldb"); | 40 FILE_PATH_LITERAL(".leveldb"); |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 void GetAllOriginsAndPaths( | 44 void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path, |
44 const base::FilePath& indexeddb_path, | 45 std::vector<GURL>* origins, |
45 std::vector<GURL>* origins, | 46 std::vector<base::FilePath>* file_paths) { |
46 std::vector<base::FilePath>* file_paths) { | |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
48 if (indexeddb_path.empty()) | 48 if (indexeddb_path.empty()) |
49 return; | 49 return; |
50 file_util::FileEnumerator file_enumerator(indexeddb_path, | 50 file_util::FileEnumerator file_enumerator( |
51 false, file_util::FileEnumerator::DIRECTORIES); | 51 indexeddb_path, false, file_util::FileEnumerator::DIRECTORIES); |
52 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 52 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
53 file_path = file_enumerator.Next()) { | 53 file_path = file_enumerator.Next()) { |
54 if (file_path.Extension() == IndexedDBContextImpl::kIndexedDBExtension) { | 54 if (file_path.Extension() == IndexedDBContextImpl::kIndexedDBExtension) { |
55 WebKit::WebString origin_id_webstring = | 55 WebKit::WebString origin_id_webstring = |
56 webkit_base::FilePathToWebString(file_path.BaseName()); | 56 webkit_base::FilePathToWebString(file_path.BaseName()); |
57 origins->push_back( | 57 origins->push_back( |
58 webkit_base::GetOriginURLFromIdentifier(origin_id_webstring)); | 58 webkit_base::GetOriginURLFromIdentifier(origin_id_webstring)); |
59 if (file_paths) | 59 if (file_paths) |
60 file_paths->push_back(file_path); | 60 file_paths->push_back(file_path); |
61 } | 61 } |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 // Deletes session-only databases. | 65 // Deletes session-only databases. |
66 void ClearSessionOnlyOrigins( | 66 void ClearSessionOnlyOrigins( |
67 const base::FilePath& indexeddb_path, | 67 const base::FilePath& indexeddb_path, |
68 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { | 68 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
70 std::vector<GURL> origins; | 70 std::vector<GURL> origins; |
71 std::vector<base::FilePath> file_paths; | 71 std::vector<base::FilePath> file_paths; |
72 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); | 72 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); |
73 DCHECK_EQ(origins.size(), file_paths.size()); | 73 DCHECK_EQ(origins.size(), file_paths.size()); |
74 std::vector<base::FilePath>::const_iterator file_path_iter = | 74 std::vector<base::FilePath>::const_iterator file_path_iter = |
75 file_paths.begin(); | 75 file_paths.begin(); |
76 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 76 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
77 iter != origins.end(); ++iter, ++file_path_iter) { | 77 iter != origins.end(); |
| 78 ++iter, ++file_path_iter) { |
78 if (!special_storage_policy->IsStorageSessionOnly(*iter)) | 79 if (!special_storage_policy->IsStorageSessionOnly(*iter)) |
79 continue; | 80 continue; |
80 if (special_storage_policy->IsStorageProtected(*iter)) | 81 if (special_storage_policy->IsStorageProtected(*iter)) |
81 continue; | 82 continue; |
82 file_util::Delete(*file_path_iter, true); | 83 file_util::Delete(*file_path_iter, true); |
83 } | 84 } |
84 } | 85 } |
85 | 86 |
86 } // namespace | 87 } // namespace |
87 | 88 |
(...skipping 13 matching lines...) Expand all Loading... |
101 new IndexedDBQuotaClient(webkit_thread_loop, this)); | 102 new IndexedDBQuotaClient(webkit_thread_loop, this)); |
102 } | 103 } |
103 } | 104 } |
104 | 105 |
105 WebIDBFactory* IndexedDBContextImpl::GetIDBFactory() { | 106 WebIDBFactory* IndexedDBContextImpl::GetIDBFactory() { |
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
107 if (!idb_factory_) { | 108 if (!idb_factory_) { |
108 // Prime our cache of origins with existing databases so we can | 109 // Prime our cache of origins with existing databases so we can |
109 // detect when dbs are newly created. | 110 // detect when dbs are newly created. |
110 GetOriginSet(); | 111 GetOriginSet(); |
111 idb_factory_.reset(WebIDBFactory::create()); | 112 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewIndexedDB)) |
| 113 idb_factory_.reset(new content::WebIDBFactoryImpl()); |
| 114 else |
| 115 idb_factory_.reset(WebIDBFactory::create()); |
112 } | 116 } |
113 return idb_factory_.get(); | 117 return idb_factory_.get(); |
114 } | 118 } |
115 | 119 |
116 std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() { | 120 std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() { |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
118 std::vector<GURL> origins; | 122 std::vector<GURL> origins; |
119 std::set<GURL>* origins_set = GetOriginSet(); | 123 std::set<GURL>* origins_set = GetOriginSet(); |
120 for (std::set<GURL>::const_iterator iter = origins_set->begin(); | 124 for (std::set<GURL>::const_iterator iter = origins_set->begin(); |
121 iter != origins_set->end(); ++iter) { | 125 iter != origins_set->end(); |
| 126 ++iter) { |
122 origins.push_back(*iter); | 127 origins.push_back(*iter); |
123 } | 128 } |
124 return origins; | 129 return origins; |
125 } | 130 } |
126 | 131 |
127 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { | 132 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { |
128 std::vector<GURL> origins = GetAllOrigins(); | 133 std::vector<GURL> origins = GetAllOrigins(); |
129 std::vector<IndexedDBInfo> result; | 134 std::vector<IndexedDBInfo> result; |
130 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 135 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
131 iter != origins.end(); ++iter) { | 136 iter != origins.end(); |
| 137 ++iter) { |
132 const GURL& origin_url = *iter; | 138 const GURL& origin_url = *iter; |
133 | 139 |
134 base::FilePath idb_directory = GetFilePath(origin_url); | 140 base::FilePath idb_directory = GetFilePath(origin_url); |
135 result.push_back(IndexedDBInfo(origin_url, | 141 result.push_back(IndexedDBInfo(origin_url, |
136 GetOriginDiskUsage(origin_url), | 142 GetOriginDiskUsage(origin_url), |
137 GetOriginLastModified(origin_url), | 143 GetOriginLastModified(origin_url), |
138 idb_directory)); | 144 idb_directory)); |
139 } | 145 } |
140 return result; | 146 return result; |
141 } | 147 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 201 } |
196 } | 202 } |
197 | 203 |
198 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { | 204 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { |
199 base::string16 origin_id = | 205 base::string16 origin_id = |
200 webkit_base::GetOriginIdentifierFromURL(origin_url); | 206 webkit_base::GetOriginIdentifierFromURL(origin_url); |
201 return GetIndexedDBFilePath(origin_id); | 207 return GetIndexedDBFilePath(origin_id); |
202 } | 208 } |
203 | 209 |
204 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 210 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
205 const string16& origin_id) const { | 211 const string16& origin_id) const { |
206 return GetIndexedDBFilePath(origin_id); | 212 return GetIndexedDBFilePath(origin_id); |
207 } | 213 } |
208 | 214 |
209 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, | 215 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, |
210 WebIDBDatabase* connection) { | 216 WebIDBDatabase* connection) { |
211 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); | 217 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); |
212 if (quota_manager_proxy()) { | 218 if (quota_manager_proxy()) { |
213 quota_manager_proxy()->NotifyStorageAccessed( | 219 quota_manager_proxy()->NotifyStorageAccessed( |
214 quota::QuotaClient::kIndexedDatabase, origin_url, | 220 quota::QuotaClient::kIndexedDatabase, |
| 221 origin_url, |
215 quota::kStorageTypeTemporary); | 222 quota::kStorageTypeTemporary); |
216 } | 223 } |
217 connections_[origin_url].insert(connection); | 224 connections_[origin_url].insert(connection); |
218 if (AddToOriginSet(origin_url)) { | 225 if (AddToOriginSet(origin_url)) { |
219 // A newly created db, notify the quota system. | 226 // A newly created db, notify the quota system. |
220 QueryDiskAndUpdateQuotaUsage(origin_url); | 227 QueryDiskAndUpdateQuotaUsage(origin_url); |
221 } else { | 228 } else { |
222 EnsureDiskUsageCacheInitialized(origin_url); | 229 EnsureDiskUsageCacheInitialized(origin_url); |
223 } | 230 } |
224 QueryAvailableQuota(origin_url); | 231 QueryAvailableQuota(origin_url); |
225 } | 232 } |
226 | 233 |
227 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, | 234 void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url, |
228 WebIDBDatabase* connection) { | 235 WebIDBDatabase* connection) { |
229 // May not be in the map if connection was forced to close | 236 // May not be in the map if connection was forced to close |
230 if (connections_.find(origin_url) == connections_.end() || | 237 if (connections_.find(origin_url) == connections_.end() || |
231 connections_[origin_url].count(connection) != 1) | 238 connections_[origin_url].count(connection) != 1) |
232 return; | 239 return; |
233 if (quota_manager_proxy()) { | 240 if (quota_manager_proxy()) { |
234 quota_manager_proxy()->NotifyStorageAccessed( | 241 quota_manager_proxy()->NotifyStorageAccessed( |
235 quota::QuotaClient::kIndexedDatabase, origin_url, | 242 quota::QuotaClient::kIndexedDatabase, |
| 243 origin_url, |
236 quota::kStorageTypeTemporary); | 244 quota::kStorageTypeTemporary); |
237 } | 245 } |
238 connections_[origin_url].erase(connection); | 246 connections_[origin_url].erase(connection); |
239 if (connections_[origin_url].size() == 0) { | 247 if (connections_[origin_url].size() == 0) { |
240 QueryDiskAndUpdateQuotaUsage(origin_url); | 248 QueryDiskAndUpdateQuotaUsage(origin_url); |
241 connections_.erase(origin_url); | 249 connections_.erase(origin_url); |
242 } | 250 } |
243 } | 251 } |
244 | 252 |
245 void IndexedDBContextImpl::TransactionComplete(const GURL& origin_url) { | 253 void IndexedDBContextImpl::TransactionComplete(const GURL& origin_url) { |
(...skipping 18 matching lines...) Expand all Loading... |
264 return WouldBeOverQuota(origin_url, kOneAdditionalByte); | 272 return WouldBeOverQuota(origin_url, kOneAdditionalByte); |
265 } | 273 } |
266 | 274 |
267 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() { | 275 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() { |
268 return quota_manager_proxy_; | 276 return quota_manager_proxy_; |
269 } | 277 } |
270 | 278 |
271 IndexedDBContextImpl::~IndexedDBContextImpl() { | 279 IndexedDBContextImpl::~IndexedDBContextImpl() { |
272 WebKit::WebIDBFactory* factory = idb_factory_.release(); | 280 WebKit::WebIDBFactory* factory = idb_factory_.release(); |
273 if (factory) { | 281 if (factory) { |
274 if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT_DEPRECATED, | 282 if (!BrowserThread::DeleteSoon( |
275 FROM_HERE, factory)) | 283 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, factory)) |
276 delete factory; | 284 delete factory; |
277 } | 285 } |
278 | 286 |
279 if (data_path_.empty()) | 287 if (data_path_.empty()) |
280 return; | 288 return; |
281 | 289 |
282 if (force_keep_session_state_) | 290 if (force_keep_session_state_) |
283 return; | 291 return; |
284 | 292 |
285 bool has_session_only_databases = | 293 bool has_session_only_databases = |
286 special_storage_policy_.get() && | 294 special_storage_policy_.get() && |
287 special_storage_policy_->HasSessionOnlyOrigins(); | 295 special_storage_policy_->HasSessionOnlyOrigins(); |
288 | 296 |
289 // Clearning only session-only databases, and there are none. | 297 // Clearning only session-only databases, and there are none. |
290 if (!has_session_only_databases) | 298 if (!has_session_only_databases) |
291 return; | 299 return; |
292 | 300 |
293 // No WEBKIT thread here means we are running in a unit test where no clean | 301 // No WEBKIT thread here means we are running in a unit test where no clean |
294 // up is needed. | 302 // up is needed. |
295 BrowserThread::PostTask( | 303 BrowserThread::PostTask( |
296 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 304 BrowserThread::WEBKIT_DEPRECATED, |
297 base::Bind(&ClearSessionOnlyOrigins, | 305 FROM_HERE, |
298 data_path_, | 306 base::Bind( |
299 special_storage_policy_)); | 307 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_)); |
300 } | 308 } |
301 | 309 |
302 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath( | 310 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath( |
303 const string16& origin_id) const { | 311 const string16& origin_id) const { |
304 DCHECK(!data_path_.empty()); | 312 DCHECK(!data_path_.empty()); |
305 base::FilePath::StringType id = | 313 base::FilePath::StringType id = webkit_base::WebStringToFilePathString( |
306 webkit_base::WebStringToFilePathString(origin_id).append( | 314 origin_id).append(FILE_PATH_LITERAL(".indexeddb")); |
307 FILE_PATH_LITERAL(".indexeddb")); | |
308 return data_path_.Append(id.append(kIndexedDBExtension)); | 315 return data_path_.Append(id.append(kIndexedDBExtension)); |
309 } | 316 } |
310 | 317 |
311 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { | 318 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { |
312 if (data_path_.empty()) | 319 if (data_path_.empty()) |
313 return 0; | 320 return 0; |
314 base::string16 origin_id = | 321 base::string16 origin_id = |
315 webkit_base::GetOriginIdentifierFromURL(origin_url); | 322 webkit_base::GetOriginIdentifierFromURL(origin_url); |
316 base::FilePath file_path = GetIndexedDBFilePath(origin_id); | 323 base::FilePath file_path = GetIndexedDBFilePath(origin_id); |
317 return file_util::ComputeDirectorySize(file_path); | 324 return file_util::ComputeDirectorySize(file_path); |
318 } | 325 } |
319 | 326 |
320 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( | 327 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( |
321 const GURL& origin_url) { | 328 const GURL& origin_url) { |
322 if (origin_size_map_.find(origin_url) == origin_size_map_.end()) | 329 if (origin_size_map_.find(origin_url) == origin_size_map_.end()) |
323 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); | 330 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); |
324 } | 331 } |
325 | 332 |
326 void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage( | 333 void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage( |
327 const GURL& origin_url) { | 334 const GURL& origin_url) { |
328 int64 former_disk_usage = origin_size_map_[origin_url]; | 335 int64 former_disk_usage = origin_size_map_[origin_url]; |
329 int64 current_disk_usage = ReadUsageFromDisk(origin_url); | 336 int64 current_disk_usage = ReadUsageFromDisk(origin_url); |
330 int64 difference = current_disk_usage - former_disk_usage; | 337 int64 difference = current_disk_usage - former_disk_usage; |
331 if (difference) { | 338 if (difference) { |
332 origin_size_map_[origin_url] = current_disk_usage; | 339 origin_size_map_[origin_url] = current_disk_usage; |
333 // quota_manager_proxy() is NULL in unit tests. | 340 // quota_manager_proxy() is NULL in unit tests. |
334 if (quota_manager_proxy()) | 341 if (quota_manager_proxy()) { |
335 quota_manager_proxy()->NotifyStorageModified( | 342 quota_manager_proxy()->NotifyStorageModified( |
336 quota::QuotaClient::kIndexedDatabase, | 343 quota::QuotaClient::kIndexedDatabase, |
337 origin_url, | 344 origin_url, |
338 quota::kStorageTypeTemporary, | 345 quota::kStorageTypeTemporary, |
339 difference); | 346 difference); |
| 347 } |
340 } | 348 } |
341 } | 349 } |
342 | 350 |
343 void IndexedDBContextImpl::GotUsageAndQuota(const GURL& origin_url, | 351 void IndexedDBContextImpl::GotUsageAndQuota(const GURL& origin_url, |
344 quota::QuotaStatusCode status, | 352 quota::QuotaStatusCode status, |
345 int64 usage, int64 quota) { | 353 int64 usage, |
| 354 int64 quota) { |
346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
347 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort) | 356 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort) |
348 << "status was " << status; | 357 << "status was " << status; |
349 if (status == quota::kQuotaErrorAbort) { | 358 if (status == quota::kQuotaErrorAbort) { |
350 // We seem to no longer care to wait around for the answer. | 359 // We seem to no longer care to wait around for the answer. |
351 return; | 360 return; |
352 } | 361 } |
353 BrowserThread::PostTask( | 362 BrowserThread::PostTask(BrowserThread::WEBKIT_DEPRECATED, |
354 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 363 FROM_HERE, |
355 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota, this, origin_url, | 364 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota, |
356 usage, quota)); | 365 this, |
| 366 origin_url, |
| 367 usage, |
| 368 quota)); |
357 } | 369 } |
358 | 370 |
359 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, int64 usage, | 371 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, |
| 372 int64 usage, |
360 int64 quota) { | 373 int64 quota) { |
361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
362 space_available_map_[origin_url] = quota - usage; | 375 space_available_map_[origin_url] = quota - usage; |
363 } | 376 } |
364 | 377 |
365 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) { | 378 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) { |
366 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 379 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
368 if (quota_manager_proxy()) | 381 if (quota_manager_proxy()) { |
369 BrowserThread::PostTask( | 382 BrowserThread::PostTask( |
370 BrowserThread::IO, FROM_HERE, | 383 BrowserThread::IO, |
371 base::Bind(&IndexedDBContextImpl::QueryAvailableQuota, this, | 384 FROM_HERE, |
372 origin_url)); | 385 base::Bind( |
| 386 &IndexedDBContextImpl::QueryAvailableQuota, this, origin_url)); |
| 387 } |
373 return; | 388 return; |
374 } | 389 } |
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
376 if (!quota_manager_proxy() || !quota_manager_proxy()->quota_manager()) | 391 if (!quota_manager_proxy() || !quota_manager_proxy()->quota_manager()) |
377 return; | 392 return; |
378 quota_manager_proxy()->quota_manager()->GetUsageAndQuota( | 393 quota_manager_proxy()->quota_manager()->GetUsageAndQuota( |
379 origin_url, | 394 origin_url, |
380 quota::kStorageTypeTemporary, | 395 quota::kStorageTypeTemporary, |
381 base::Bind(&IndexedDBContextImpl::GotUsageAndQuota, this, origin_url)); | 396 base::Bind(&IndexedDBContextImpl::GotUsageAndQuota, this, origin_url)); |
382 } | 397 } |
383 | 398 |
384 std::set<GURL>* IndexedDBContextImpl::GetOriginSet() { | 399 std::set<GURL>* IndexedDBContextImpl::GetOriginSet() { |
385 if (!origin_set_) { | 400 if (!origin_set_) { |
386 origin_set_.reset(new std::set<GURL>); | 401 origin_set_.reset(new std::set<GURL>); |
387 std::vector<GURL> origins; | 402 std::vector<GURL> origins; |
388 GetAllOriginsAndPaths(data_path_, &origins, NULL); | 403 GetAllOriginsAndPaths(data_path_, &origins, NULL); |
389 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 404 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
390 iter != origins.end(); ++iter) { | 405 iter != origins.end(); |
| 406 ++iter) { |
391 origin_set_->insert(*iter); | 407 origin_set_->insert(*iter); |
392 } | 408 } |
393 } | 409 } |
394 return origin_set_.get(); | 410 return origin_set_.get(); |
395 } | 411 } |
396 | 412 |
397 void IndexedDBContextImpl::ResetCaches() { | 413 void IndexedDBContextImpl::ResetCaches() { |
398 origin_set_.reset(); | 414 origin_set_.reset(); |
399 origin_size_map_.clear(); | 415 origin_size_map_.clear(); |
400 space_available_map_.clear(); | 416 space_available_map_.clear(); |
401 } | 417 } |
402 | 418 |
403 } // namespace content | 419 } // namespace content |
OLD | NEW |