OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ |
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 class Profile; | 24 class Profile; |
25 | 25 |
26 namespace net { | 26 namespace net { |
27 class IOBuffer; | 27 class IOBuffer; |
28 } // namespace net | 28 } // namespace net |
29 | 29 |
30 namespace base { | 30 namespace base { |
31 class FilePath; | 31 class FilePath; |
32 } // namespace base | 32 } // namespace base |
33 | 33 |
34 namespace extensions { | |
35 class EventRouter; | |
36 } // namespace extensions | |
37 | |
38 namespace chromeos { | 34 namespace chromeos { |
39 namespace file_system_provider { | 35 namespace file_system_provider { |
40 | 36 |
| 37 // Define a policy that gets specific routers |
| 38 template <int source = Source_Type::extension> |
| 39 struct SourcePolicy : Source_Traits<source> { |
| 40 typedef typename Source_Traits<source>::EventRouterType EventRouterType; |
| 41 EventRouterType* Get(Profile* profile); |
| 42 }; |
| 43 |
41 class NotificationManagerInterface; | 44 class NotificationManagerInterface; |
42 | 45 |
43 // Automatically calls the |update_callback| after all of the callbacks created | 46 // Automatically calls the |update_callback| after all of the callbacks created |
44 // with |CreateCallback| are called. | 47 // with |CreateCallback| are called. |
45 // | 48 // |
46 // It's used to update tags of watchers once a notification about a change is | 49 // It's used to update tags of watchers once a notification about a change is |
47 // handled. It is to make sure that the change notification is fully handled | 50 // handled. It is to make sure that the change notification is fully handled |
48 // before remembering the new tag. | 51 // before remembering the new tag. |
49 // | 52 // |
50 // It is necessary to update the tag after all observers handle it fully, so | 53 // It is necessary to update the tag after all observers handle it fully, so |
(...skipping 15 matching lines...) Expand all Loading... |
66 | 69 |
67 virtual ~AutoUpdater(); | 70 virtual ~AutoUpdater(); |
68 | 71 |
69 base::Closure update_callback_; | 72 base::Closure update_callback_; |
70 int created_callbacks_; | 73 int created_callbacks_; |
71 int pending_callbacks_; | 74 int pending_callbacks_; |
72 }; | 75 }; |
73 | 76 |
74 // Provided file system implementation. Forwards requests between providers and | 77 // Provided file system implementation. Forwards requests between providers and |
75 // clients. | 78 // clients. |
76 class ProvidedFileSystem : public ProvidedFileSystemInterface { | 79 template <int source = Source_Type::extension> |
| 80 class ProvidedFileSystem : public ProvidedFileSystemInterface, |
| 81 public SourcePolicy<source> { |
77 public: | 82 public: |
78 ProvidedFileSystem(Profile* profile, | 83 ProvidedFileSystem(Profile* profile, |
79 const ProvidedFileSystemInfo& file_system_info); | 84 const ProvidedFileSystemInfo& file_system_info); |
80 ~ProvidedFileSystem() override; | 85 ~ProvidedFileSystem() override; |
81 | 86 |
82 // Sets a custom event router. Used in unit tests to mock out the real | 87 // Sets a custom event router. Used in unit tests to mock out the real |
83 // extension. | 88 // extension. |
84 void SetEventRouterForTesting(extensions::EventRouter* event_router); | 89 void SetEventRouterForTesting( |
| 90 typename SourcePolicy<source>::EventRouterType* event_router); |
85 | 91 |
86 // Sets a custom notification manager. It will recreate the request manager, | 92 // Sets a custom notification manager. It will recreate the request manager, |
87 // so is must be called just after creating ProvideFileSystem instance. | 93 // so is must be called just after creating ProvideFileSystem instance. |
88 // Used by unit tests. | 94 // Used by unit tests. |
89 void SetNotificationManagerForTesting( | 95 void SetNotificationManagerForTesting( |
90 scoped_ptr<NotificationManagerInterface> notification_manager); | 96 scoped_ptr<NotificationManagerInterface> notification_manager); |
91 | 97 |
92 // ProvidedFileSystemInterface overrides. | 98 // ProvidedFileSystemInterface overrides. |
93 AbortCallback RequestUnmount( | 99 AbortCallback RequestUnmount( |
94 const storage::AsyncFileUtil::StatusCallback& callback) override; | 100 const storage::AsyncFileUtil::StatusCallback& callback) override; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 const OpenFileCallback& callback, | 231 const OpenFileCallback& callback, |
226 int file_handle, | 232 int file_handle, |
227 base::File::Error result); | 233 base::File::Error result); |
228 | 234 |
229 // Called when closing a file is completed with either a success or an error. | 235 // Called when closing a file is completed with either a success or an error. |
230 void OnCloseFileCompleted( | 236 void OnCloseFileCompleted( |
231 int file_handle, | 237 int file_handle, |
232 const storage::AsyncFileUtil::StatusCallback& callback, | 238 const storage::AsyncFileUtil::StatusCallback& callback, |
233 base::File::Error result); | 239 base::File::Error result); |
234 | 240 |
235 Profile* profile_; // Not owned. | 241 // Not owned. |
236 extensions::EventRouter* event_router_; // Not owned. May be NULL. | 242 Profile* profile_; |
| 243 // Not owned. May be NULL |
| 244 typename SourcePolicy<source>::EventRouterType* event_router_; |
237 ProvidedFileSystemInfo file_system_info_; | 245 ProvidedFileSystemInfo file_system_info_; |
238 scoped_ptr<NotificationManagerInterface> notification_manager_; | 246 scoped_ptr<NotificationManagerInterface> notification_manager_; |
239 scoped_ptr<RequestManager> request_manager_; | 247 scoped_ptr<RequestManager> request_manager_; |
240 Watchers watchers_; | 248 Watchers watchers_; |
241 Queue watcher_queue_; | 249 Queue watcher_queue_; |
242 OpenedFiles opened_files_; | 250 OpenedFiles opened_files_; |
243 ObserverList<ProvidedFileSystemObserver> observers_; | 251 ObserverList<ProvidedFileSystemObserver> observers_; |
244 | 252 |
245 base::WeakPtrFactory<ProvidedFileSystem> weak_ptr_factory_; | 253 base::WeakPtrFactory<ProvidedFileSystem<source>> weak_ptr_factory_; |
246 DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystem); | 254 DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystem<source>); |
247 }; | 255 }; |
248 | 256 |
249 } // namespace file_system_provider | 257 } // namespace file_system_provider |
250 } // namespace chromeos | 258 } // namespace chromeos |
251 | 259 |
252 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ | 260 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ |
OLD | NEW |