pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_ |
| 6 | #define STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 10 | #include "base/callback_forward.h" |
| 11 | #include "base/files/file.h" |
| 12 | |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 13 | namespace storage { |
| 14 | |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 15 | class FileSystemURL; |
| 16 | |
| 17 | // An interface for providing entry observing capability for file system |
| 18 | // backends. |
| 19 | // |
nya | bf45258a | 2017-02-24 05:58:21 | [diff] [blame] | 20 | // All member functions must be called on the IO thread. Callbacks will be |
| 21 | // called on the IO thread. |
| 22 | // |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 23 | // It is NOT valid to give null callback to this class, and implementors |
| 24 | // can assume that they don't get any null callbacks. |
| 25 | class WatcherManager { |
| 26 | public: |
mtomasz | 340ba20 | 2014-10-31 05:53:49 | [diff] [blame] | 27 | enum ChangeType { CHANGED, DELETED }; |
mtomasz | b524db20 | 2014-10-27 06:42:12 | [diff] [blame] | 28 | |
Joshua Bell | 3bad1f6 | 2018-04-24 05:15:08 | [diff] [blame] | 29 | using StatusCallback = base::Callback<void(base::File::Error result)>; |
| 30 | using NotificationCallback = base::Callback<void(ChangeType change_type)>; |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 31 | |
| 32 | virtual ~WatcherManager() {} |
| 33 | |
mtomasz | 340ba20 | 2014-10-31 05:53:49 | [diff] [blame] | 34 | // Adds an entry watcher. If the |recursive| mode is not supported then |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 35 | // FILE_ERROR_INVALID_OPERATION must be returned as an error. If the |url| is |
mtomasz | 340ba20 | 2014-10-31 05:53:49 | [diff] [blame] | 36 | // already watched with the same |recursive|, or setting up the watcher fails, |
| 37 | // then |callback| must be called with a specific error code. |
| 38 | // |
| 39 | // There may be up to two watchers for the same |url| as well as one of them |
| 40 | // is recursive, and the other one is not. |
| 41 | // |
| 42 | // In case of a success |callback| must be called with the FILE_OK error code. |
| 43 | // |notification_callback| is called for every change related to the watched |
| 44 | // directory. |
| 45 | virtual void AddWatcher( |
mtomasz | b524db20 | 2014-10-27 06:42:12 | [diff] [blame] | 46 | const FileSystemURL& url, |
| 47 | bool recursive, |
| 48 | const StatusCallback& callback, |
| 49 | const NotificationCallback& notification_callback) = 0; |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 50 | |
mtomasz | 340ba20 | 2014-10-31 05:53:49 | [diff] [blame] | 51 | // Removes a watcher represented by |url| in |recursive| mode. |
| 52 | virtual void RemoveWatcher(const FileSystemURL& url, |
| 53 | bool recursive, |
| 54 | const StatusCallback& callback) = 0; |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace storage |
| 58 | |
| 59 | #endif // STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_ |