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