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

Unified Diff: webkit/browser/fileapi/syncable/sync_file_system_backend.cc

Issue 18668003: SyncFS: Introduce SyncFileSystemBackend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lazy initialization Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
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..d64b48964a51c5dcae89edb2cd5d5476454936d5
--- /dev/null
+++ b/webkit/browser/fileapi/syncable/sync_file_system_backend.cc
@@ -0,0 +1,196 @@
+// 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 {
+
+namespace {
+const char kSyncableOriginsCountLabel[] = "FileSystem.SyncableOriginsCount";
+} // namespace
+
+SyncFileSystemBackend::SyncFileSystemBackend(
+ base::SequencedTaskRunner* file_task_runner,
+ const fileapi::FileSystemOptions& file_system_options)
+ : SandboxFileSystemBackend(NULL, file_task_runner, file_system_options) {
+}
+
+SyncFileSystemBackend::~SyncFileSystemBackend() {
+ file_task_runner_->DeleteSoon(FROM_HERE, change_tracker_.release());
+}
+
+bool SyncFileSystemBackend::CanHandleType(
+ fileapi::FileSystemType type) const {
+ return type == fileapi::kFileSystemTypeSyncable ||
+ type == fileapi::kFileSystemTypeSyncableForInternalSync;
+}
+
+void SyncFileSystemBackend::InitializeFileSystem(
+ const GURL& origin_url,
+ fileapi::FileSystemType type,
+ fileapi::OpenFileSystemMode mode,
+ fileapi::FileSystemContext* context,
+ const InitializeFileSystemCallback& callback) {
+ if (!sandbox_context_)
+ LazyInitialize(context->sandbox_context());
+ SandboxFileSystemBackend::InitializeFileSystem(
+ origin_url, type, mode, context, callback);
+}
+
+fileapi::FileSystemFileUtil* SyncFileSystemBackend::GetFileUtil(
+ fileapi::FileSystemType type,
+ const fileapi::FileSystemContext* context) {
+ if (!sandbox_context_)
+ LazyInitialize(context->sandbox_context());
+ return sandbox_context_->sync_file_util();
kinuko 2013/07/17 15:01:30 Have you checked when these GetFileUtil() and GetA
nhiroki 2013/07/22 04:34:14 Yes, I have checked. There is possibility to call
kinuko 2013/07/22 05:11:30 1) This is happening because we try to initialize
nhiroki 2013/07/23 05:02:12 Both cases looks inevitable, so I introduced the s
+}
+
+fileapi::AsyncFileUtil* SyncFileSystemBackend::GetAsyncFileUtil(
+ fileapi::FileSystemType type,
+ const fileapi::FileSystemContext* context) {
+ if (!sandbox_context_)
+ LazyInitialize(context->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::GetOriginsForTypeOnFileThread(
+ fileapi::FileSystemType type,
+ std::set<GURL>* origins) {
+ DCHECK(CanHandleType(type));
+ DCHECK(origins);
+ scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator());
+ GURL origin;
+ while (!(origin = enumerator->Next()).is_empty()) {
+ if (enumerator->HasFileSystemType(type))
+ origins->insert(origin);
+ }
+ switch (type) {
+ case fileapi::kFileSystemTypeSyncable:
+ UMA_HISTOGRAM_COUNTS(kSyncableOriginsCountLabel, origins->size());
+ break;
+ default:
+ break;
+ }
+}
+
+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));
+}
+
+void SyncFileSystemBackend::set_change_tracker(
+ scoped_ptr<LocalFileChangeTracker> tracker) {
+ DCHECK(!change_tracker_.get());
+ DCHECK(tracker.get());
+ change_tracker_ = tracker.Pass();
+ AddFileUpdateObserver(fileapi::kFileSystemTypeSyncable,
+ change_tracker_.get(),
+ file_task_runner_);
+ AddFileChangeObserver(fileapi::kFileSystemTypeSyncable,
+ change_tracker_.get(),
+ file_task_runner_);
+}
+
+void SyncFileSystemBackend::set_sync_context(
+ sync_file_system::LocalFileSyncContext* sync_context) {
+ sync_context_ = sync_context;
+}
+
+void SyncFileSystemBackend::LazyInitialize(
+ fileapi::SandboxContext* sandbox_context) {
+ DCHECK(!sandbox_context_);
+ sandbox_context_ = sandbox_context;
+ // Set quota observers.
+ if (enable_usage_tracking_) {
+ update_observers_ = update_observers_.AddObserver(
+ sandbox_context_->quota_observer(), file_task_runner_);
+ access_observers_ = access_observers_.AddObserver(
+ sandbox_context_->quota_observer(), NULL);
+ syncable_update_observers_ = syncable_update_observers_.AddObserver(
+ sandbox_context_->quota_observer(), file_task_runner_);
+ }
+}
+
+} // namespace sync_file_system

Powered by Google App Engine
This is Rietveld 408576698