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 "webkit/browser/database/database_tracker.h" | 5 #include "webkit/browser/database/database_tracker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/file_enumerator.h" |
13 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
14 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
18 #include "sql/connection.h" | 19 #include "sql/connection.h" |
19 #include "sql/meta_table.h" | 20 #include "sql/meta_table.h" |
20 #include "sql/transaction.h" | 21 #include "sql/transaction.h" |
21 #include "third_party/sqlite/sqlite3.h" | 22 #include "third_party/sqlite/sqlite3.h" |
22 #include "webkit/base/origin_url_conversions.h" | 23 #include "webkit/base/origin_url_conversions.h" |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 base::FilePath origin_dir = db_dir_.Append(base::FilePath::FromWStringHack( | 408 base::FilePath origin_dir = db_dir_.Append(base::FilePath::FromWStringHack( |
408 UTF16ToWide(origin_identifier))); | 409 UTF16ToWide(origin_identifier))); |
409 | 410 |
410 // Create a temporary directory to move possibly still existing databases to, | 411 // Create a temporary directory to move possibly still existing databases to, |
411 // as we can't delete the origin directory on windows if it contains opened | 412 // as we can't delete the origin directory on windows if it contains opened |
412 // files. | 413 // files. |
413 base::FilePath new_origin_dir; | 414 base::FilePath new_origin_dir; |
414 file_util::CreateTemporaryDirInDir(db_dir_, | 415 file_util::CreateTemporaryDirInDir(db_dir_, |
415 kTemporaryDirectoryPrefix, | 416 kTemporaryDirectoryPrefix, |
416 &new_origin_dir); | 417 &new_origin_dir); |
417 file_util::FileEnumerator databases( | 418 base::FileEnumerator databases( |
418 origin_dir, | 419 origin_dir, |
419 false, | 420 false, |
420 file_util::FileEnumerator::FILES); | 421 base::FileEnumerator::FILES); |
421 for (base::FilePath database = databases.Next(); !database.empty(); | 422 for (base::FilePath database = databases.Next(); !database.empty(); |
422 database = databases.Next()) { | 423 database = databases.Next()) { |
423 base::FilePath new_file = new_origin_dir.Append(database.BaseName()); | 424 base::FilePath new_file = new_origin_dir.Append(database.BaseName()); |
424 file_util::Move(database, new_file); | 425 file_util::Move(database, new_file); |
425 } | 426 } |
426 file_util::Delete(origin_dir, true); | 427 file_util::Delete(origin_dir, true); |
427 file_util::Delete(new_origin_dir, true); // might fail on windows. | 428 file_util::Delete(new_origin_dir, true); // might fail on windows. |
428 | 429 |
429 databases_table_->DeleteOrigin(origin_identifier); | 430 databases_table_->DeleteOrigin(origin_identifier); |
430 | 431 |
(...skipping 21 matching lines...) Expand all Loading... |
452 | 453 |
453 bool DatabaseTracker::LazyInit() { | 454 bool DatabaseTracker::LazyInit() { |
454 if (!is_initialized_ && !shutting_down_) { | 455 if (!is_initialized_ && !shutting_down_) { |
455 DCHECK(!db_->is_open()); | 456 DCHECK(!db_->is_open()); |
456 DCHECK(!databases_table_.get()); | 457 DCHECK(!databases_table_.get()); |
457 DCHECK(!meta_table_.get()); | 458 DCHECK(!meta_table_.get()); |
458 | 459 |
459 // If there are left-over directories from failed deletion attempts, clean | 460 // If there are left-over directories from failed deletion attempts, clean |
460 // them up. | 461 // them up. |
461 if (file_util::DirectoryExists(db_dir_)) { | 462 if (file_util::DirectoryExists(db_dir_)) { |
462 file_util::FileEnumerator directories( | 463 base::FileEnumerator directories( |
463 db_dir_, | 464 db_dir_, |
464 false, | 465 false, |
465 file_util::FileEnumerator::DIRECTORIES, | 466 base::FileEnumerator::DIRECTORIES, |
466 kTemporaryDirectoryPattern); | 467 kTemporaryDirectoryPattern); |
467 for (base::FilePath directory = directories.Next(); !directory.empty(); | 468 for (base::FilePath directory = directories.Next(); !directory.empty(); |
468 directory = directories.Next()) { | 469 directory = directories.Next()) { |
469 file_util::Delete(directory, true); | 470 file_util::Delete(directory, true); |
470 } | 471 } |
471 } | 472 } |
472 | 473 |
473 // If the tracker database exists, but it's corrupt or doesn't | 474 // If the tracker database exists, but it's corrupt or doesn't |
474 // have a meta table, delete the database directory. | 475 // have a meta table, delete the database directory. |
475 const base::FilePath kTrackerDatabaseFullPath = | 476 const base::FilePath kTrackerDatabaseFullPath = |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 if (!db_tracker_thread_->BelongsToCurrentThread()) { | 871 if (!db_tracker_thread_->BelongsToCurrentThread()) { |
871 db_tracker_thread_->PostTask( | 872 db_tracker_thread_->PostTask( |
872 FROM_HERE, | 873 FROM_HERE, |
873 base::Bind(&DatabaseTracker::SetForceKeepSessionState, this)); | 874 base::Bind(&DatabaseTracker::SetForceKeepSessionState, this)); |
874 return; | 875 return; |
875 } | 876 } |
876 force_keep_session_state_ = true; | 877 force_keep_session_state_ = true; |
877 } | 878 } |
878 | 879 |
879 } // namespace webkit_database | 880 } // namespace webkit_database |
OLD | NEW |