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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
// Copyright (c) 2012 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/fileapi/test_mount_point_provider.h"
#include <set>
#include <string>
#include <vector>
#include "base/file_util.h"
#include "base/sequenced_task_runner.h"
#include "webkit/fileapi/file_system_file_reader.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_quota_util.h"
#include "webkit/fileapi/local_file_util.h"
#include "webkit/fileapi/native_file_util.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/quota/quota_manager.h"
namespace fileapi {
namespace {
// This only supports single origin.
class TestFileSystemQuotaUtil : public FileSystemQuotaUtil {
public:
explicit TestFileSystemQuotaUtil(base::SequencedTaskRunner* task_runner)
: FileSystemQuotaUtil(task_runner), usage_(0) {}
virtual ~TestFileSystemQuotaUtil() {}
virtual void GetOriginsForTypeOnFileThread(
FileSystemType type,
std::set<GURL>* origins) OVERRIDE {
NOTREACHED();
}
virtual void GetOriginsForHostOnFileThread(
FileSystemType type,
const std::string& host,
std::set<GURL>* origins) OVERRIDE {
NOTREACHED();
}
virtual int64 GetOriginUsageOnFileThread(
const GURL& origin_url,
FileSystemType type) OVERRIDE {
return usage_;
}
virtual void NotifyOriginWasAccessedOnIOThread(
quota::QuotaManagerProxy* proxy,
const GURL& origin_url,
FileSystemType type) OVERRIDE {
// Do nothing.
}
virtual void UpdateOriginUsageOnFileThread(
quota::QuotaManagerProxy* proxy,
const GURL& origin_url,
FileSystemType type,
int64 delta) OVERRIDE {
usage_ += delta;
}
virtual void StartUpdateOriginOnFileThread(
const GURL& origin_url,
FileSystemType type) OVERRIDE {
// Do nothing.
}
virtual void EndUpdateOriginOnFileThread(
const GURL& origin_url,
FileSystemType type) OVERRIDE {}
virtual void InvalidateUsageCache(const GURL& origin_url,
FileSystemType type) OVERRIDE {
// Do nothing.
}
private:
int64 usage_;
};
} // namespace
TestMountPointProvider::TestMountPointProvider(
base::SequencedTaskRunner* task_runner,
const FilePath& base_path)
: base_path_(base_path),
local_file_util_(new LocalFileUtil(new NativeFileUtil())),
quota_util_(new TestFileSystemQuotaUtil(task_runner)) {
}
TestMountPointProvider::~TestMountPointProvider() {
}
void TestMountPointProvider::ValidateFileSystemRoot(
const GURL& origin_url,
FileSystemType type,
bool create,
const ValidateFileSystemCallback& callback) {
// This won't be called unless we add test code that opens a test
// filesystem by OpenFileSystem.
NOTREACHED();
}
FilePath TestMountPointProvider::GetFileSystemRootPathOnFileThread(
const GURL& origin_url,
FileSystemType type,
const FilePath& virtual_path,
bool create) {
DCHECK_EQ(kFileSystemTypeTest, type);
bool success = true;
if (create)
success = file_util::CreateDirectory(base_path_);
else
success = file_util::DirectoryExists(base_path_);
return success ? base_path_ : FilePath();
}
bool TestMountPointProvider::IsAccessAllowed(
const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) {
return type == fileapi::kFileSystemTypeTest;
}
bool TestMountPointProvider::IsRestrictedFileName(
const FilePath& filename) const {
return false;
}
std::vector<FilePath> TestMountPointProvider::GetRootDirectories() const {
return std::vector<FilePath>();
}
FileSystemFileUtil* TestMountPointProvider::GetFileUtil() {
return local_file_util_.get();
}
FilePath TestMountPointProvider::GetPathForPermissionsCheck(
const FilePath& virtual_path) const {
return base_path_.Append(virtual_path);
}
FileSystemOperationInterface*
TestMountPointProvider::CreateFileSystemOperation(
const GURL& origin_url,
FileSystemType file_system_type,
const FilePath& virtual_path,
FileSystemContext* context) const {
return new FileSystemOperation(context);
}
webkit_blob::FileReader* TestMountPointProvider::CreateFileReader(
const GURL& url,
int64 offset,
FileSystemContext* context) const {
return new FileSystemFileReader(context, url, offset);
}
fileapi::FileWriter* TestMountPointProvider::CreateFileWriter(
const GURL& url,
int64 offset,
FileSystemContext* context) const {
// TODO(kinaba,kinuko): return SandboxFileWriter when it is implemented.
NOTIMPLEMENTED();
return NULL;
}
FileSystemQuotaUtil* TestMountPointProvider::GetQuotaUtil() {
return quota_util_.get();
}
} // namespace fileapi
|