blob: c1e76d37f974e12304a9beda1a424e617ef38eec [file] [log] [blame]
[email protected]6faad822012-05-11 12:58:291// Copyright (c) 2012 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/fileapi/test_mount_point_provider.h"
6
7#include <set>
8#include <string>
9#include <vector>
10
11#include "base/file_util.h"
12#include "base/sequenced_task_runner.h"
[email protected]c4ca3b452012-05-31 03:15:4613#include "webkit/fileapi/file_system_file_stream_reader.h"
[email protected]6faad822012-05-11 12:58:2914#include "webkit/fileapi/file_system_quota_util.h"
[email protected]7e836a3d2012-05-31 05:14:5915#include "webkit/fileapi/file_system_util.h"
[email protected]02a60542012-07-24 20:05:3316#include "webkit/fileapi/local_file_system_operation.h"
[email protected]6faad822012-05-11 12:58:2917#include "webkit/fileapi/local_file_util.h"
18#include "webkit/fileapi/native_file_util.h"
[email protected]74698902012-06-12 12:16:3819#include "webkit/fileapi/sandbox_file_stream_writer.h"
[email protected]6faad822012-05-11 12:58:2920#include "webkit/quota/quota_manager.h"
21
22namespace fileapi {
23
24namespace {
25
26// This only supports single origin.
27class TestFileSystemQuotaUtil : public FileSystemQuotaUtil {
28 public:
29 explicit TestFileSystemQuotaUtil(base::SequencedTaskRunner* task_runner)
30 : FileSystemQuotaUtil(task_runner), usage_(0) {}
31 virtual ~TestFileSystemQuotaUtil() {}
32
33 virtual void GetOriginsForTypeOnFileThread(
34 FileSystemType type,
35 std::set<GURL>* origins) OVERRIDE {
36 NOTREACHED();
37 }
38 virtual void GetOriginsForHostOnFileThread(
39 FileSystemType type,
40 const std::string& host,
41 std::set<GURL>* origins) OVERRIDE {
42 NOTREACHED();
43 }
44 virtual int64 GetOriginUsageOnFileThread(
[email protected]22894522012-05-23 07:14:5845 FileSystemContext* context,
[email protected]6faad822012-05-11 12:58:2946 const GURL& origin_url,
47 FileSystemType type) OVERRIDE {
48 return usage_;
49 }
50 virtual void NotifyOriginWasAccessedOnIOThread(
51 quota::QuotaManagerProxy* proxy,
52 const GURL& origin_url,
53 FileSystemType type) OVERRIDE {
54 // Do nothing.
55 }
56 virtual void UpdateOriginUsageOnFileThread(
57 quota::QuotaManagerProxy* proxy,
58 const GURL& origin_url,
59 FileSystemType type,
60 int64 delta) OVERRIDE {
61 usage_ += delta;
[email protected]6faad822012-05-11 12:58:2962 }
63 virtual void StartUpdateOriginOnFileThread(
64 const GURL& origin_url,
65 FileSystemType type) OVERRIDE {
66 // Do nothing.
67 }
68 virtual void EndUpdateOriginOnFileThread(
69 const GURL& origin_url,
70 FileSystemType type) OVERRIDE {}
71 virtual void InvalidateUsageCache(const GURL& origin_url,
72 FileSystemType type) OVERRIDE {
73 // Do nothing.
74 }
75
76 private:
77 int64 usage_;
78};
79
80} // namespace
81
82TestMountPointProvider::TestMountPointProvider(
83 base::SequencedTaskRunner* task_runner,
84 const FilePath& base_path)
85 : base_path_(base_path),
[email protected]95af7372012-05-28 07:51:2086 local_file_util_(new LocalFileUtil()),
[email protected]6faad822012-05-11 12:58:2987 quota_util_(new TestFileSystemQuotaUtil(task_runner)) {
88}
89
90TestMountPointProvider::~TestMountPointProvider() {
91}
92
93void TestMountPointProvider::ValidateFileSystemRoot(
94 const GURL& origin_url,
95 FileSystemType type,
96 bool create,
97 const ValidateFileSystemCallback& callback) {
98 // This won't be called unless we add test code that opens a test
99 // filesystem by OpenFileSystem.
100 NOTREACHED();
101}
102
103FilePath TestMountPointProvider::GetFileSystemRootPathOnFileThread(
104 const GURL& origin_url,
105 FileSystemType type,
106 const FilePath& virtual_path,
107 bool create) {
108 DCHECK_EQ(kFileSystemTypeTest, type);
109 bool success = true;
110 if (create)
111 success = file_util::CreateDirectory(base_path_);
112 else
113 success = file_util::DirectoryExists(base_path_);
114 return success ? base_path_ : FilePath();
115}
116
117bool TestMountPointProvider::IsAccessAllowed(
118 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) {
119 return type == fileapi::kFileSystemTypeTest;
120}
121
122bool TestMountPointProvider::IsRestrictedFileName(
123 const FilePath& filename) const {
124 return false;
125}
126
[email protected]d6afd112012-07-25 22:55:04127FileSystemFileUtil* TestMountPointProvider::GetFileUtil(FileSystemType type) {
[email protected]6faad822012-05-11 12:58:29128 return local_file_util_.get();
129}
130
131FilePath TestMountPointProvider::GetPathForPermissionsCheck(
132 const FilePath& virtual_path) const {
133 return base_path_.Append(virtual_path);
134}
135
136FileSystemOperationInterface*
137TestMountPointProvider::CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:09138 const FileSystemURL& url,
[email protected]6faad822012-05-11 12:58:29139 FileSystemContext* context) const {
[email protected]75af1a42012-07-26 04:06:20140 scoped_ptr<FileSystemOperationContext> operation_context(
141 new FileSystemOperationContext(context));
142 return new LocalFileSystemOperation(context, operation_context.Pass());
[email protected]6faad822012-05-11 12:58:29143}
144
[email protected]c4ca3b452012-05-31 03:15:46145webkit_blob::FileStreamReader* TestMountPointProvider::CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09146 const FileSystemURL& url,
[email protected]6faad822012-05-11 12:58:29147 int64 offset,
148 FileSystemContext* context) const {
[email protected]c4ca3b452012-05-31 03:15:46149 return new FileSystemFileStreamReader(context, url, offset);
[email protected]6faad822012-05-11 12:58:29150}
151
[email protected]7e836a3d2012-05-31 05:14:59152fileapi::FileStreamWriter* TestMountPointProvider::CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09153 const FileSystemURL& url,
[email protected]7e84b912012-05-16 04:42:01154 int64 offset,
155 FileSystemContext* context) const {
[email protected]74698902012-06-12 12:16:38156 return new SandboxFileStreamWriter(context, url, offset);
[email protected]7e84b912012-05-16 04:42:01157}
158
[email protected]6faad822012-05-11 12:58:29159FileSystemQuotaUtil* TestMountPointProvider::GetQuotaUtil() {
160 return quota_util_.get();
161}
162
163} // namespace fileapi