Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/browser/fileapi/syncable/sync_file_system_backend.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "webkit/browser/fileapi/async_file_util_adapter.h" | |
| 10 #include "webkit/browser/fileapi/file_system_context.h" | |
| 11 #include "webkit/browser/fileapi/obfuscated_file_util.h" | |
| 12 #include "webkit/browser/fileapi/sandbox_quota_observer.h" | |
| 13 #include "webkit/browser/fileapi/syncable/syncable_file_system_operation.h" | |
| 14 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" | |
| 15 #include "webkit/common/fileapi/file_system_util.h" | |
| 16 | |
| 17 namespace sync_file_system { | |
| 18 | |
| 19 SyncFileSystemBackend::SyncFileSystemBackend( | |
| 20 const fileapi::FileSystemOptions& file_system_options) | |
| 21 : SandboxFileSystemBackend(NULL, file_system_options) { | |
| 22 } | |
| 23 | |
| 24 SyncFileSystemBackend::~SyncFileSystemBackend() { | |
| 25 } | |
| 26 | |
| 27 bool SyncFileSystemBackend::CanHandleType( | |
| 28 fileapi::FileSystemType type) const { | |
| 29 return type == fileapi::kFileSystemTypeSyncable || | |
| 30 type == fileapi::kFileSystemTypeSyncableForInternalSync; | |
| 31 } | |
| 32 | |
| 33 void SyncFileSystemBackend::Initialize( | |
| 34 const fileapi::FileSystemContext* context) { | |
| 35 DCHECK(context); | |
| 36 DCHECK(!sandbox_context()); | |
| 37 set_sandbox_context(context->sandbox_context()); | |
| 38 // Set quota observers. | |
| 39 if (sandbox_context()->is_usage_tracking_enabled()) { | |
| 40 set_update_observers(update_observers()->AddObserver( | |
| 41 sandbox_context()->quota_observer(), | |
| 42 sandbox_context()->file_task_runner())); | |
| 43 set_access_observers(access_observers()->AddObserver( | |
| 44 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
| |
| 45 syncable_update_observers_ = syncable_update_observers_.AddObserver( | |
| 46 sandbox_context()->quota_observer(), | |
| 47 sandbox_context()->file_task_runner()); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 void SyncFileSystemBackend::OpenFileSystem( | |
| 52 const GURL& origin_url, | |
| 53 fileapi::FileSystemType type, | |
| 54 fileapi::OpenFileSystemMode mode, | |
| 55 const OpenFileSystemCallback& callback) { | |
| 56 // TODO(nhiroki): Implement SyncFileSystem's own OpenFileSystem. | |
| 57 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
| |
| 58 } | |
| 59 | |
| 60 fileapi::FileSystemFileUtil* SyncFileSystemBackend::GetFileUtil( | |
| 61 fileapi::FileSystemType type) { | |
| 62 DCHECK(sandbox_context()); | |
| 63 return sandbox_context()->sync_file_util(); | |
| 64 } | |
| 65 | |
| 66 fileapi::AsyncFileUtil* SyncFileSystemBackend::GetAsyncFileUtil( | |
| 67 fileapi::FileSystemType type) { | |
| 68 DCHECK(sandbox_context()); | |
| 69 return sandbox_context()->file_util(); | |
| 70 } | |
| 71 | |
| 72 fileapi::FileSystemOperation* | |
| 73 SyncFileSystemBackend::CreateFileSystemOperation( | |
| 74 const fileapi::FileSystemURL& url, | |
| 75 fileapi::FileSystemContext* context, | |
| 76 base::PlatformFileError* error_code) const { | |
| 77 if (!IsAccessValid(url)) { | |
| 78 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | |
| 79 return NULL; | |
| 80 } | |
| 81 | |
| 82 if (url.type() == fileapi::kFileSystemTypeSyncableForInternalSync) { | |
| 83 return SandboxFileSystemBackend::CreateFileSystemOperation( | |
| 84 url, context, error_code); | |
| 85 } | |
| 86 | |
| 87 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | |
| 88 new fileapi::FileSystemOperationContext(context)); | |
| 89 operation_context->set_update_observers(syncable_update_observers_); | |
| 90 operation_context->set_change_observers(syncable_change_observers_); | |
| 91 | |
| 92 return new SyncableFileSystemOperation( | |
| 93 url, context, operation_context.Pass()); | |
| 94 } | |
| 95 | |
| 96 void SyncFileSystemBackend::AddFileUpdateObserver( | |
| 97 fileapi::FileSystemType type, | |
| 98 fileapi::FileUpdateObserver* observer, | |
| 99 base::SequencedTaskRunner* task_runner) { | |
| 100 DCHECK(CanHandleType(type)); | |
| 101 if (type == fileapi::kFileSystemTypeSyncableForInternalSync) { | |
| 102 SandboxFileSystemBackend::AddFileUpdateObserver( | |
| 103 type, observer, task_runner); | |
| 104 return; | |
| 105 } | |
| 106 fileapi::UpdateObserverList* list = &syncable_update_observers_; | |
| 107 *list = list->AddObserver(observer, task_runner); | |
| 108 } | |
| 109 | |
| 110 void SyncFileSystemBackend::AddFileChangeObserver( | |
| 111 fileapi::FileSystemType type, | |
| 112 fileapi::FileChangeObserver* observer, | |
| 113 base::SequencedTaskRunner* task_runner) { | |
| 114 DCHECK(CanHandleType(type)); | |
| 115 if (type == fileapi::kFileSystemTypeSyncableForInternalSync) { | |
| 116 SandboxFileSystemBackend::AddFileChangeObserver( | |
| 117 type, observer, task_runner); | |
| 118 return; | |
| 119 } | |
| 120 fileapi::ChangeObserverList* list = &syncable_change_observers_; | |
| 121 *list = list->AddObserver(observer, task_runner); | |
| 122 } | |
| 123 | |
| 124 const fileapi::UpdateObserverList* SyncFileSystemBackend::GetUpdateObservers( | |
| 125 fileapi::FileSystemType type) const { | |
| 126 DCHECK(CanHandleType(type)); | |
| 127 if (type == fileapi::kFileSystemTypeSyncableForInternalSync) | |
| 128 return update_observers(); | |
| 129 return &syncable_update_observers_; | |
| 130 } | |
| 131 | |
| 132 const fileapi::ChangeObserverList* SyncFileSystemBackend::GetChangeObservers( | |
| 133 fileapi::FileSystemType type) const { | |
| 134 DCHECK(CanHandleType(type)); | |
| 135 if (type == fileapi::kFileSystemTypeSyncableForInternalSync) | |
| 136 return change_observers(); | |
| 137 return &syncable_change_observers_; | |
| 138 } | |
| 139 | |
| 140 // static | |
| 141 SyncFileSystemBackend* SyncFileSystemBackend::GetBackend( | |
| 142 const fileapi::FileSystemContext* file_system_context) { | |
| 143 return static_cast<SyncFileSystemBackend*>( | |
| 144 file_system_context->GetFileSystemBackend( | |
| 145 fileapi::kFileSystemTypeSyncable)); | |
| 146 } | |
| 147 | |
| 148 } // namespace sync_file_system | |
| OLD | NEW |