Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / storage / browser / fileapi / sandbox_file_system_backend.cc
blob7247b8ebb1a44d261fa9b010c7dbec225f006f74
1 // 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.
5 #include "storage/browser/fileapi/sandbox_file_system_backend.h"
7 #include "base/bind.h"
8 #include "base/files/file_util.h"
9 #include "base/logging.h"
10 #include "base/metrics/histogram.h"
11 #include "base/task_runner_util.h"
12 #include "storage/browser/fileapi/async_file_util_adapter.h"
13 #include "storage/browser/fileapi/copy_or_move_file_validator.h"
14 #include "storage/browser/fileapi/file_stream_reader.h"
15 #include "storage/browser/fileapi/file_stream_writer.h"
16 #include "storage/browser/fileapi/file_system_context.h"
17 #include "storage/browser/fileapi/file_system_operation.h"
18 #include "storage/browser/fileapi/file_system_operation_context.h"
19 #include "storage/browser/fileapi/file_system_options.h"
20 #include "storage/browser/fileapi/file_system_usage_cache.h"
21 #include "storage/browser/fileapi/obfuscated_file_util.h"
22 #include "storage/browser/fileapi/sandbox_quota_observer.h"
23 #include "storage/browser/quota/quota_manager.h"
24 #include "storage/common/fileapi/file_system_types.h"
25 #include "storage/common/fileapi/file_system_util.h"
26 #include "url/gurl.h"
28 using storage::QuotaManagerProxy;
29 using storage::SpecialStoragePolicy;
31 namespace storage {
33 SandboxFileSystemBackend::SandboxFileSystemBackend(
34 SandboxFileSystemBackendDelegate* delegate)
35 : delegate_(delegate),
36 enable_temporary_file_system_in_incognito_(false) {
39 SandboxFileSystemBackend::~SandboxFileSystemBackend() {
42 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const {
43 return type == kFileSystemTypeTemporary ||
44 type == kFileSystemTypePersistent;
47 void SandboxFileSystemBackend::Initialize(FileSystemContext* context) {
48 DCHECK(delegate_);
50 // Set quota observers.
51 delegate_->RegisterQuotaUpdateObserver(storage::kFileSystemTypeTemporary);
52 delegate_->AddFileAccessObserver(
53 storage::kFileSystemTypeTemporary, delegate_->quota_observer(), NULL);
55 delegate_->RegisterQuotaUpdateObserver(storage::kFileSystemTypePersistent);
56 delegate_->AddFileAccessObserver(
57 storage::kFileSystemTypePersistent, delegate_->quota_observer(), NULL);
60 void SandboxFileSystemBackend::ResolveURL(
61 const FileSystemURL& url,
62 OpenFileSystemMode mode,
63 const OpenFileSystemCallback& callback) {
64 DCHECK(CanHandleType(url.type()));
65 DCHECK(delegate_);
66 if (delegate_->file_system_options().is_incognito() &&
67 !(url.type() == kFileSystemTypeTemporary &&
68 enable_temporary_file_system_in_incognito_)) {
69 // TODO(kinuko): return an isolated temporary directory.
70 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY);
71 return;
74 delegate_->OpenFileSystem(url.origin(),
75 url.type(),
76 mode,
77 callback,
78 GetFileSystemRootURI(url.origin(), url.type()));
81 AsyncFileUtil* SandboxFileSystemBackend::GetAsyncFileUtil(
82 FileSystemType type) {
83 DCHECK(delegate_);
84 return delegate_->file_util();
87 WatcherManager* SandboxFileSystemBackend::GetWatcherManager(
88 FileSystemType type) {
89 return NULL;
92 CopyOrMoveFileValidatorFactory*
93 SandboxFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
94 FileSystemType type,
95 base::File::Error* error_code) {
96 DCHECK(error_code);
97 *error_code = base::File::FILE_OK;
98 return NULL;
101 FileSystemOperation* SandboxFileSystemBackend::CreateFileSystemOperation(
102 const FileSystemURL& url,
103 FileSystemContext* context,
104 base::File::Error* error_code) const {
105 DCHECK(CanHandleType(url.type()));
106 DCHECK(error_code);
108 DCHECK(delegate_);
109 scoped_ptr<FileSystemOperationContext> operation_context =
110 delegate_->CreateFileSystemOperationContext(url, context, error_code);
111 if (!operation_context)
112 return NULL;
114 SpecialStoragePolicy* policy = delegate_->special_storage_policy();
115 if (policy && policy->IsStorageUnlimited(url.origin()))
116 operation_context->set_quota_limit_type(storage::kQuotaLimitTypeUnlimited);
117 else
118 operation_context->set_quota_limit_type(storage::kQuotaLimitTypeLimited);
120 return FileSystemOperation::Create(url, context, operation_context.Pass());
123 bool SandboxFileSystemBackend::SupportsStreaming(
124 const storage::FileSystemURL& url) const {
125 return false;
128 bool SandboxFileSystemBackend::HasInplaceCopyImplementation(
129 storage::FileSystemType type) const {
130 return false;
133 scoped_ptr<storage::FileStreamReader>
134 SandboxFileSystemBackend::CreateFileStreamReader(
135 const FileSystemURL& url,
136 int64 offset,
137 int64 max_bytes_to_read,
138 const base::Time& expected_modification_time,
139 FileSystemContext* context) const {
140 DCHECK(CanHandleType(url.type()));
141 DCHECK(delegate_);
142 return delegate_->CreateFileStreamReader(
143 url, offset, expected_modification_time, context);
146 scoped_ptr<storage::FileStreamWriter>
147 SandboxFileSystemBackend::CreateFileStreamWriter(
148 const FileSystemURL& url,
149 int64 offset,
150 FileSystemContext* context) const {
151 DCHECK(CanHandleType(url.type()));
152 DCHECK(delegate_);
153 return delegate_->CreateFileStreamWriter(url, offset, context, url.type());
156 FileSystemQuotaUtil* SandboxFileSystemBackend::GetQuotaUtil() {
157 return delegate_;
160 const UpdateObserverList* SandboxFileSystemBackend::GetUpdateObservers(
161 FileSystemType type) const {
162 return delegate_->GetUpdateObservers(type);
165 const ChangeObserverList* SandboxFileSystemBackend::GetChangeObservers(
166 FileSystemType type) const {
167 return delegate_->GetChangeObservers(type);
170 const AccessObserverList* SandboxFileSystemBackend::GetAccessObservers(
171 FileSystemType type) const {
172 return delegate_->GetAccessObservers(type);
175 SandboxFileSystemBackendDelegate::OriginEnumerator*
176 SandboxFileSystemBackend::CreateOriginEnumerator() {
177 DCHECK(delegate_);
178 return delegate_->CreateOriginEnumerator();
181 } // namespace storage