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.
5 #include "storage/browser/fileapi/sandbox_isolated_origin_database.h"
7 #include "base/files/file_util.h"
8 #include "base/logging.h"
9 #include "storage/browser/fileapi/sandbox_origin_database.h"
13 // Special directory name for isolated origin.
14 const base::FilePath::CharType
15 SandboxIsolatedOriginDatabase::kObsoleteOriginDirectory
[] =
16 FILE_PATH_LITERAL("iso");
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),
24 file_system_directory_(file_system_directory
),
25 origin_directory_(origin_directory
) {
28 SandboxIsolatedOriginDatabase::~SandboxIsolatedOriginDatabase() {
31 bool SandboxIsolatedOriginDatabase::HasOriginPath(
32 const std::string
& origin
) {
33 return (origin_
== origin
);
36 bool SandboxIsolatedOriginDatabase::GetPathForOrigin(
37 const std::string
& origin
, base::FilePath
* directory
) {
38 if (origin
!= origin_
)
40 *directory
= origin_directory_
;
44 bool SandboxIsolatedOriginDatabase::RemovePathForOrigin(
45 const std::string
& origin
) {
49 bool SandboxIsolatedOriginDatabase::ListAllOrigins(
50 std::vector
<OriginRecord
>* origins
) {
51 origins
->push_back(OriginRecord(origin_
, origin_directory_
));
55 void SandboxIsolatedOriginDatabase::DropDatabase() {
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
);
65 if (database
->HasOriginPath(origin
)) {
67 base::DeleteFile(isolated_directory
, true /* recursive */);
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
);
80 } // namespace storage