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.
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync_file_system/sync_callbacks.h"
10 #include "chrome/browser/sync_file_system/sync_status_code.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "storage/browser/fileapi/file_system_backend.h"
14 #include "storage/browser/fileapi/file_system_quota_util.h"
15 #include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h"
16 #include "storage/browser/fileapi/task_runner_bound_observer_list.h"
18 namespace sync_file_system {
20 class LocalFileChangeTracker;
21 class LocalFileSyncContext;
23 class SyncFileSystemBackend : public storage::FileSystemBackend {
25 explicit SyncFileSystemBackend(Profile* profile);
26 virtual ~SyncFileSystemBackend();
28 static SyncFileSystemBackend* CreateForTesting();
30 // FileSystemBackend overrides.
31 virtual bool CanHandleType(storage::FileSystemType type) const OVERRIDE;
32 virtual void Initialize(storage::FileSystemContext* context) OVERRIDE;
33 virtual void ResolveURL(const storage::FileSystemURL& url,
34 storage::OpenFileSystemMode mode,
35 const OpenFileSystemCallback& callback) OVERRIDE;
36 virtual storage::AsyncFileUtil* GetAsyncFileUtil(
37 storage::FileSystemType type) OVERRIDE;
38 virtual storage::WatcherManager* GetWatcherManager(
39 storage::FileSystemType type) OVERRIDE;
40 virtual storage::CopyOrMoveFileValidatorFactory*
41 GetCopyOrMoveFileValidatorFactory(storage::FileSystemType type,
42 base::File::Error* error_code) OVERRIDE;
43 virtual storage::FileSystemOperation* CreateFileSystemOperation(
44 const storage::FileSystemURL& url,
45 storage::FileSystemContext* context,
46 base::File::Error* error_code) const OVERRIDE;
47 virtual bool SupportsStreaming(
48 const storage::FileSystemURL& url) const OVERRIDE;
49 virtual bool HasInplaceCopyImplementation(
50 storage::FileSystemType type) const OVERRIDE;
51 virtual scoped_ptr<storage::FileStreamReader> CreateFileStreamReader(
52 const storage::FileSystemURL& url,
54 int64 max_bytes_to_read,
55 const base::Time& expected_modification_time,
56 storage::FileSystemContext* context) const OVERRIDE;
57 virtual scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter(
58 const storage::FileSystemURL& url,
60 storage::FileSystemContext* context) const OVERRIDE;
61 virtual storage::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE;
62 virtual const storage::UpdateObserverList* GetUpdateObservers(
63 storage::FileSystemType type) const OVERRIDE;
64 virtual const storage::ChangeObserverList* GetChangeObservers(
65 storage::FileSystemType type) const OVERRIDE;
66 virtual const storage::AccessObserverList* GetAccessObservers(
67 storage::FileSystemType type) const OVERRIDE;
69 static SyncFileSystemBackend* GetBackend(
70 const storage::FileSystemContext* context);
72 LocalFileChangeTracker* change_tracker() { return change_tracker_.get(); }
73 void SetLocalFileChangeTracker(scoped_ptr<LocalFileChangeTracker> tracker);
75 LocalFileSyncContext* sync_context() { return sync_context_.get(); }
76 void set_sync_context(LocalFileSyncContext* sync_context);
79 class ProfileHolder : public content::NotificationObserver {
81 explicit ProfileHolder(Profile* profile);
83 // NotificationObserver override.
84 virtual void Observe(int type,
85 const content::NotificationSource& source,
86 const content::NotificationDetails& details) OVERRIDE;
88 Profile* GetProfile();
91 content::NotificationRegistrar registrar_;
96 storage::FileSystemContext* context_;
98 scoped_ptr<LocalFileChangeTracker> change_tracker_;
99 scoped_refptr<LocalFileSyncContext> sync_context_;
101 // Should be accessed on the UI thread.
102 scoped_ptr<ProfileHolder> profile_holder_;
104 // A flag to skip the initialization sequence of SyncFileSystemService for
106 bool skip_initialize_syncfs_service_for_testing_;
108 storage::SandboxFileSystemBackendDelegate* GetDelegate() const;
110 void InitializeSyncFileSystemService(
111 const GURL& origin_url,
112 const SyncStatusCallback& callback);
113 void DidInitializeSyncFileSystemService(
114 storage::FileSystemContext* context,
115 const GURL& origin_url,
116 storage::FileSystemType type,
117 storage::OpenFileSystemMode mode,
118 const OpenFileSystemCallback& callback,
119 SyncStatusCode status);
121 DISALLOW_COPY_AND_ASSIGN(SyncFileSystemBackend);
124 } // namespace sync_file_system
126 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_