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