Chromium Code Reviews| Index: webkit/browser/fileapi/syncable/sync_file_system_backend.cc |
| diff --git a/webkit/browser/fileapi/syncable/sync_file_system_backend.cc b/webkit/browser/fileapi/syncable/sync_file_system_backend.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..65b3f806f6964731c25038705c3ffec20d43a854 |
| --- /dev/null |
| +++ b/webkit/browser/fileapi/syncable/sync_file_system_backend.cc |
| @@ -0,0 +1,148 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "webkit/browser/fileapi/syncable/sync_file_system_backend.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/metrics/histogram.h" |
| +#include "webkit/browser/fileapi/async_file_util_adapter.h" |
| +#include "webkit/browser/fileapi/file_system_context.h" |
| +#include "webkit/browser/fileapi/obfuscated_file_util.h" |
| +#include "webkit/browser/fileapi/sandbox_quota_observer.h" |
| +#include "webkit/browser/fileapi/syncable/syncable_file_system_operation.h" |
| +#include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" |
| +#include "webkit/common/fileapi/file_system_util.h" |
| + |
| +namespace sync_file_system { |
| + |
| +SyncFileSystemBackend::SyncFileSystemBackend( |
| + const fileapi::FileSystemOptions& file_system_options) |
| + : SandboxFileSystemBackend(NULL, file_system_options) { |
| +} |
| + |
| +SyncFileSystemBackend::~SyncFileSystemBackend() { |
| +} |
| + |
| +bool SyncFileSystemBackend::CanHandleType( |
| + fileapi::FileSystemType type) const { |
| + return type == fileapi::kFileSystemTypeSyncable || |
| + type == fileapi::kFileSystemTypeSyncableForInternalSync; |
| +} |
| + |
| +void SyncFileSystemBackend::Initialize( |
| + const fileapi::FileSystemContext* context) { |
| + DCHECK(context); |
| + DCHECK(!sandbox_context()); |
| + set_sandbox_context(context->sandbox_context()); |
| + // Set quota observers. |
| + if (sandbox_context()->is_usage_tracking_enabled()) { |
| + set_update_observers(update_observers()->AddObserver( |
| + sandbox_context()->quota_observer(), |
| + sandbox_context()->file_task_runner())); |
| + set_access_observers(access_observers()->AddObserver( |
| + sandbox_context()->quota_observer(), NULL)); |
|
kinuko
2013/07/24 06:18:30
When do we use the parent class's update_observers
nhiroki
2013/07/24 10:22:58
Right, I realized we don't need to treat the those
|
| + syncable_update_observers_ = syncable_update_observers_.AddObserver( |
| + sandbox_context()->quota_observer(), |
| + sandbox_context()->file_task_runner()); |
| + } |
| +} |
| + |
| +void SyncFileSystemBackend::OpenFileSystem( |
| + const GURL& origin_url, |
| + fileapi::FileSystemType type, |
| + fileapi::OpenFileSystemMode mode, |
| + const OpenFileSystemCallback& callback) { |
| + // TODO(nhiroki): Implement SyncFileSystem's own OpenFileSystem. |
| + SandboxFileSystemBackend::OpenFileSystem(origin_url, type, mode, callback); |
|
kinuko
2013/07/24 06:18:30
What's your plan to proceed? I'm slightly not sure
nhiroki
2013/07/24 10:22:58
Let me explain... it was my plan that the followin
|
| +} |
| + |
| +fileapi::FileSystemFileUtil* SyncFileSystemBackend::GetFileUtil( |
| + fileapi::FileSystemType type) { |
| + DCHECK(sandbox_context()); |
| + return sandbox_context()->sync_file_util(); |
| +} |
| + |
| +fileapi::AsyncFileUtil* SyncFileSystemBackend::GetAsyncFileUtil( |
| + fileapi::FileSystemType type) { |
| + DCHECK(sandbox_context()); |
| + return sandbox_context()->file_util(); |
| +} |
| + |
| +fileapi::FileSystemOperation* |
| +SyncFileSystemBackend::CreateFileSystemOperation( |
| + const fileapi::FileSystemURL& url, |
| + fileapi::FileSystemContext* context, |
| + base::PlatformFileError* error_code) const { |
| + if (!IsAccessValid(url)) { |
| + *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
| + return NULL; |
| + } |
| + |
| + if (url.type() == fileapi::kFileSystemTypeSyncableForInternalSync) { |
| + return SandboxFileSystemBackend::CreateFileSystemOperation( |
| + url, context, error_code); |
| + } |
| + |
| + scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
| + new fileapi::FileSystemOperationContext(context)); |
| + operation_context->set_update_observers(syncable_update_observers_); |
| + operation_context->set_change_observers(syncable_change_observers_); |
| + |
| + return new SyncableFileSystemOperation( |
| + url, context, operation_context.Pass()); |
| +} |
| + |
| +void SyncFileSystemBackend::AddFileUpdateObserver( |
| + fileapi::FileSystemType type, |
| + fileapi::FileUpdateObserver* observer, |
| + base::SequencedTaskRunner* task_runner) { |
| + DCHECK(CanHandleType(type)); |
| + if (type == fileapi::kFileSystemTypeSyncableForInternalSync) { |
| + SandboxFileSystemBackend::AddFileUpdateObserver( |
| + type, observer, task_runner); |
| + return; |
| + } |
| + fileapi::UpdateObserverList* list = &syncable_update_observers_; |
| + *list = list->AddObserver(observer, task_runner); |
| +} |
| + |
| +void SyncFileSystemBackend::AddFileChangeObserver( |
| + fileapi::FileSystemType type, |
| + fileapi::FileChangeObserver* observer, |
| + base::SequencedTaskRunner* task_runner) { |
| + DCHECK(CanHandleType(type)); |
| + if (type == fileapi::kFileSystemTypeSyncableForInternalSync) { |
| + SandboxFileSystemBackend::AddFileChangeObserver( |
| + type, observer, task_runner); |
| + return; |
| + } |
| + fileapi::ChangeObserverList* list = &syncable_change_observers_; |
| + *list = list->AddObserver(observer, task_runner); |
| +} |
| + |
| +const fileapi::UpdateObserverList* SyncFileSystemBackend::GetUpdateObservers( |
| + fileapi::FileSystemType type) const { |
| + DCHECK(CanHandleType(type)); |
| + if (type == fileapi::kFileSystemTypeSyncableForInternalSync) |
| + return update_observers(); |
| + return &syncable_update_observers_; |
| +} |
| + |
| +const fileapi::ChangeObserverList* SyncFileSystemBackend::GetChangeObservers( |
| + fileapi::FileSystemType type) const { |
| + DCHECK(CanHandleType(type)); |
| + if (type == fileapi::kFileSystemTypeSyncableForInternalSync) |
| + return change_observers(); |
| + return &syncable_change_observers_; |
| +} |
| + |
| +// static |
| +SyncFileSystemBackend* SyncFileSystemBackend::GetBackend( |
| + const fileapi::FileSystemContext* file_system_context) { |
| + return static_cast<SyncFileSystemBackend*>( |
| + file_system_context->GetFileSystemBackend( |
| + fileapi::kFileSystemTypeSyncable)); |
| +} |
| + |
| +} // namespace sync_file_system |