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

Unified Diff: net/base/file_path_watcher_callback.h

Issue 9540011: [net] Add DNS-related signals and NetLog to NetworkChangeNotifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved DNS watch to a separate IO thread on mac. Created 8 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/file_path_watcher_callback.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
+
« no previous file with comments | « no previous file | net/base/file_path_watcher_callback.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698