Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: webkit/browser/fileapi/sandbox_file_system_backend.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "webkit/browser/fileapi/sandbox_file_system_backend.h"
6
7 #include "base/bind.h"
8 #include "base/file_util.h"
9 #include "base/logging.h"
10 #include "base/metrics/histogram.h"
11 #include "base/task_runner_util.h"
12 #include "url/gurl.h"
13 #include "webkit/browser/blob/file_stream_reader.h"
14 #include "webkit/browser/fileapi/async_file_util_adapter.h"
15 #include "webkit/browser/fileapi/copy_or_move_file_validator.h"
16 #include "webkit/browser/fileapi/file_stream_writer.h"
17 #include "webkit/browser/fileapi/file_system_context.h"
18 #include "webkit/browser/fileapi/file_system_operation.h"
19 #include "webkit/browser/fileapi/file_system_operation_context.h"
20 #include "webkit/browser/fileapi/file_system_options.h"
21 #include "webkit/browser/fileapi/file_system_usage_cache.h"
22 #include "webkit/browser/fileapi/obfuscated_file_util.h"
23 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h"
24 #include "webkit/browser/fileapi/sandbox_quota_observer.h"
25 #include "webkit/browser/quota/quota_manager.h"
26 #include "webkit/common/fileapi/file_system_types.h"
27 #include "webkit/common/fileapi/file_system_util.h"
28
29 using quota::QuotaManagerProxy;
30 using quota::SpecialStoragePolicy;
31
32 namespace fileapi {
33
34 SandboxFileSystemBackend::SandboxFileSystemBackend(
35 SandboxFileSystemBackendDelegate* delegate)
36 : delegate_(delegate),
37 enable_temporary_file_system_in_incognito_(false) {
38 }
39
40 SandboxFileSystemBackend::~SandboxFileSystemBackend() {
41 }
42
43 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const {
44 return type == kFileSystemTypeTemporary ||
45 type == kFileSystemTypePersistent;
46 }
47
48 void SandboxFileSystemBackend::Initialize(FileSystemContext* context) {
49 DCHECK(delegate_);
50
51 // Set quota observers.
52 delegate_->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypeTemporary);
53 delegate_->AddFileAccessObserver(
54 fileapi::kFileSystemTypeTemporary,
55 delegate_->quota_observer(), NULL);
56
57 delegate_->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypePersistent);
58 delegate_->AddFileAccessObserver(
59 fileapi::kFileSystemTypePersistent,
60 delegate_->quota_observer(), NULL);
61 }
62
63 void SandboxFileSystemBackend::ResolveURL(
64 const FileSystemURL& url,
65 OpenFileSystemMode mode,
66 const OpenFileSystemCallback& callback) {
67 DCHECK(CanHandleType(url.type()));
68 DCHECK(delegate_);
69 if (delegate_->file_system_options().is_incognito() &&
70 !(url.type() == kFileSystemTypeTemporary &&
71 enable_temporary_file_system_in_incognito_)) {
72 // TODO(kinuko): return an isolated temporary directory.
73 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY);
74 return;
75 }
76
77 delegate_->OpenFileSystem(url.origin(),
78 url.type(),
79 mode,
80 callback,
81 GetFileSystemRootURI(url.origin(), url.type()));
82 }
83
84 AsyncFileUtil* SandboxFileSystemBackend::GetAsyncFileUtil(
85 FileSystemType type) {
86 DCHECK(delegate_);
87 return delegate_->file_util();
88 }
89
90 CopyOrMoveFileValidatorFactory*
91 SandboxFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
92 FileSystemType type,
93 base::File::Error* error_code) {
94 DCHECK(error_code);
95 *error_code = base::File::FILE_OK;
96 return NULL;
97 }
98
99 FileSystemOperation* SandboxFileSystemBackend::CreateFileSystemOperation(
100 const FileSystemURL& url,
101 FileSystemContext* context,
102 base::File::Error* error_code) const {
103 DCHECK(CanHandleType(url.type()));
104 DCHECK(error_code);
105
106 DCHECK(delegate_);
107 scoped_ptr<FileSystemOperationContext> operation_context =
108 delegate_->CreateFileSystemOperationContext(url, context, error_code);
109 if (!operation_context)
110 return NULL;
111
112 SpecialStoragePolicy* policy = delegate_->special_storage_policy();
113 if (policy && policy->IsStorageUnlimited(url.origin()))
114 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited);
115 else
116 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited);
117
118 return FileSystemOperation::Create(url, context, operation_context.Pass());
119 }
120
121 bool SandboxFileSystemBackend::SupportsStreaming(
122 const fileapi::FileSystemURL& url) const {
123 return false;
124 }
125
126 scoped_ptr<webkit_blob::FileStreamReader>
127 SandboxFileSystemBackend::CreateFileStreamReader(
128 const FileSystemURL& url,
129 int64 offset,
130 const base::Time& expected_modification_time,
131 FileSystemContext* context) const {
132 DCHECK(CanHandleType(url.type()));
133 DCHECK(delegate_);
134 return delegate_->CreateFileStreamReader(
135 url, offset, expected_modification_time, context);
136 }
137
138 scoped_ptr<fileapi::FileStreamWriter>
139 SandboxFileSystemBackend::CreateFileStreamWriter(
140 const FileSystemURL& url,
141 int64 offset,
142 FileSystemContext* context) const {
143 DCHECK(CanHandleType(url.type()));
144 DCHECK(delegate_);
145 return delegate_->CreateFileStreamWriter(url, offset, context, url.type());
146 }
147
148 FileSystemQuotaUtil* SandboxFileSystemBackend::GetQuotaUtil() {
149 return delegate_;
150 }
151
152 SandboxFileSystemBackendDelegate::OriginEnumerator*
153 SandboxFileSystemBackend::CreateOriginEnumerator() {
154 DCHECK(delegate_);
155 return delegate_->CreateOriginEnumerator();
156 }
157
158 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/sandbox_file_system_backend.h ('k') | webkit/browser/fileapi/sandbox_file_system_backend_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698