blob: 8f3b6bd431317a9fe9398ad9042c4ecbd7752e71 [file] [log] [blame]
pilgrim4af8c212014-09-05 17:30:151// 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
pilgrim4af8c212014-09-05 17:30:1510#include "base/callback_forward.h"
11#include "base/files/file.h"
12
pilgrim4af8c212014-09-05 17:30:1513namespace storage {
14
pilgrim4af8c212014-09-05 17:30:1515class FileSystemURL;
16
17// An interface for providing entry observing capability for file system
18// backends.
19//
nyabf45258a2017-02-24 05:58:2120// All member functions must be called on the IO thread. Callbacks will be
21// called on the IO thread.
22//
pilgrim4af8c212014-09-05 17:30:1523// It is NOT valid to give null callback to this class, and implementors
24// can assume that they don't get any null callbacks.
25class WatcherManager {
26 public:
mtomasz340ba202014-10-31 05:53:4927 enum ChangeType { CHANGED, DELETED };
mtomaszb524db202014-10-27 06:42:1228
Joshua Bell3bad1f62018-04-24 05:15:0829 using StatusCallback = base::Callback<void(base::File::Error result)>;
30 using NotificationCallback = base::Callback<void(ChangeType change_type)>;
pilgrim4af8c212014-09-05 17:30:1531
32 virtual ~WatcherManager() {}
33
mtomasz340ba202014-10-31 05:53:4934 // Adds an entry watcher. If the |recursive| mode is not supported then
pilgrim4af8c212014-09-05 17:30:1535 // FILE_ERROR_INVALID_OPERATION must be returned as an error. If the |url| is
mtomasz340ba202014-10-31 05:53:4936 // 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(
mtomaszb524db202014-10-27 06:42:1246 const FileSystemURL& url,
47 bool recursive,
48 const StatusCallback& callback,
49 const NotificationCallback& notification_callback) = 0;
pilgrim4af8c212014-09-05 17:30:1550
mtomasz340ba202014-10-31 05:53:4951 // Removes a watcher represented by |url| in |recursive| mode.
52 virtual void RemoveWatcher(const FileSystemURL& url,
53 bool recursive,
54 const StatusCallback& callback) = 0;
pilgrim4af8c212014-09-05 17:30:1555};
56
57} // namespace storage
58
59#endif // STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_