Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: chrome/browser/file_path_watcher.h

Issue 5606002: Move:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/favicon_service.cc ('k') | chrome/browser/file_path_watcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 // This module provides a way to monitor a file or directory for changes.
6
7 #ifndef CHROME_BROWSER_FILE_PATH_WATCHER_H_
8 #define CHROME_BROWSER_FILE_PATH_WATCHER_H_
9 #pragma once
10
11 #include "base/basictypes.h"
12 #include "base/file_path.h"
13 #include "base/ref_counted.h"
14 #include "chrome/browser/browser_thread.h"
15
16 // This class lets you register interest in changes on a FilePath.
17 // The delegate will get called whenever the file or directory referenced by the
18 // FilePath is changed, including created or deleted. Due to limitations in the
19 // underlying OS APIs, spurious notifications might occur that don't relate to
20 // an actual change to the watch target.
21 class FilePathWatcher {
22 public:
23 // Declares the callback client code implements to receive notifications. Note
24 // that implementations of this interface should not keep a reference to the
25 // corresponding FileWatcher object to prevent a reference cycle.
26 class Delegate : public base::RefCountedThreadSafe<Delegate> {
27 public:
28 virtual ~Delegate() {}
29 virtual void OnFilePathChanged(const FilePath& path) = 0;
30 // Called when platform specific code detected an error. The watcher will
31 // not call OnFilePathChanged for future changes.
32 virtual void OnError() {}
33 };
34
35 FilePathWatcher();
36 ~FilePathWatcher();
37
38 // Register interest in any changes on |path|. OnPathChanged will be called
39 // back for each change. Returns true on success.
40 bool Watch(const FilePath& path, Delegate* delegate) WARN_UNUSED_RESULT;
41
42 // Used internally to encapsulate different members on different platforms.
43 class PlatformDelegate
44 : public base::RefCountedThreadSafe<PlatformDelegate,
45 BrowserThread::DeleteOnFileThread> {
46 public:
47 virtual ~PlatformDelegate() {}
48
49 // Start watching for the given |path| and notify |delegate| about changes.
50 virtual bool Watch(const FilePath& path, Delegate* delegate)
51 WARN_UNUSED_RESULT = 0;
52
53 // Stop watching. This is called from FilePathWatcher's dtor in order to
54 // allow to shut down properly while the object is still alive.
55 virtual void Cancel() {}
56 };
57
58 private:
59 scoped_refptr<PlatformDelegate> impl_;
60
61 DISALLOW_COPY_AND_ASSIGN(FilePathWatcher);
62 };
63
64 #endif // CHROME_BROWSER_FILE_PATH_WATCHER_H_
OLDNEW
« no previous file with comments | « chrome/browser/favicon_service.cc ('k') | chrome/browser/file_path_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698