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

Side by Side Diff: net/base/network_change_notifier_win.cc

Issue 10377092: [net/dns] Isolate DnsConfigWatcher from DnsConfigService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Braces. Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/network_change_notifier_win.h" 5 #include "net/base/network_change_notifier_win.h"
6 6
7 #include <iphlpapi.h> 7 #include <iphlpapi.h>
8 #include <winsock2.h> 8 #include <winsock2.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/threading/thread.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "net/base/winsock_init.h" 15 #include "net/base/winsock_init.h"
16 #include "net/dns/dns_config_watcher.h"
15 17
16 #pragma comment(lib, "iphlpapi.lib") 18 #pragma comment(lib, "iphlpapi.lib")
17 19
20 namespace net {
21
18 namespace { 22 namespace {
19 23
20 // Time between NotifyAddrChange retries, on failure. 24 // Time between NotifyAddrChange retries, on failure.
21 const int kWatchForAddressChangeRetryIntervalMs = 500; 25 const int kWatchForAddressChangeRetryIntervalMs = 500;
22 26
23 } // namespace 27 } // namespace
24 28
25 namespace net { 29 // Thread on which we can run DnsConfigWatcher, which requires AssertIOAllowed
30 // to open registry keys and to handle FilePathWatcher updates.
31 class NetworkChangeNotifierWin::DnsWatcherThread : public base::Thread {
32 public:
33 DnsWatcherThread() : base::Thread("NetworkChangeNotifier") {}
34
35 virtual ~DnsWatcherThread() {
36 Stop();
37 }
38
39 virtual void Init() OVERRIDE {
40 watcher_.Init();
41 }
42
43 virtual void CleanUp() OVERRIDE {
44 watcher_.CleanUp();
45 }
46
47 private:
48 internal::DnsConfigWatcher watcher_;
49
50 DISALLOW_COPY_AND_ASSIGN(DnsWatcherThread);
51 };
26 52
27 NetworkChangeNotifierWin::NetworkChangeNotifierWin() 53 NetworkChangeNotifierWin::NetworkChangeNotifierWin()
28 : is_watching_(false), 54 : is_watching_(false),
29 sequential_failures_(0), 55 sequential_failures_(0),
30 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 56 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
57 dns_watcher_thread_(new DnsWatcherThread()) {
31 memset(&addr_overlapped_, 0, sizeof addr_overlapped_); 58 memset(&addr_overlapped_, 0, sizeof addr_overlapped_);
32 addr_overlapped_.hEvent = WSACreateEvent(); 59 addr_overlapped_.hEvent = WSACreateEvent();
60 dns_watcher_thread_->StartWithOptions(
61 base::Thread::Options(MessageLoop::TYPE_IO, 0));
33 } 62 }
34 63
35 NetworkChangeNotifierWin::~NetworkChangeNotifierWin() { 64 NetworkChangeNotifierWin::~NetworkChangeNotifierWin() {
36 if (is_watching_) { 65 if (is_watching_) {
37 CancelIPChangeNotify(&addr_overlapped_); 66 CancelIPChangeNotify(&addr_overlapped_);
38 addr_watcher_.StopWatching(); 67 addr_watcher_.StopWatching();
39 } 68 }
40 WSACloseEvent(addr_overlapped_.hEvent); 69 WSACloseEvent(addr_overlapped_.hEvent);
41 } 70 }
42 71
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 262
234 addr_watcher_.StartWatching(addr_overlapped_.hEvent, this); 263 addr_watcher_.StartWatching(addr_overlapped_.hEvent, this);
235 return true; 264 return true;
236 } 265 }
237 266
238 void NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange() { 267 void NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange() {
239 NotifyObserversOfOnlineStateChange(); 268 NotifyObserversOfOnlineStateChange();
240 } 269 }
241 270
242 } // namespace net 271 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698