OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/browser/fileapi/sandbox_isolated_origin_database.h" |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" |
| 9 #include "webkit/browser/fileapi/sandbox_origin_database.h" |
| 10 |
| 11 namespace fileapi { |
| 12 |
| 13 // Special directory name for isolated origin. |
| 14 const base::FilePath::CharType kOriginDirectory[] = FILE_PATH_LITERAL("iso"); |
| 15 |
| 16 SandboxIsolatedOriginDatabase::SandboxIsolatedOriginDatabase( |
| 17 const std::string& origin, |
| 18 const base::FilePath& file_system_directory) |
| 19 : migration_checked_(false), |
| 20 origin_(origin), |
| 21 file_system_directory_(file_system_directory) { |
| 22 } |
| 23 |
| 24 SandboxIsolatedOriginDatabase::~SandboxIsolatedOriginDatabase() { |
| 25 } |
| 26 |
| 27 bool SandboxIsolatedOriginDatabase::HasOriginPath( |
| 28 const std::string& origin) { |
| 29 MigrateDatabaseIfNeeded(); |
| 30 return (origin_ == origin); |
| 31 } |
| 32 |
| 33 bool SandboxIsolatedOriginDatabase::GetPathForOrigin( |
| 34 const std::string& origin, base::FilePath* directory) { |
| 35 MigrateDatabaseIfNeeded(); |
| 36 if (origin != origin_) |
| 37 return false; |
| 38 *directory = base::FilePath(kOriginDirectory); |
| 39 return true; |
| 40 } |
| 41 |
| 42 bool SandboxIsolatedOriginDatabase::RemovePathForOrigin( |
| 43 const std::string& origin) { |
| 44 return true; |
| 45 } |
| 46 |
| 47 bool SandboxIsolatedOriginDatabase::ListAllOrigins( |
| 48 std::vector<OriginRecord>* origins) { |
| 49 MigrateDatabaseIfNeeded(); |
| 50 origins->push_back(OriginRecord(origin_, base::FilePath(kOriginDirectory))); |
| 51 return true; |
| 52 } |
| 53 |
| 54 void SandboxIsolatedOriginDatabase::DropDatabase() { |
| 55 } |
| 56 |
| 57 void SandboxIsolatedOriginDatabase::MigrateDatabaseIfNeeded() { |
| 58 if (migration_checked_) |
| 59 return; |
| 60 |
| 61 migration_checked_ = true; |
| 62 // See if we have non-isolated version of sandbox database. |
| 63 scoped_ptr<SandboxOriginDatabase> database( |
| 64 new SandboxOriginDatabase(file_system_directory_)); |
| 65 if (!database->HasOriginPath(origin_)) |
| 66 return; |
| 67 |
| 68 base::FilePath directory_name; |
| 69 if (database->GetPathForOrigin(origin_, &directory_name) && |
| 70 directory_name != base::FilePath(kOriginDirectory)) { |
| 71 base::FilePath from_path = file_system_directory_.Append(directory_name); |
| 72 base::FilePath to_path = file_system_directory_.Append(kOriginDirectory); |
| 73 |
| 74 if (file_util::PathExists(to_path)) |
| 75 file_util::Delete(to_path, true /* recursive */); |
| 76 file_util::Move(from_path, to_path); |
| 77 } |
| 78 |
| 79 database->RemoveDatabase(); |
| 80 } |
| 81 |
| 82 } // namespace fileapi |
OLD | NEW |