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 STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_ | 5 #ifndef STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_ |
6 #define STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_ | 6 #define STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class Time; | 15 class Time; |
16 } | 16 } |
17 | 17 |
18 namespace storage { | 18 namespace storage { |
19 | 19 |
20 class FileSystemOperationContext; | 20 class FileSystemOperationContext; |
21 class FileSystemURL; | 21 class FileSystemURL; |
22 | 22 |
23 // An interface for providing entry observing capability for file system | 23 // An interface for providing entry observing capability for file system |
24 // backends. | 24 // backends. |
25 // | 25 // |
26 // It is NOT valid to give null callback to this class, and implementors | 26 // It is NOT valid to give null callback to this class, and implementors |
27 // can assume that they don't get any null callbacks. | 27 // can assume that they don't get any null callbacks. |
28 class WatcherManager { | 28 class WatcherManager { |
29 public: | 29 public: |
| 30 enum Action { CHANGED, REMOVED }; |
| 31 |
30 typedef base::Callback<void(base::File::Error result)> StatusCallback; | 32 typedef base::Callback<void(base::File::Error result)> StatusCallback; |
31 | 33 typedef base::Callback<void(Action action)> NotificationCallback; |
32 // Observes watched entries. | |
33 class Observer { | |
34 public: | |
35 Observer() {} | |
36 virtual ~Observer() {} | |
37 | |
38 // Notifies about an entry represented by |url| being changed. | |
39 virtual void OnEntryChanged(const FileSystemURL& url) = 0; | |
40 | |
41 // Notifies about an entry represented by |url| being removed. | |
42 virtual void OnEntryRemoved(const FileSystemURL& url) = 0; | |
43 }; | |
44 | 34 |
45 virtual ~WatcherManager() {} | 35 virtual ~WatcherManager() {} |
46 | 36 |
47 virtual void AddObserver(Observer* observer) = 0; | |
48 virtual void RemoveObserver(Observer* observer) = 0; | |
49 virtual bool HasObserver(Observer* observer) const = 0; | |
50 | |
51 // Observes a directory entry. If the |recursive| mode is not supported then | 37 // Observes a directory entry. If the |recursive| mode is not supported then |
52 // FILE_ERROR_INVALID_OPERATION must be returned as an error. If the |url| is | 38 // FILE_ERROR_INVALID_OPERATION must be returned as an error. If the |url| is |
53 // already watched, or setting up the watcher fails, then |callback| | 39 // already watched, or setting up the watcher fails, then |callback| |
54 // must be called with a specific error code. Otherwise |callback| must be | 40 // must be called with a specific error code. Otherwise |callback| must be |
55 // called with the FILE_OK error code. | 41 // called with the FILE_OK error code. |notification_callback| is called for |
56 virtual void WatchDirectory(const FileSystemURL& url, | 42 // every change related to the watched directory. |
57 bool recursive, | 43 virtual void WatchDirectory( |
58 const StatusCallback& callback) = 0; | 44 const FileSystemURL& url, |
| 45 bool recursive, |
| 46 const StatusCallback& callback, |
| 47 const NotificationCallback& notification_callback) = 0; |
59 | 48 |
60 // Stops observing an entry represented by |url|. | 49 // Stops observing an entry represented by |url|. |
61 virtual void UnwatchEntry(const FileSystemURL& url, | 50 virtual void UnwatchEntry(const FileSystemURL& url, |
62 const StatusCallback& callback) = 0; | 51 const StatusCallback& callback) = 0; |
63 }; | 52 }; |
64 | 53 |
65 } // namespace storage | 54 } // namespace storage |
66 | 55 |
67 #endif // STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_ | 56 #endif // STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_ |
OLD | NEW |