| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #ifndef NET_DNS_NOTIFY_WATCHER_MAC_H_ |
| 6 #define NET_DNS_NOTIFY_WATCHER_MAC_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/callback.h" |
| 10 #include "base/message_loop.h" |
| 11 |
| 12 namespace net { |
| 13 |
| 14 // Watches for notifications from Libnotify and delivers them to a Callback. |
| 15 // After failure the watch is cancelled and will have to be restarted. |
| 16 class NotifyWatcherMac : public MessageLoopForIO::Watcher { |
| 17 public: |
| 18 // Called on received notification with true on success and false on error. |
| 19 typedef base::Callback<void(bool succeeded)> CallbackType; |
| 20 |
| 21 NotifyWatcherMac(); |
| 22 |
| 23 // When deleted, automatically cancels. |
| 24 virtual ~NotifyWatcherMac(); |
| 25 |
| 26 // Registers for notifications for |key|. Returns true if succeeds. If so, |
| 27 // will deliver asynchronous notifications and errors to |callback|. |
| 28 bool Watch(const char* key, const CallbackType& callback); |
| 29 |
| 30 // Cancels the watch. |
| 31 void Cancel(); |
| 32 |
| 33 private: |
| 34 // MessageLoopForIO::Watcher: |
| 35 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 36 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE {} |
| 37 |
| 38 int notify_fd_; |
| 39 int notify_token_; |
| 40 CallbackType callback_; |
| 41 MessageLoopForIO::FileDescriptorWatcher watcher_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(NotifyWatcherMac); |
| 44 }; |
| 45 |
| 46 } // namespace net |
| 47 |
| 48 #endif // NET_DNS_NOTIFY_WATCHER_MAC_H_ |
| OLD | NEW |