| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/plugin_private_file_system_backend.h" | 5 #include "storage/browser/fileapi/plugin_private_file_system_backend.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
| 13 #include "webkit/browser/blob/file_stream_reader.h" | 13 #include "storage/browser/blob/file_stream_reader.h" |
| 14 #include "webkit/browser/fileapi/async_file_util_adapter.h" | 14 #include "storage/browser/fileapi/async_file_util_adapter.h" |
| 15 #include "webkit/browser/fileapi/file_stream_writer.h" | 15 #include "storage/browser/fileapi/file_stream_writer.h" |
| 16 #include "webkit/browser/fileapi/file_system_context.h" | 16 #include "storage/browser/fileapi/file_system_context.h" |
| 17 #include "webkit/browser/fileapi/file_system_operation.h" | 17 #include "storage/browser/fileapi/file_system_operation.h" |
| 18 #include "webkit/browser/fileapi/file_system_operation_context.h" | 18 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 19 #include "webkit/browser/fileapi/file_system_options.h" | 19 #include "storage/browser/fileapi/file_system_options.h" |
| 20 #include "webkit/browser/fileapi/isolated_context.h" | 20 #include "storage/browser/fileapi/isolated_context.h" |
| 21 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 21 #include "storage/browser/fileapi/obfuscated_file_util.h" |
| 22 #include "webkit/browser/fileapi/quota/quota_reservation.h" | 22 #include "storage/browser/fileapi/quota/quota_reservation.h" |
| 23 #include "webkit/common/fileapi/file_system_util.h" | 23 #include "storage/common/fileapi/file_system_util.h" |
| 24 | 24 |
| 25 namespace fileapi { | 25 namespace storage { |
| 26 | 26 |
| 27 class PluginPrivateFileSystemBackend::FileSystemIDToPluginMap { | 27 class PluginPrivateFileSystemBackend::FileSystemIDToPluginMap { |
| 28 public: | 28 public: |
| 29 explicit FileSystemIDToPluginMap(base::SequencedTaskRunner* task_runner) | 29 explicit FileSystemIDToPluginMap(base::SequencedTaskRunner* task_runner) |
| 30 : task_runner_(task_runner) {} | 30 : task_runner_(task_runner) {} |
| 31 ~FileSystemIDToPluginMap() {} | 31 ~FileSystemIDToPluginMap() {} |
| 32 | 32 |
| 33 std::string GetPluginIDForURL(const FileSystemURL& url) { | 33 std::string GetPluginIDForURL(const FileSystemURL& url) { |
| 34 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 34 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 35 Map::iterator found = map_.find(url.filesystem_id()); | 35 Map::iterator found = map_.find(url.filesystem_id()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 } // namespace | 85 } // namespace |
| 86 | 86 |
| 87 PluginPrivateFileSystemBackend::PluginPrivateFileSystemBackend( | 87 PluginPrivateFileSystemBackend::PluginPrivateFileSystemBackend( |
| 88 base::SequencedTaskRunner* file_task_runner, | 88 base::SequencedTaskRunner* file_task_runner, |
| 89 const base::FilePath& profile_path, | 89 const base::FilePath& profile_path, |
| 90 quota::SpecialStoragePolicy* special_storage_policy, | 90 quota::SpecialStoragePolicy* special_storage_policy, |
| 91 const FileSystemOptions& file_system_options) | 91 const FileSystemOptions& file_system_options) |
| 92 : file_task_runner_(file_task_runner), | 92 : file_task_runner_(file_task_runner), |
| 93 file_system_options_(file_system_options), | 93 file_system_options_(file_system_options), |
| 94 base_path_(profile_path.Append( | 94 base_path_(profile_path.Append(kFileSystemDirectory) |
| 95 kFileSystemDirectory).Append(kPluginPrivateDirectory)), | 95 .Append(kPluginPrivateDirectory)), |
| 96 plugin_map_(new FileSystemIDToPluginMap(file_task_runner)), | 96 plugin_map_(new FileSystemIDToPluginMap(file_task_runner)), |
| 97 weak_factory_(this) { | 97 weak_factory_(this) { |
| 98 file_util_.reset( | 98 file_util_.reset(new AsyncFileUtilAdapter(new ObfuscatedFileUtil( |
| 99 new AsyncFileUtilAdapter(new ObfuscatedFileUtil( | 99 special_storage_policy, |
| 100 special_storage_policy, | 100 base_path_, |
| 101 base_path_, file_system_options.env_override(), | 101 file_system_options.env_override(), |
| 102 file_task_runner, | 102 file_task_runner, |
| 103 base::Bind(&FileSystemIDToPluginMap::GetPluginIDForURL, | 103 base::Bind(&FileSystemIDToPluginMap::GetPluginIDForURL, |
| 104 base::Owned(plugin_map_)), | 104 base::Owned(plugin_map_)), |
| 105 std::set<std::string>(), | 105 std::set<std::string>(), |
| 106 NULL))); | 106 NULL))); |
| 107 } | 107 } |
| 108 | 108 |
| 109 PluginPrivateFileSystemBackend::~PluginPrivateFileSystemBackend() { | 109 PluginPrivateFileSystemBackend::~PluginPrivateFileSystemBackend() { |
| 110 if (!file_task_runner_->RunsTasksOnCurrentThread()) { | 110 if (!file_task_runner_->RunsTasksOnCurrentThread()) { |
| 111 AsyncFileUtil* file_util = file_util_.release(); | 111 AsyncFileUtil* file_util = file_util_.release(); |
| 112 if (!file_task_runner_->DeleteSoon(FROM_HERE, file_util)) | 112 if (!file_task_runner_->DeleteSoon(FROM_HERE, file_util)) |
| 113 delete file_util; | 113 delete file_util; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 void PluginPrivateFileSystemBackend::OpenPrivateFileSystem( | 117 void PluginPrivateFileSystemBackend::OpenPrivateFileSystem( |
| 118 const GURL& origin_url, | 118 const GURL& origin_url, |
| 119 FileSystemType type, | 119 FileSystemType type, |
| 120 const std::string& filesystem_id, | 120 const std::string& filesystem_id, |
| 121 const std::string& plugin_id, | 121 const std::string& plugin_id, |
| 122 OpenFileSystemMode mode, | 122 OpenFileSystemMode mode, |
| 123 const StatusCallback& callback) { | 123 const StatusCallback& callback) { |
| 124 if (!CanHandleType(type) || file_system_options_.is_incognito()) { | 124 if (!CanHandleType(type) || file_system_options_.is_incognito()) { |
| 125 base::MessageLoopProxy::current()->PostTask( | 125 base::MessageLoopProxy::current()->PostTask( |
| 126 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_SECURITY)); | 126 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_SECURITY)); |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 PostTaskAndReplyWithResult( | 130 PostTaskAndReplyWithResult(file_task_runner_.get(), |
| 131 file_task_runner_.get(), | 131 FROM_HERE, |
| 132 FROM_HERE, | 132 base::Bind(&OpenFileSystemOnFileTaskRunner, |
| 133 base::Bind(&OpenFileSystemOnFileTaskRunner, | 133 obfuscated_file_util(), |
| 134 obfuscated_file_util(), plugin_map_, | 134 plugin_map_, |
| 135 origin_url, filesystem_id, plugin_id, mode), | 135 origin_url, |
| 136 callback); | 136 filesystem_id, |
| 137 plugin_id, |
| 138 mode), |
| 139 callback); |
| 137 } | 140 } |
| 138 | 141 |
| 139 bool PluginPrivateFileSystemBackend::CanHandleType(FileSystemType type) const { | 142 bool PluginPrivateFileSystemBackend::CanHandleType(FileSystemType type) const { |
| 140 return type == kFileSystemTypePluginPrivate; | 143 return type == kFileSystemTypePluginPrivate; |
| 141 } | 144 } |
| 142 | 145 |
| 143 void PluginPrivateFileSystemBackend::Initialize(FileSystemContext* context) { | 146 void PluginPrivateFileSystemBackend::Initialize(FileSystemContext* context) { |
| 144 } | 147 } |
| 145 | 148 |
| 146 void PluginPrivateFileSystemBackend::ResolveURL( | 149 void PluginPrivateFileSystemBackend::ResolveURL( |
| 147 const FileSystemURL& url, | 150 const FileSystemURL& url, |
| 148 OpenFileSystemMode mode, | 151 OpenFileSystemMode mode, |
| 149 const OpenFileSystemCallback& callback) { | 152 const OpenFileSystemCallback& callback) { |
| 150 // We never allow opening a new plugin-private filesystem via usual | 153 // We never allow opening a new plugin-private filesystem via usual |
| 151 // ResolveURL. | 154 // ResolveURL. |
| 152 base::MessageLoopProxy::current()->PostTask( | 155 base::MessageLoopProxy::current()->PostTask( |
| 153 FROM_HERE, | 156 FROM_HERE, |
| 154 base::Bind(callback, GURL(), std::string(), | 157 base::Bind( |
| 155 base::File::FILE_ERROR_SECURITY)); | 158 callback, GURL(), std::string(), base::File::FILE_ERROR_SECURITY)); |
| 156 } | 159 } |
| 157 | 160 |
| 158 AsyncFileUtil* | 161 AsyncFileUtil* PluginPrivateFileSystemBackend::GetAsyncFileUtil( |
| 159 PluginPrivateFileSystemBackend::GetAsyncFileUtil(FileSystemType type) { | 162 FileSystemType type) { |
| 160 return file_util_.get(); | 163 return file_util_.get(); |
| 161 } | 164 } |
| 162 | 165 |
| 163 CopyOrMoveFileValidatorFactory* | 166 CopyOrMoveFileValidatorFactory* |
| 164 PluginPrivateFileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 167 PluginPrivateFileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
| 165 FileSystemType type, | 168 FileSystemType type, |
| 166 base::File::Error* error_code) { | 169 base::File::Error* error_code) { |
| 167 DCHECK(error_code); | 170 DCHECK(error_code); |
| 168 *error_code = base::File::FILE_OK; | 171 *error_code = base::File::FILE_OK; |
| 169 return NULL; | 172 return NULL; |
| 170 } | 173 } |
| 171 | 174 |
| 172 FileSystemOperation* PluginPrivateFileSystemBackend::CreateFileSystemOperation( | 175 FileSystemOperation* PluginPrivateFileSystemBackend::CreateFileSystemOperation( |
| 173 const FileSystemURL& url, | 176 const FileSystemURL& url, |
| 174 FileSystemContext* context, | 177 FileSystemContext* context, |
| 175 base::File::Error* error_code) const { | 178 base::File::Error* error_code) const { |
| 176 scoped_ptr<FileSystemOperationContext> operation_context( | 179 scoped_ptr<FileSystemOperationContext> operation_context( |
| 177 new FileSystemOperationContext(context)); | 180 new FileSystemOperationContext(context)); |
| 178 return FileSystemOperation::Create(url, context, operation_context.Pass()); | 181 return FileSystemOperation::Create(url, context, operation_context.Pass()); |
| 179 } | 182 } |
| 180 | 183 |
| 181 bool PluginPrivateFileSystemBackend::SupportsStreaming( | 184 bool PluginPrivateFileSystemBackend::SupportsStreaming( |
| 182 const fileapi::FileSystemURL& url) const { | 185 const storage::FileSystemURL& url) const { |
| 183 return false; | 186 return false; |
| 184 } | 187 } |
| 185 | 188 |
| 186 scoped_ptr<webkit_blob::FileStreamReader> | 189 scoped_ptr<storage::FileStreamReader> |
| 187 PluginPrivateFileSystemBackend::CreateFileStreamReader( | 190 PluginPrivateFileSystemBackend::CreateFileStreamReader( |
| 188 const FileSystemURL& url, | 191 const FileSystemURL& url, |
| 189 int64 offset, | 192 int64 offset, |
| 190 const base::Time& expected_modification_time, | 193 const base::Time& expected_modification_time, |
| 191 FileSystemContext* context) const { | 194 FileSystemContext* context) const { |
| 192 return scoped_ptr<webkit_blob::FileStreamReader>(); | 195 return scoped_ptr<storage::FileStreamReader>(); |
| 193 } | 196 } |
| 194 | 197 |
| 195 scoped_ptr<FileStreamWriter> | 198 scoped_ptr<FileStreamWriter> |
| 196 PluginPrivateFileSystemBackend::CreateFileStreamWriter( | 199 PluginPrivateFileSystemBackend::CreateFileStreamWriter( |
| 197 const FileSystemURL& url, | 200 const FileSystemURL& url, |
| 198 int64 offset, | 201 int64 offset, |
| 199 FileSystemContext* context) const { | 202 FileSystemContext* context) const { |
| 200 return scoped_ptr<FileStreamWriter>(); | 203 return scoped_ptr<FileStreamWriter>(); |
| 201 } | 204 } |
| 202 | 205 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 const GURL& origin_url, | 262 const GURL& origin_url, |
| 260 FileSystemType type) { | 263 FileSystemType type) { |
| 261 // We don't track usage on this filesystem. | 264 // We don't track usage on this filesystem. |
| 262 NOTREACHED(); | 265 NOTREACHED(); |
| 263 return scoped_refptr<QuotaReservation>(); | 266 return scoped_refptr<QuotaReservation>(); |
| 264 } | 267 } |
| 265 | 268 |
| 266 void PluginPrivateFileSystemBackend::AddFileUpdateObserver( | 269 void PluginPrivateFileSystemBackend::AddFileUpdateObserver( |
| 267 FileSystemType type, | 270 FileSystemType type, |
| 268 FileUpdateObserver* observer, | 271 FileUpdateObserver* observer, |
| 269 base::SequencedTaskRunner* task_runner) {} | 272 base::SequencedTaskRunner* task_runner) { |
| 273 } |
| 270 | 274 |
| 271 void PluginPrivateFileSystemBackend::AddFileChangeObserver( | 275 void PluginPrivateFileSystemBackend::AddFileChangeObserver( |
| 272 FileSystemType type, | 276 FileSystemType type, |
| 273 FileChangeObserver* observer, | 277 FileChangeObserver* observer, |
| 274 base::SequencedTaskRunner* task_runner) {} | 278 base::SequencedTaskRunner* task_runner) { |
| 279 } |
| 275 | 280 |
| 276 void PluginPrivateFileSystemBackend::AddFileAccessObserver( | 281 void PluginPrivateFileSystemBackend::AddFileAccessObserver( |
| 277 FileSystemType type, | 282 FileSystemType type, |
| 278 FileAccessObserver* observer, | 283 FileAccessObserver* observer, |
| 279 base::SequencedTaskRunner* task_runner) {} | 284 base::SequencedTaskRunner* task_runner) { |
| 285 } |
| 280 | 286 |
| 281 const UpdateObserverList* PluginPrivateFileSystemBackend::GetUpdateObservers( | 287 const UpdateObserverList* PluginPrivateFileSystemBackend::GetUpdateObservers( |
| 282 FileSystemType type) const { | 288 FileSystemType type) const { |
| 283 return NULL; | 289 return NULL; |
| 284 } | 290 } |
| 285 | 291 |
| 286 const ChangeObserverList* PluginPrivateFileSystemBackend::GetChangeObservers( | 292 const ChangeObserverList* PluginPrivateFileSystemBackend::GetChangeObservers( |
| 287 FileSystemType type) const { | 293 FileSystemType type) const { |
| 288 return NULL; | 294 return NULL; |
| 289 } | 295 } |
| 290 | 296 |
| 291 const AccessObserverList* PluginPrivateFileSystemBackend::GetAccessObservers( | 297 const AccessObserverList* PluginPrivateFileSystemBackend::GetAccessObservers( |
| 292 FileSystemType type) const { | 298 FileSystemType type) const { |
| 293 return NULL; | 299 return NULL; |
| 294 } | 300 } |
| 295 | 301 |
| 296 ObfuscatedFileUtil* PluginPrivateFileSystemBackend::obfuscated_file_util() { | 302 ObfuscatedFileUtil* PluginPrivateFileSystemBackend::obfuscated_file_util() { |
| 297 return static_cast<ObfuscatedFileUtil*>( | 303 return static_cast<ObfuscatedFileUtil*>( |
| 298 static_cast<AsyncFileUtilAdapter*>(file_util_.get())->sync_file_util()); | 304 static_cast<AsyncFileUtilAdapter*>(file_util_.get())->sync_file_util()); |
| 299 } | 305 } |
| 300 | 306 |
| 301 } // namespace fileapi | 307 } // namespace storage |
| OLD | NEW |