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/message_loop/message_loop_proxy.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 "content/browser/indexed_db/indexed_db_quota_client.h" | 17 #include "content/browser/indexed_db/indexed_db_quota_client.h" |
18 #include "content/browser/indexed_db/webidbdatabase_impl.h" | 18 #include "content/browser/indexed_db/webidbdatabase_impl.h" |
19 #include "content/browser/indexed_db/webidbfactory_impl.h" | 19 #include "content/browser/indexed_db/webidbfactory_impl.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/indexed_db_info.h" | 21 #include "content/public/browser/indexed_db_info.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "third_party/WebKit/public/platform/WebString.h" | 23 #include "third_party/WebKit/public/platform/WebString.h" |
24 #include "webkit/base/file_path_string_conversions.h" | 24 #include "webkit/base/file_path_string_conversions.h" |
25 #include "webkit/base/origin_url_conversions.h" | |
26 #include "webkit/browser/database/database_util.h" | 25 #include "webkit/browser/database/database_util.h" |
27 #include "webkit/browser/quota/quota_manager.h" | 26 #include "webkit/browser/quota/quota_manager.h" |
28 #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" |
29 | 29 |
30 using webkit_database::DatabaseUtil; | 30 using webkit_database::DatabaseUtil; |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = | 33 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = |
34 FILE_PATH_LITERAL("IndexedDB"); | 34 FILE_PATH_LITERAL("IndexedDB"); |
35 | 35 |
36 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] = | 36 static const base::FilePath::CharType kIndexedDBExtension[] = |
| 37 FILE_PATH_LITERAL(".indexeddb"); |
| 38 |
| 39 static const base::FilePath::CharType kLevelDBExtension[] = |
37 FILE_PATH_LITERAL(".leveldb"); | 40 FILE_PATH_LITERAL(".leveldb"); |
38 | 41 |
39 namespace { | 42 namespace { |
40 | 43 |
41 void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path, | 44 void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path, |
42 std::vector<GURL>* origins, | 45 std::vector<GURL>* origins, |
43 std::vector<base::FilePath>* file_paths) { | 46 std::vector<base::FilePath>* file_paths) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
45 if (indexeddb_path.empty()) | 48 if (indexeddb_path.empty()) |
46 return; | 49 return; |
47 base::FileEnumerator file_enumerator( | 50 base::FileEnumerator file_enumerator( |
48 indexeddb_path, false, base::FileEnumerator::DIRECTORIES); | 51 indexeddb_path, false, base::FileEnumerator::DIRECTORIES); |
49 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 52 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
50 file_path = file_enumerator.Next()) { | 53 file_path = file_enumerator.Next()) { |
51 if (file_path.Extension() == IndexedDBContextImpl::kIndexedDBExtension) { | 54 if (file_path.Extension() == kLevelDBExtension && |
52 std::string origin_id = file_path.BaseName().MaybeAsASCII(); | 55 file_path.RemoveExtension().Extension() == kIndexedDBExtension) { |
53 origins->push_back(webkit_base::GetOriginURLFromIdentifier(origin_id)); | 56 std::string origin_id = file_path.BaseName().RemoveExtension() |
| 57 .RemoveExtension().MaybeAsASCII(); |
| 58 origins->push_back(webkit_database::GetOriginFromIdentifier(origin_id)); |
54 if (file_paths) | 59 if (file_paths) |
55 file_paths->push_back(file_path); | 60 file_paths->push_back(file_path); |
56 } | 61 } |
57 } | 62 } |
58 } | 63 } |
59 | 64 |
60 // Deletes session-only databases. | 65 // Deletes session-only databases. |
61 void ClearSessionOnlyOrigins( | 66 void ClearSessionOnlyOrigins( |
62 const base::FilePath& indexeddb_path, | 67 const base::FilePath& indexeddb_path, |
63 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { | 68 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 connections.erase(it++); | 193 connections.erase(it++); |
189 db->forceClose(); | 194 db->forceClose(); |
190 } | 195 } |
191 DCHECK_EQ(connections_[origin_url].size(), 0UL); | 196 DCHECK_EQ(connections_[origin_url].size(), 0UL); |
192 connections_.erase(origin_url); | 197 connections_.erase(origin_url); |
193 } | 198 } |
194 } | 199 } |
195 | 200 |
196 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { | 201 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { |
197 std::string origin_id = | 202 std::string origin_id = |
198 webkit_base::GetOriginIdentifierFromURL(origin_url); | 203 webkit_database::GetIdentifierFromOrigin(origin_url); |
199 return GetIndexedDBFilePath(origin_id); | 204 return GetIndexedDBFilePath(origin_id); |
200 } | 205 } |
201 | 206 |
202 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 207 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
203 const std::string& origin_id) const { | 208 const std::string& origin_id) const { |
204 return GetIndexedDBFilePath(origin_id); | 209 return GetIndexedDBFilePath(origin_id); |
205 } | 210 } |
206 | 211 |
207 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, | 212 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, |
208 WebIDBDatabaseImpl* connection) { | 213 WebIDBDatabaseImpl* connection) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 BrowserThread::WEBKIT_DEPRECATED, | 301 BrowserThread::WEBKIT_DEPRECATED, |
297 FROM_HERE, | 302 FROM_HERE, |
298 base::Bind( | 303 base::Bind( |
299 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_)); | 304 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_)); |
300 } | 305 } |
301 | 306 |
302 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath( | 307 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath( |
303 const std::string& origin_id) const { | 308 const std::string& origin_id) const { |
304 DCHECK(!data_path_.empty()); | 309 DCHECK(!data_path_.empty()); |
305 return data_path_.AppendASCII(origin_id). | 310 return data_path_.AppendASCII(origin_id). |
306 AddExtension(FILE_PATH_LITERAL(".indexeddb")). | 311 AddExtension(kIndexedDBExtension). |
307 AddExtension(kIndexedDBExtension); | 312 AddExtension(kLevelDBExtension); |
308 } | 313 } |
309 | 314 |
310 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { | 315 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { |
311 if (data_path_.empty()) | 316 if (data_path_.empty()) |
312 return 0; | 317 return 0; |
313 std::string origin_id = | 318 std::string origin_id = |
314 webkit_base::GetOriginIdentifierFromURL(origin_url); | 319 webkit_database::GetIdentifierFromOrigin(origin_url); |
315 base::FilePath file_path = GetIndexedDBFilePath(origin_id); | 320 base::FilePath file_path = GetIndexedDBFilePath(origin_id); |
316 return file_util::ComputeDirectorySize(file_path); | 321 return file_util::ComputeDirectorySize(file_path); |
317 } | 322 } |
318 | 323 |
319 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( | 324 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( |
320 const GURL& origin_url) { | 325 const GURL& origin_url) { |
321 if (origin_size_map_.find(origin_url) == origin_size_map_.end()) | 326 if (origin_size_map_.find(origin_url) == origin_size_map_.end()) |
322 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); | 327 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); |
323 } | 328 } |
324 | 329 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 return origin_set_.get(); | 407 return origin_set_.get(); |
403 } | 408 } |
404 | 409 |
405 void IndexedDBContextImpl::ResetCaches() { | 410 void IndexedDBContextImpl::ResetCaches() { |
406 origin_set_.reset(); | 411 origin_set_.reset(); |
407 origin_size_map_.clear(); | 412 origin_size_map_.clear(); |
408 space_available_map_.clear(); | 413 space_available_map_.clear(); |
409 } | 414 } |
410 | 415 |
411 } // namespace content | 416 } // namespace content |
OLD | NEW |