Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / dns / notify_watcher_mac.h
blob01375d5663755480b933d5a48f2af4ebd65ccd09
1 // Copyright (c) 2012 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.
5 #ifndef NET_DNS_NOTIFY_WATCHER_MAC_H_
6 #define NET_DNS_NOTIFY_WATCHER_MAC_H_
8 #include "base/callback.h"
9 #include "base/message_loop/message_loop.h"
11 namespace net {
13 // Watches for notifications from Libnotify and delivers them to a Callback.
14 // After failure the watch is cancelled and will have to be restarted.
15 class NotifyWatcherMac : public base::MessageLoopForIO::Watcher {
16 public:
17 // Called on received notification with true on success and false on error.
18 typedef base::Callback<void(bool succeeded)> CallbackType;
20 NotifyWatcherMac();
22 // When deleted, automatically cancels.
23 virtual ~NotifyWatcherMac();
25 // Registers for notifications for |key|. Returns true if succeeds. If so,
26 // will deliver asynchronous notifications and errors to |callback|.
27 bool Watch(const char* key, const CallbackType& callback);
29 // Cancels the watch.
30 void Cancel();
32 private:
33 // MessageLoopForIO::Watcher:
34 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
35 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE {}
37 int notify_fd_;
38 int notify_token_;
39 CallbackType callback_;
40 base::MessageLoopForIO::FileDescriptorWatcher watcher_;
42 DISALLOW_COPY_AND_ASSIGN(NotifyWatcherMac);
45 } // namespace net
47 #endif // NET_DNS_NOTIFY_WATCHER_MAC_H_