Chromium Code Reviews| Index: base/file_path_component_watcher.h |
| diff --git a/base/file_path_component_watcher.h b/base/file_path_component_watcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..03b3240bcc0730f6ef6ea6bb5951ac3ad55b5afb |
| --- /dev/null |
| +++ b/base/file_path_component_watcher.h |
| @@ -0,0 +1,69 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
|
Mark Mentovai
2011/03/11 20:13:52
What year is it?
Throughout the entire change, th
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// This module provides a way to monitor a filepath for changes in the path. |
|
TVL
2011/03/11 14:03:54
chrome/browser/file_path_watcher/file_path_watcher
Mark Mentovai
2011/03/11 20:13:52
TVL wrote:
Mark Mentovai
2011/03/11 20:13:52
filepath is two words.
|
| + |
| +#ifndef BASE_FILE_PATH_COMPONENT_WATCHER_H_ |
| +#define BASE_FILE_PATH_COMPONENT_WATCHER_H_ |
| +#pragma once |
| + |
| +#include "base/basictypes.h" |
| +#include "base/file_path.h" |
| +#include "base/ref_counted.h" |
| + |
| +namespace base { |
| +// This class lets you register interest in changes on a FilePath. |
| +// The delegate will get called whenever any components of a FilePath are |
| +// changed (moved, deleted, attributes changed). This is different from |
| +// FilePathWatcher, in that FilePathWatcher watches a single file, and it's |
|
Mark Mentovai
2011/03/11 20:13:52
"single file, and it's" -> "single file and its"
|
| +// parent directory for changes, whereas this watches each component in a file's |
| +// path for changes. |
| +class FilePathComponentWatcher { |
| + public: |
| + // Declares the callback client code implements to receive notifications. Note |
| + // that implementations of this interface should not keep a reference to the |
| + // corresponding FileWatcher object to prevent a reference cycle. |
|
Mark Mentovai
2011/03/11 20:13:52
What’s a FileWatcher object?
|
| + class Delegate : public base::RefCountedThreadSafe<Delegate> { |
| + public: |
| + virtual ~Delegate() {} |
| + virtual void OnFilePathComponentsChanged(FilePathComponentWatcher* watcher, |
| + const FilePath& old_path, |
| + const FilePath& new_path) = 0; |
| + // Called when platform specific code detected an error. The watcher will |
|
Mark Mentovai
2011/03/11 20:13:52
Blank line before.
|
| + // not call OnFilePathChanged for future changes. |
| + virtual void OnError(FilePathComponentWatcher* watcher) {} |
| + }; |
| + |
| + FilePathComponentWatcher(); |
| + ~FilePathComponentWatcher(); |
| + |
| + // Register interest in any changes on |path|. OnPathChanged will be called |
| + // back for each change. Returns true on success. |
| + bool Watch(const FilePath& path, Delegate* delegate) WARN_UNUSED_RESULT; |
|
Mark Mentovai
2011/03/11 20:13:52
Are you supposed to be able to call Watch twice on
|
| + |
| + // Used internally to encapsulate different members on different platforms. |
|
Mark Mentovai
2011/03/11 20:13:52
I’m going to hold off on a thorough review of the
|
| + class PlatformDelegate |
| + : public base::RefCountedThreadSafe<PlatformDelegate> { |
|
Mark Mentovai
2011/03/11 20:13:52
What I just said notwithstanding…
Why is the plat
|
| + public: |
| + virtual ~PlatformDelegate() {} |
| + |
| + // Start watching for the given |path| and notify |delegate| about changes. |
| + virtual bool Watch(const FilePath& path, Delegate* delegate) |
| + WARN_UNUSED_RESULT = 0; |
| + |
| + // Stop watching. This is called from FilePathComponentWatcher's dtor |
|
Mark Mentovai
2011/03/11 20:13:52
Spell things out. Destructor, not dtor.
|
| + // in order to allow it to shut down properly while the object is still |
| + // alive. |
| + virtual void Cancel() {} |
| + }; |
| + |
| + private: |
| + scoped_refptr<PlatformDelegate> impl_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FilePathComponentWatcher); |
| +}; |
| + |
| +} // namespace |
|
Mark Mentovai
2011/03/11 20:13:52
} // namespace base
|
| + |
| +#endif // BASE_FILE_PATH_COMPONENT_WATCHER_H_ |