| Index: net/base/file_path_watcher_callback.h
|
| diff --git a/net/base/file_path_watcher_callback.h b/net/base/file_path_watcher_callback.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1f3bb94009553597f6fddb8728f09667d406a91f
|
| --- /dev/null
|
| +++ b/net/base/file_path_watcher_callback.h
|
| @@ -0,0 +1,60 @@
|
| +// Copyright (c) 2012 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.
|
| +
|
| +#ifndef NET_FILE_PATH_WATCHER_CALLBACK_H_
|
| +#define NET_FILE_PATH_WATCHER_CALLBACK_H_
|
| +#pragma once
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/callback.h"
|
| +#include "base/file_path.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/threading/non_thread_safe.h"
|
| +
|
| +namespace base {
|
| +namespace files {
|
| +class FilePathWatcher;
|
| +}
|
| +}
|
| +
|
| +namespace net {
|
| +
|
| +// Convenience wrapper which holds a FilePathWatcher and a
|
| +// FilePathWatcher::Delegate which forwards its calls to a Callback.
|
| +class FilePathWatcherCallback : public base::NonThreadSafe {
|
| + public:
|
| + FilePathWatcherCallback();
|
| + // When deleted, automatically cancels the FilePathWatcher.
|
| + virtual ~FilePathWatcherCallback();
|
| +
|
| + // Starts watching the file at |path|. Returns true if Watch succeeds.
|
| + // If so, the delegate will call callback.Run(true) from OnFilePathChanged and
|
| + // callback.Run(false) from OnFilePathError. After failure the watch is
|
| + // cancelled and will have to be restarted. If called again, the previous
|
| + // watch is cancelled.
|
| + bool Watch(const FilePath& path,
|
| + const base::Callback<void(bool succeeded)>& callback);
|
| +
|
| + // Cancels the current watch.
|
| + void Cancel();
|
| +
|
| + private:
|
| + class WatcherDelegate;
|
| +
|
| + void OnFilePathChanged();
|
| + void OnFilePathError();
|
| +
|
| + base::Callback<void(bool succeeded)> callback_;
|
| + scoped_ptr<base::files::FilePathWatcher> watcher_;
|
| + scoped_refptr<WatcherDelegate> delegate_;
|
| + DISALLOW_COPY_AND_ASSIGN(FilePathWatcherCallback);
|
| +};
|
| +
|
| +} // namespace net
|
| +
|
| +#endif // NET_FILE_PATH_WATCHER_CALLBACK_H_
|
| +
|
|
|