Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: webkit/database/database_tracker.cc

Issue 13165005: Move FileEnumerator to its own file, do some refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge, fixes Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/valgrind/tsan/suppressions.txt ('k') | webkit/dom_storage/dom_storage_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
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/database/database_quota_client.h" 23 #include "webkit/database/database_quota_client.h"
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 base::FilePath origin_dir = db_dir_.Append(base::FilePath::FromWStringHack( 406 base::FilePath origin_dir = db_dir_.Append(base::FilePath::FromWStringHack(
406 UTF16ToWide(origin_identifier))); 407 UTF16ToWide(origin_identifier)));
407 408
408 // Create a temporary directory to move possibly still existing databases to, 409 // Create a temporary directory to move possibly still existing databases to,
409 // as we can't delete the origin directory on windows if it contains opened 410 // as we can't delete the origin directory on windows if it contains opened
410 // files. 411 // files.
411 base::FilePath new_origin_dir; 412 base::FilePath new_origin_dir;
412 file_util::CreateTemporaryDirInDir(db_dir_, 413 file_util::CreateTemporaryDirInDir(db_dir_,
413 kTemporaryDirectoryPrefix, 414 kTemporaryDirectoryPrefix,
414 &new_origin_dir); 415 &new_origin_dir);
415 file_util::FileEnumerator databases( 416 base::FileEnumerator databases(
416 origin_dir, 417 origin_dir,
417 false, 418 false,
418 file_util::FileEnumerator::FILES); 419 base::FileEnumerator::FILES);
419 for (base::FilePath database = databases.Next(); !database.empty(); 420 for (base::FilePath database = databases.Next(); !database.empty();
420 database = databases.Next()) { 421 database = databases.Next()) {
421 base::FilePath new_file = new_origin_dir.Append(database.BaseName()); 422 base::FilePath new_file = new_origin_dir.Append(database.BaseName());
422 file_util::Move(database, new_file); 423 file_util::Move(database, new_file);
423 } 424 }
424 file_util::Delete(origin_dir, true); 425 file_util::Delete(origin_dir, true);
425 file_util::Delete(new_origin_dir, true); // might fail on windows. 426 file_util::Delete(new_origin_dir, true); // might fail on windows.
426 427
427 databases_table_->DeleteOrigin(origin_identifier); 428 databases_table_->DeleteOrigin(origin_identifier);
428 429
(...skipping 21 matching lines...) Expand all
450 451
451 bool DatabaseTracker::LazyInit() { 452 bool DatabaseTracker::LazyInit() {
452 if (!is_initialized_ && !shutting_down_) { 453 if (!is_initialized_ && !shutting_down_) {
453 DCHECK(!db_->is_open()); 454 DCHECK(!db_->is_open());
454 DCHECK(!databases_table_.get()); 455 DCHECK(!databases_table_.get());
455 DCHECK(!meta_table_.get()); 456 DCHECK(!meta_table_.get());
456 457
457 // If there are left-over directories from failed deletion attempts, clean 458 // If there are left-over directories from failed deletion attempts, clean
458 // them up. 459 // them up.
459 if (file_util::DirectoryExists(db_dir_)) { 460 if (file_util::DirectoryExists(db_dir_)) {
460 file_util::FileEnumerator directories( 461 base::FileEnumerator directories(
461 db_dir_, 462 db_dir_,
462 false, 463 false,
463 file_util::FileEnumerator::DIRECTORIES, 464 base::FileEnumerator::DIRECTORIES,
464 kTemporaryDirectoryPattern); 465 kTemporaryDirectoryPattern);
465 for (base::FilePath directory = directories.Next(); !directory.empty(); 466 for (base::FilePath directory = directories.Next(); !directory.empty();
466 directory = directories.Next()) { 467 directory = directories.Next()) {
467 file_util::Delete(directory, true); 468 file_util::Delete(directory, true);
468 } 469 }
469 } 470 }
470 471
471 // If the tracker database exists, but it's corrupt or doesn't 472 // If the tracker database exists, but it's corrupt or doesn't
472 // have a meta table, delete the database directory. 473 // have a meta table, delete the database directory.
473 const base::FilePath kTrackerDatabaseFullPath = 474 const base::FilePath kTrackerDatabaseFullPath =
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 if (!db_tracker_thread_->BelongsToCurrentThread()) { 870 if (!db_tracker_thread_->BelongsToCurrentThread()) {
870 db_tracker_thread_->PostTask( 871 db_tracker_thread_->PostTask(
871 FROM_HERE, 872 FROM_HERE,
872 base::Bind(&DatabaseTracker::SetForceKeepSessionState, this)); 873 base::Bind(&DatabaseTracker::SetForceKeepSessionState, this));
873 return; 874 return;
874 } 875 }
875 force_keep_session_state_ = true; 876 force_keep_session_state_ = true;
876 } 877 }
877 878
878 } // namespace webkit_database 879 } // namespace webkit_database
OLDNEW
« no previous file with comments | « tools/valgrind/tsan/suppressions.txt ('k') | webkit/dom_storage/dom_storage_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698