| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_config_watcher_mac.h" | 5 #include "net/base/network_config_watcher_mac.h" |
| 6 | 6 |
| 7 #include <SystemConfiguration/SCDynamicStoreKey.h> | 7 #include <SystemConfiguration/SCDynamicStoreKey.h> |
| 8 #include <SystemConfiguration/SCSchemaDefinitions.h> | 8 #include <SystemConfiguration/SCSchemaDefinitions.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/threading/thread_restrictions.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Called back by OS. Calls OnNetworkConfigChange(). | 20 // Called back by OS. Calls OnNetworkConfigChange(). |
| 20 void DynamicStoreCallback(SCDynamicStoreRef /* store */, | 21 void DynamicStoreCallback(SCDynamicStoreRef /* store */, |
| 21 CFArrayRef changed_keys, | 22 CFArrayRef changed_keys, |
| 22 void* config_delegate) { | 23 void* config_delegate) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMacThread); | 48 DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMacThread); |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 NetworkConfigWatcherMacThread::NetworkConfigWatcherMacThread( | 51 NetworkConfigWatcherMacThread::NetworkConfigWatcherMacThread( |
| 51 NetworkConfigWatcherMac::Delegate* delegate) | 52 NetworkConfigWatcherMac::Delegate* delegate) |
| 52 : base::Thread("NetworkConfigWatcher"), | 53 : base::Thread("NetworkConfigWatcher"), |
| 53 delegate_(delegate), | 54 delegate_(delegate), |
| 54 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} | 55 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} |
| 55 | 56 |
| 56 NetworkConfigWatcherMacThread::~NetworkConfigWatcherMacThread() { | 57 NetworkConfigWatcherMacThread::~NetworkConfigWatcherMacThread() { |
| 57 Stop(); | 58 // As nothing in this thread is allowed to perform blocking I/O |
| 59 // we are save to permit this for the thread's termination. |
| 60 { |
| 61 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 62 Stop(); |
| 63 } |
| 58 } | 64 } |
| 59 | 65 |
| 60 void NetworkConfigWatcherMacThread::Init() { | 66 void NetworkConfigWatcherMacThread::Init() { |
| 67 base::ThreadRestrictions::SetIOAllowed(false); |
| 68 |
| 61 // TODO(willchan): Look to see if there's a better signal for when it's ok to | 69 // TODO(willchan): Look to see if there's a better signal for when it's ok to |
| 62 // initialize this, rather than just delaying it by a fixed time. | 70 // initialize this, rather than just delaying it by a fixed time. |
| 63 const int kInitializationDelayMS = 1000; | 71 const int kInitializationDelayMS = 1000; |
| 64 message_loop()->PostDelayedTask( | 72 message_loop()->PostDelayedTask( |
| 65 FROM_HERE, | 73 FROM_HERE, |
| 66 method_factory_.NewRunnableMethod( | 74 method_factory_.NewRunnableMethod( |
| 67 &NetworkConfigWatcherMacThread::InitNotifications), | 75 &NetworkConfigWatcherMacThread::InitNotifications), |
| 68 kInitializationDelayMS); | 76 kInitializationDelayMS); |
| 69 } | 77 } |
| 70 | 78 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // We create this notifier thread because the notification implementation | 112 // We create this notifier thread because the notification implementation |
| 105 // needs a thread with a CFRunLoop, and there's no guarantee that | 113 // needs a thread with a CFRunLoop, and there's no guarantee that |
| 106 // MessageLoop::current() meets that criterion. | 114 // MessageLoop::current() meets that criterion. |
| 107 base::Thread::Options thread_options(MessageLoop::TYPE_UI, 0); | 115 base::Thread::Options thread_options(MessageLoop::TYPE_UI, 0); |
| 108 notifier_thread_->StartWithOptions(thread_options); | 116 notifier_thread_->StartWithOptions(thread_options); |
| 109 } | 117 } |
| 110 | 118 |
| 111 NetworkConfigWatcherMac::~NetworkConfigWatcherMac() {} | 119 NetworkConfigWatcherMac::~NetworkConfigWatcherMac() {} |
| 112 | 120 |
| 113 } // namespace net | 121 } // namespace net |
| OLD | NEW |