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
15 SandboxIsolatedOriginDatabase::kObsoleteOriginDirectory[] =
16 FILE_PATH_LITERAL("iso");
17
SandboxIsolatedOriginDatabase(const std::string & origin,const base::FilePath & file_system_directory,const base::FilePath & origin_directory)18 SandboxIsolatedOriginDatabase::SandboxIsolatedOriginDatabase(
19 const std::string& origin,
20 const base::FilePath& file_system_directory,
21 const base::FilePath& origin_directory)
22 : migration_checked_(false),
23 origin_(origin),
24 file_system_directory_(file_system_directory),
25 origin_directory_(origin_directory) {
26 }
27
~SandboxIsolatedOriginDatabase()28 SandboxIsolatedOriginDatabase::~SandboxIsolatedOriginDatabase() {
29 }
30
HasOriginPath(const std::string & origin)31 bool SandboxIsolatedOriginDatabase::HasOriginPath(
32 const std::string& origin) {
33 return (origin_ == origin);
34 }
35
GetPathForOrigin(const std::string & origin,base::FilePath * directory)36 bool SandboxIsolatedOriginDatabase::GetPathForOrigin(
37 const std::string& origin, base::FilePath* directory) {
38 if (origin != origin_)
39 return false;
40 *directory = origin_directory_;
41 return true;
42 }
43
RemovePathForOrigin(const std::string & origin)44 bool SandboxIsolatedOriginDatabase::RemovePathForOrigin(
45 const std::string& origin) {
46 return true;
47 }
48
ListAllOrigins(std::vector<OriginRecord> * origins)49 bool SandboxIsolatedOriginDatabase::ListAllOrigins(
50 std::vector<OriginRecord>* origins) {
51 origins->push_back(OriginRecord(origin_, origin_directory_));
52 return true;
53 }
54
DropDatabase()55 void SandboxIsolatedOriginDatabase::DropDatabase() {
56 }
57
MigrateBackFromObsoleteOriginDatabase(const std::string & origin,const base::FilePath & file_system_directory,SandboxOriginDatabase * database)58 void SandboxIsolatedOriginDatabase::MigrateBackFromObsoleteOriginDatabase(
59 const std::string& origin,
60 const base::FilePath& file_system_directory,
61 SandboxOriginDatabase* database) {
62 base::FilePath isolated_directory =
63 file_system_directory.Append(kObsoleteOriginDirectory);
64
65 if (database->HasOriginPath(origin)) {
66 // Don't bother.
67 base::DeleteFile(isolated_directory, true /* recursive */);
68 return;
69 }
70
71 base::FilePath directory_name;
72 if (database->GetPathForOrigin(origin, &directory_name)) {
73 base::FilePath origin_directory =
74 file_system_directory.Append(directory_name);
75 base::DeleteFile(origin_directory, true /* recursive */);
76 base::Move(isolated_directory, origin_directory);
77 }
78 }
79
80 } // namespace fileapi
81