| 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..fb069dfcc52331960b73a1bf0ca9d7d601f9b8cf
|
| --- /dev/null
|
| +++ b/base/file_path_component_watcher.h
|
| @@ -0,0 +1,69 @@
|
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// 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.
|
| +
|
| +#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
|
| +// parent directory for changes, whereas this watches each component in a file's
|
| +// path for changes.
|
| +// A watcher will only register a single notification.
|
| +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.
|
| + class Delegate : public base::RefCountedThreadSafe<Delegate> {
|
| + public:
|
| + virtual ~Delegate() {}
|
| + virtual void OnFilePathComponentsChanged(const FilePath& old_path,
|
| + const FilePath& new_path) = 0;
|
| + // Called when platform specific code detected an error. The watcher will
|
| + // not call OnFilePathChanged for future changes.
|
| + virtual void OnError() {}
|
| + };
|
| +
|
| + 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;
|
| +
|
| + // Used internally to encapsulate different members on different platforms.
|
| + class PlatformDelegate
|
| + : public base::RefCountedThreadSafe<PlatformDelegate> {
|
| + 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
|
| + // 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
|
| +
|
| +#endif // BASE_FILE_PATH_COMPONENT_WATCHER_H_
|
|
|