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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_ | 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_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_ |
7 | 7 |
| 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" |
8 #include "webkit/browser/fileapi/file_system_backend.h" | 13 #include "webkit/browser/fileapi/file_system_backend.h" |
9 #include "webkit/browser/fileapi/file_system_quota_util.h" | 14 #include "webkit/browser/fileapi/file_system_quota_util.h" |
10 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" | 15 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" |
11 | 16 |
12 namespace sync_file_system { | 17 namespace sync_file_system { |
13 | 18 |
14 class LocalFileChangeTracker; | 19 class LocalFileChangeTracker; |
15 class LocalFileSyncContext; | 20 class LocalFileSyncContext; |
16 | 21 |
17 class SyncFileSystemBackend | 22 class SyncFileSystemBackend |
18 : public fileapi::FileSystemBackend { | 23 : public fileapi::FileSystemBackend { |
19 public: | 24 public: |
20 SyncFileSystemBackend(); | 25 explicit SyncFileSystemBackend(Profile* profile); |
21 virtual ~SyncFileSystemBackend(); | 26 virtual ~SyncFileSystemBackend(); |
22 | 27 |
| 28 static SyncFileSystemBackend* CreateForTesting(); |
| 29 |
23 // FileSystemBackend overrides. | 30 // FileSystemBackend overrides. |
24 virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; | 31 virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; |
25 virtual void Initialize(fileapi::FileSystemContext* context) OVERRIDE; | 32 virtual void Initialize(fileapi::FileSystemContext* context) OVERRIDE; |
26 virtual void OpenFileSystem( | 33 virtual void OpenFileSystem( |
27 const GURL& origin_url, | 34 const GURL& origin_url, |
28 fileapi::FileSystemType type, | 35 fileapi::FileSystemType type, |
29 fileapi::OpenFileSystemMode mode, | 36 fileapi::OpenFileSystemMode mode, |
30 const OpenFileSystemCallback& callback) OVERRIDE; | 37 const OpenFileSystemCallback& callback) OVERRIDE; |
31 virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( | 38 virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( |
32 fileapi::FileSystemType type) OVERRIDE; | 39 fileapi::FileSystemType type) OVERRIDE; |
(...skipping 12 matching lines...) Expand all Loading... |
45 fileapi::FileSystemContext* context) const OVERRIDE; | 52 fileapi::FileSystemContext* context) const OVERRIDE; |
46 virtual scoped_ptr<fileapi::FileStreamWriter> CreateFileStreamWriter( | 53 virtual scoped_ptr<fileapi::FileStreamWriter> CreateFileStreamWriter( |
47 const fileapi::FileSystemURL& url, | 54 const fileapi::FileSystemURL& url, |
48 int64 offset, | 55 int64 offset, |
49 fileapi::FileSystemContext* context) const OVERRIDE; | 56 fileapi::FileSystemContext* context) const OVERRIDE; |
50 virtual fileapi::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; | 57 virtual fileapi::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; |
51 | 58 |
52 static SyncFileSystemBackend* GetBackend( | 59 static SyncFileSystemBackend* GetBackend( |
53 const fileapi::FileSystemContext* context); | 60 const fileapi::FileSystemContext* context); |
54 | 61 |
55 sync_file_system::LocalFileChangeTracker* change_tracker() { | 62 LocalFileChangeTracker* change_tracker() { return change_tracker_.get(); } |
56 return change_tracker_.get(); | 63 void SetLocalFileChangeTracker(scoped_ptr<LocalFileChangeTracker> tracker); |
57 } | |
58 void SetLocalFileChangeTracker( | |
59 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker); | |
60 | 64 |
61 sync_file_system::LocalFileSyncContext* sync_context() { | 65 LocalFileSyncContext* sync_context() { return sync_context_.get(); } |
62 return sync_context_.get(); | 66 void set_sync_context(LocalFileSyncContext* sync_context); |
63 } | |
64 void set_sync_context(sync_file_system::LocalFileSyncContext* sync_context); | |
65 | 67 |
66 private: | 68 private: |
67 // Owned by FileSystemContext. | 69 class ProfileHolder : public content::NotificationObserver { |
68 fileapi::SandboxFileSystemBackendDelegate* delegate_; | 70 public: |
| 71 explicit ProfileHolder(Profile* profile); |
69 | 72 |
70 scoped_ptr<sync_file_system::LocalFileChangeTracker> change_tracker_; | 73 // NotificationObserver override. |
71 scoped_refptr<sync_file_system::LocalFileSyncContext> sync_context_; | 74 virtual void Observe(int type, |
| 75 const content::NotificationSource& source, |
| 76 const content::NotificationDetails& details) OVERRIDE; |
| 77 |
| 78 Profile* GetProfile(); |
| 79 |
| 80 private: |
| 81 content::NotificationRegistrar registrar_; |
| 82 Profile* profile_; |
| 83 }; |
| 84 |
| 85 // Not owned. |
| 86 fileapi::FileSystemContext* context_; |
| 87 |
| 88 scoped_ptr<LocalFileChangeTracker> change_tracker_; |
| 89 scoped_refptr<LocalFileSyncContext> sync_context_; |
| 90 |
| 91 // Should be accessed on the UI thread. |
| 92 scoped_ptr<ProfileHolder> profile_holder_; |
| 93 |
| 94 // A flag to skip the initialization sequence of SyncFileSystemService for |
| 95 // testing. |
| 96 bool skip_initialize_syncfs_service_for_testing_; |
| 97 |
| 98 fileapi::SandboxFileSystemBackendDelegate* GetDelegate() const; |
| 99 |
| 100 void InitializeSyncFileSystemService( |
| 101 const GURL& origin_url, |
| 102 const SyncStatusCallback& callback); |
| 103 void DidInitializeSyncFileSystemService( |
| 104 fileapi::FileSystemContext* context, |
| 105 const GURL& origin_url, |
| 106 fileapi::FileSystemType type, |
| 107 fileapi::OpenFileSystemMode mode, |
| 108 const OpenFileSystemCallback& callback, |
| 109 SyncStatusCode status); |
72 | 110 |
73 DISALLOW_COPY_AND_ASSIGN(SyncFileSystemBackend); | 111 DISALLOW_COPY_AND_ASSIGN(SyncFileSystemBackend); |
74 }; | 112 }; |
75 | 113 |
76 } // namespace sync_file_system | 114 } // namespace sync_file_system |
77 | 115 |
78 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_ | 116 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_ |
OLD | NEW |