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_FILE_SYSTEM_WATCHER_MANAGER_H_ 6 #define STORAGE_BROWSER_FILE_SYSTEM_WATCHER_MANAGER_H_ 7 8 #include <vector> 9 10 #include "base/callback_forward.h" 11 #include "base/files/file.h" 12 13 namespace storage { 14 15 class FileSystemURL; 16 17 // An interface for providing entry observing capability for file system 18 // backends. 19 // 20 // All member functions must be called on the IO thread. Callbacks will be 21 // called on the IO thread. 22 // 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: 27 enum ChangeType { CHANGED, DELETED }; 28 29 using StatusCallback = base::OnceCallback<void(base::File::Error result)>; 30 using NotificationCallback = 31 base::RepeatingCallback<void(ChangeType change_type)>; 32 ~WatcherManager()33 virtual ~WatcherManager() {} 34 35 // Adds an entry watcher. If the |recursive| mode is not supported then 36 // FILE_ERROR_INVALID_OPERATION must be returned as an error. If the |url| is 37 // already watched with the same |recursive|, or setting up the watcher fails, 38 // then |callback| must be called with a specific error code. 39 // 40 // There may be up to two watchers for the same |url| as well as one of them 41 // is recursive, and the other one is not. 42 // 43 // In case of a success |callback| must be called with the FILE_OK error code. 44 // |notification_callback| is called for every change related to the watched 45 // directory. 46 virtual void AddWatcher(const FileSystemURL& url, 47 bool recursive, 48 StatusCallback callback, 49 NotificationCallback notification_callback) = 0; 50 51 // Removes a watcher represented by |url| in |recursive| mode. 52 virtual void RemoveWatcher(const FileSystemURL& url, 53 bool recursive, 54 StatusCallback callback) = 0; 55 }; 56 57 } // namespace storage 58 59 #endif // STORAGE_BROWSER_FILE_SYSTEM_WATCHER_MANAGER_H_ 60