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
10#include "base/basictypes.h"
11#include "base/callback_forward.h"
12#include "base/files/file.h"
13
14namespace base {
15class Time;
16}
17
18namespace storage {
19
20class FileSystemOperationContext;
21class FileSystemURL;
22
23// An interface for providing entry observing capability for file system
24// backends.
25//
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.
28class WatcherManager {
29 public:
30  typedef base::Callback<void(base::File::Error result)> StatusCallback;
31
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
45  virtual ~WatcherManager() {}
46
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
52  // 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|
54  // must be called with a specific error code. Otherwise |callback| must be
55  // called with the FILE_OK error code.
56  virtual void WatchDirectory(const FileSystemURL& url,
57                              bool recursive,
58                              const StatusCallback& callback) = 0;
59
60  // Stops observing an entry represented by |url|.
61  virtual void UnwatchEntry(const FileSystemURL& url,
62                            const StatusCallback& callback) = 0;
63};
64
65}  // namespace storage
66
67#endif  // STORAGE_BROWSER_FILEAPI_WATCHER_MANAGER_H_
68