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

Side by Side Diff: net/dns/notify_watcher_mac.cc

Issue 9969190: [net/dns] Watch configd notifications to detect DnsConfig changes on Mac. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added comments. Created 8 years, 8 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 unified diff | Download patch
OLDNEW
(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 #include "net/dns/notify_watcher_mac.h"
6
7 #include <notify.h>
8
9 namespace net {
10
11 NotifyWatcherMac::NotifyWatcherMac() : notify_fd_(-1), notify_token_(-1) {}
12
13 NotifyWatcherMac::~NotifyWatcherMac() {
14 Cancel();
15 }
16
17 bool NotifyWatcherMac::Watch(const char* key, const CallbackType& callback) {
18 DCHECK(key);
Mark Mentovai 2012/04/17 16:27:43 #include "base/logging.h".
19 DCHECK(!callback.is_null());
20 Cancel();
21 uint32_t status = notify_register_file_descriptor(
22 key, &notify_fd_, 0, &notify_token_);
23 if (status != NOTIFY_STATUS_OK)
24 return false;
25 if (!MessageLoopForIO::current()->WatchFileDescriptor(
26 notify_fd_,
27 true,
28 MessageLoopForIO::WATCH_READ,
29 &watcher_,
30 this)) {
31 Cancel();
32 return false;
33 }
34 callback_ = callback;
35 return true;
36 }
37
38 void NotifyWatcherMac::Cancel() {
39 if (notify_fd_ >= 0) {
40 notify_cancel(notify_token_); // Also closes |notify_fd_|.
41 notify_fd_ = -1;
42 callback_.Reset();
Mark Mentovai 2012/04/17 16:27:43 Would you need to reset this even if notify_fd_ <=
szym 2012/04/17 19:39:31 This is set in line 34, only after status == NOTIF
43 watcher_.StopWatchingFileDescriptor();
Mark Mentovai 2012/04/17 16:27:43 Is this safe if you got to Cancel() because WatchF
szym 2012/04/17 19:39:31 This is always safe to call, see message_pump_libe
44 }
45 }
46
47 void NotifyWatcherMac::OnFileCanReadWithoutBlocking(int /* fd */) {
Mark Mentovai 2012/04/17 16:27:43 No /* */ necessary
48 int token;
49 int status = read(notify_fd_, &token, sizeof(token));
Mark Mentovai 2012/04/17 16:27:43 Always write HANDLE_EINTR around read. #include "b
50 if (status < 0) {
51 Cancel();
52 callback_.Run(false);
53 return;
54 }
55 // Ignoring |token| read to avoid possible endianness mismatch:
Mark Mentovai 2012/04/17 16:27:43 read -> value
56 // http://openradar.appspot.com/8821081
57 callback_.Run(true);
58 }
59
60 } // namespace net
61
Mark Mentovai 2012/04/17 16:27:43 No blank line at EOF.
szym 2012/04/17 19:39:31 As before. Lint complained about that.
OLDNEW
« net/dns/notify_watcher_mac.h ('K') | « net/dns/notify_watcher_mac.h ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698