OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/database/database_tracker.h" | 5 #include "webkit/database/database_tracker.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/sql/connection.h" | 9 #include "app/sql/connection.h" |
10 #include "app/sql/meta_table.h" | 10 #include "app/sql/meta_table.h" |
11 #include "app/sql/statement.h" | 11 #include "app/sql/statement.h" |
12 #include "app/sql/transaction.h" | 12 #include "app/sql/transaction.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
| 18 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
17 #include "webkit/database/databases_table.h" | 19 #include "webkit/database/databases_table.h" |
18 #include "webkit/database/quota_table.h" | 20 #include "webkit/database/quota_table.h" |
| 21 #include "webkit/glue/webkit_glue.h" |
19 | 22 |
20 namespace webkit_database { | 23 namespace webkit_database { |
21 | 24 |
22 const FilePath::CharType kDatabaseDirectoryName[] = | 25 const FilePath::CharType kDatabaseDirectoryName[] = |
23 FILE_PATH_LITERAL("databases"); | 26 FILE_PATH_LITERAL("databases"); |
24 const FilePath::CharType kTrackerDatabaseFileName[] = | 27 const FilePath::CharType kTrackerDatabaseFileName[] = |
25 FILE_PATH_LITERAL("Databases.db"); | 28 FILE_PATH_LITERAL("Databases.db"); |
26 const int kCurrentVersion = 2; | 29 const int kCurrentVersion = 2; |
27 const int kCompatibleVersion = 1; | 30 const int kCompatibleVersion = 1; |
28 const int64 kDefaultExtensionQuota = 50 * 1024 * 1024; | 31 const int64 kDefaultExtensionQuota = 50 * 1024 * 1024; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 int64 DatabaseTracker::UpdateCachedDatabaseFileSize( | 327 int64 DatabaseTracker::UpdateCachedDatabaseFileSize( |
325 const string16& origin_identifier, | 328 const string16& origin_identifier, |
326 const string16& database_name) { | 329 const string16& database_name) { |
327 int64 new_size = GetDBFileSize(origin_identifier, database_name); | 330 int64 new_size = GetDBFileSize(origin_identifier, database_name); |
328 CachedOriginInfo* origin_info = GetCachedOriginInfo(origin_identifier); | 331 CachedOriginInfo* origin_info = GetCachedOriginInfo(origin_identifier); |
329 if (origin_info) | 332 if (origin_info) |
330 origin_info->SetDatabaseSize(database_name, new_size); | 333 origin_info->SetDatabaseSize(database_name, new_size); |
331 return new_size; | 334 return new_size; |
332 } | 335 } |
333 | 336 |
| 337 // static |
| 338 void DatabaseTracker::ClearLocalState(const FilePath& profile_path, |
| 339 const char* url_scheme_to_be_skipped) { |
| 340 FilePath db_dir = profile_path.Append(FilePath(kDatabaseDirectoryName)); |
| 341 FilePath db_tracker = db_dir.Append(FilePath(kTrackerDatabaseFileName)); |
| 342 if (file_util::DirectoryExists(db_dir) && |
| 343 file_util::PathExists(db_tracker)) { |
| 344 scoped_ptr<sql::Connection> db_(new sql::Connection); |
| 345 if (!db_->Open(db_tracker) || |
| 346 !db_->DoesTableExist("Databases")) { |
| 347 db_->Close(); |
| 348 file_util::Delete(db_dir, true); |
| 349 return; |
| 350 } else { |
| 351 sql::Statement delete_statement(db_->GetCachedStatement( |
| 352 SQL_FROM_HERE, "DELETE FROM Databases WHERE origin NOT LIKE ?")); |
| 353 std::string filter(url_scheme_to_be_skipped); |
| 354 filter += "_%"; |
| 355 delete_statement.BindString(0, filter); |
| 356 if (!delete_statement.Run()) { |
| 357 db_->Close(); |
| 358 file_util::Delete(db_dir, true); |
| 359 return; |
| 360 } |
| 361 } |
| 362 } |
| 363 file_util::FileEnumerator file_enumerator(db_dir, false, |
| 364 file_util::FileEnumerator::DIRECTORIES); |
| 365 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| 366 file_path = file_enumerator.Next()) { |
| 367 if (file_path.BaseName() != FilePath(kTrackerDatabaseFileName)) { |
| 368 scoped_ptr<WebKit::WebSecurityOrigin> web_security_origin( |
| 369 WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( |
| 370 webkit_glue::FilePathToWebString(file_path.BaseName()))); |
| 371 if (!EqualsASCII(web_security_origin->protocol(), |
| 372 url_scheme_to_be_skipped)) |
| 373 file_util::Delete(file_path, true); |
| 374 } |
| 375 } |
| 376 } |
| 377 |
334 } // namespace webkit_database | 378 } // namespace webkit_database |
OLD | NEW |