OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 5 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 #include "webkit/browser/blob/file_stream_reader.h" | 13 #include "webkit/browser/blob/file_stream_reader.h" |
14 #include "webkit/browser/fileapi/async_file_util_adapter.h" | 14 #include "webkit/browser/fileapi/async_file_util_adapter.h" |
15 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | 15 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
16 #include "webkit/browser/fileapi/file_stream_writer.h" | 16 #include "webkit/browser/fileapi/file_stream_writer.h" |
17 #include "webkit/browser/fileapi/file_system_context.h" | 17 #include "webkit/browser/fileapi/file_system_context.h" |
18 #include "webkit/browser/fileapi/file_system_operation.h" | 18 #include "webkit/browser/fileapi/file_system_operation.h" |
19 #include "webkit/browser/fileapi/file_system_operation_context.h" | 19 #include "webkit/browser/fileapi/file_system_operation_context.h" |
20 #include "webkit/browser/fileapi/file_system_options.h" | 20 #include "webkit/browser/fileapi/file_system_options.h" |
21 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 21 #include "webkit/browser/fileapi/file_system_usage_cache.h" |
22 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 22 #include "webkit/browser/fileapi/obfuscated_file_util.h" |
23 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" | 23 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" |
24 #include "webkit/browser/fileapi/sandbox_quota_observer.h" | 24 #include "webkit/browser/fileapi/sandbox_quota_observer.h" |
25 #include "webkit/browser/quota/quota_manager.h" | 25 #include "webkit/browser/quota/quota_manager.h" |
26 #include "webkit/common/fileapi/file_system_types.h" | 26 #include "webkit/common/fileapi/file_system_types.h" |
27 #include "webkit/common/fileapi/file_system_util.h" | 27 #include "webkit/common/fileapi/file_system_util.h" |
28 | 28 |
29 using quota::QuotaManagerProxy; | 29 using storage::QuotaManagerProxy; |
30 using quota::SpecialStoragePolicy; | 30 using storage::SpecialStoragePolicy; |
31 | 31 |
32 namespace fileapi { | 32 namespace storage { |
33 | 33 |
34 SandboxFileSystemBackend::SandboxFileSystemBackend( | 34 SandboxFileSystemBackend::SandboxFileSystemBackend( |
35 SandboxFileSystemBackendDelegate* delegate) | 35 SandboxFileSystemBackendDelegate* delegate) |
36 : delegate_(delegate), | 36 : delegate_(delegate), |
37 enable_temporary_file_system_in_incognito_(false) { | 37 enable_temporary_file_system_in_incognito_(false) { |
38 } | 38 } |
39 | 39 |
40 SandboxFileSystemBackend::~SandboxFileSystemBackend() { | 40 SandboxFileSystemBackend::~SandboxFileSystemBackend() { |
41 } | 41 } |
42 | 42 |
43 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { | 43 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { |
44 return type == kFileSystemTypeTemporary || | 44 return type == kFileSystemTypeTemporary || |
45 type == kFileSystemTypePersistent; | 45 type == kFileSystemTypePersistent; |
46 } | 46 } |
47 | 47 |
48 void SandboxFileSystemBackend::Initialize(FileSystemContext* context) { | 48 void SandboxFileSystemBackend::Initialize(FileSystemContext* context) { |
49 DCHECK(delegate_); | 49 DCHECK(delegate_); |
50 | 50 |
51 // Set quota observers. | 51 // Set quota observers. |
52 delegate_->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypeTemporary); | 52 delegate_->RegisterQuotaUpdateObserver(storage::kFileSystemTypeTemporary); |
53 delegate_->AddFileAccessObserver( | 53 delegate_->AddFileAccessObserver( |
54 fileapi::kFileSystemTypeTemporary, | 54 storage::kFileSystemTypeTemporary, delegate_->quota_observer(), NULL); |
55 delegate_->quota_observer(), NULL); | |
56 | 55 |
57 delegate_->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypePersistent); | 56 delegate_->RegisterQuotaUpdateObserver(storage::kFileSystemTypePersistent); |
58 delegate_->AddFileAccessObserver( | 57 delegate_->AddFileAccessObserver( |
59 fileapi::kFileSystemTypePersistent, | 58 storage::kFileSystemTypePersistent, delegate_->quota_observer(), NULL); |
60 delegate_->quota_observer(), NULL); | |
61 } | 59 } |
62 | 60 |
63 void SandboxFileSystemBackend::ResolveURL( | 61 void SandboxFileSystemBackend::ResolveURL( |
64 const FileSystemURL& url, | 62 const FileSystemURL& url, |
65 OpenFileSystemMode mode, | 63 OpenFileSystemMode mode, |
66 const OpenFileSystemCallback& callback) { | 64 const OpenFileSystemCallback& callback) { |
67 DCHECK(CanHandleType(url.type())); | 65 DCHECK(CanHandleType(url.type())); |
68 DCHECK(delegate_); | 66 DCHECK(delegate_); |
69 if (delegate_->file_system_options().is_incognito() && | 67 if (delegate_->file_system_options().is_incognito() && |
70 !(url.type() == kFileSystemTypeTemporary && | 68 !(url.type() == kFileSystemTypeTemporary && |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 DCHECK(error_code); | 102 DCHECK(error_code); |
105 | 103 |
106 DCHECK(delegate_); | 104 DCHECK(delegate_); |
107 scoped_ptr<FileSystemOperationContext> operation_context = | 105 scoped_ptr<FileSystemOperationContext> operation_context = |
108 delegate_->CreateFileSystemOperationContext(url, context, error_code); | 106 delegate_->CreateFileSystemOperationContext(url, context, error_code); |
109 if (!operation_context) | 107 if (!operation_context) |
110 return NULL; | 108 return NULL; |
111 | 109 |
112 SpecialStoragePolicy* policy = delegate_->special_storage_policy(); | 110 SpecialStoragePolicy* policy = delegate_->special_storage_policy(); |
113 if (policy && policy->IsStorageUnlimited(url.origin())) | 111 if (policy && policy->IsStorageUnlimited(url.origin())) |
114 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited); | 112 operation_context->set_quota_limit_type(storage::kQuotaLimitTypeUnlimited); |
115 else | 113 else |
116 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited); | 114 operation_context->set_quota_limit_type(storage::kQuotaLimitTypeLimited); |
117 | 115 |
118 return FileSystemOperation::Create(url, context, operation_context.Pass()); | 116 return FileSystemOperation::Create(url, context, operation_context.Pass()); |
119 } | 117 } |
120 | 118 |
121 bool SandboxFileSystemBackend::SupportsStreaming( | 119 bool SandboxFileSystemBackend::SupportsStreaming( |
122 const fileapi::FileSystemURL& url) const { | 120 const storage::FileSystemURL& url) const { |
123 return false; | 121 return false; |
124 } | 122 } |
125 | 123 |
126 bool SandboxFileSystemBackend::HasInplaceCopyImplementation( | 124 bool SandboxFileSystemBackend::HasInplaceCopyImplementation( |
127 fileapi::FileSystemType type) const { | 125 storage::FileSystemType type) const { |
128 return true; | 126 return true; |
129 } | 127 } |
130 | 128 |
131 scoped_ptr<webkit_blob::FileStreamReader> | 129 scoped_ptr<storage::FileStreamReader> |
132 SandboxFileSystemBackend::CreateFileStreamReader( | 130 SandboxFileSystemBackend::CreateFileStreamReader( |
133 const FileSystemURL& url, | 131 const FileSystemURL& url, |
134 int64 offset, | 132 int64 offset, |
135 const base::Time& expected_modification_time, | 133 const base::Time& expected_modification_time, |
136 FileSystemContext* context) const { | 134 FileSystemContext* context) const { |
137 DCHECK(CanHandleType(url.type())); | 135 DCHECK(CanHandleType(url.type())); |
138 DCHECK(delegate_); | 136 DCHECK(delegate_); |
139 return delegate_->CreateFileStreamReader( | 137 return delegate_->CreateFileStreamReader( |
140 url, offset, expected_modification_time, context); | 138 url, offset, expected_modification_time, context); |
141 } | 139 } |
142 | 140 |
143 scoped_ptr<fileapi::FileStreamWriter> | 141 scoped_ptr<storage::FileStreamWriter> |
144 SandboxFileSystemBackend::CreateFileStreamWriter( | 142 SandboxFileSystemBackend::CreateFileStreamWriter( |
145 const FileSystemURL& url, | 143 const FileSystemURL& url, |
146 int64 offset, | 144 int64 offset, |
147 FileSystemContext* context) const { | 145 FileSystemContext* context) const { |
148 DCHECK(CanHandleType(url.type())); | 146 DCHECK(CanHandleType(url.type())); |
149 DCHECK(delegate_); | 147 DCHECK(delegate_); |
150 return delegate_->CreateFileStreamWriter(url, offset, context, url.type()); | 148 return delegate_->CreateFileStreamWriter(url, offset, context, url.type()); |
151 } | 149 } |
152 | 150 |
153 FileSystemQuotaUtil* SandboxFileSystemBackend::GetQuotaUtil() { | 151 FileSystemQuotaUtil* SandboxFileSystemBackend::GetQuotaUtil() { |
154 return delegate_; | 152 return delegate_; |
155 } | 153 } |
156 | 154 |
157 SandboxFileSystemBackendDelegate::OriginEnumerator* | 155 SandboxFileSystemBackendDelegate::OriginEnumerator* |
158 SandboxFileSystemBackend::CreateOriginEnumerator() { | 156 SandboxFileSystemBackend::CreateOriginEnumerator() { |
159 DCHECK(delegate_); | 157 DCHECK(delegate_); |
160 return delegate_->CreateOriginEnumerator(); | 158 return delegate_->CreateOriginEnumerator(); |
161 } | 159 } |
162 | 160 |
163 } // namespace fileapi | 161 } // namespace storage |
OLD | NEW |