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

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

Issue 6353008: Allow IO operations in destructor of net::NetworkConfigWatcherMacThread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/threading/thread_restrictions.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) {
23 NetworkConfigWatcherMac::Delegate* net_config_delegate = 24 NetworkConfigWatcherMac::Delegate* net_config_delegate =
(...skipping 23 matching lines...) Expand all
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() {
58 // Allow IO because Stop() calls PlatformThread::Join(), which is a blocking
59 // operation. This is expected during shutdown.
60 base::ThreadRestrictions::ScopedAllowIO allow_io;
61
57 Stop(); 62 Stop();
58 } 63 }
59 64
60 void NetworkConfigWatcherMacThread::Init() { 65 void NetworkConfigWatcherMacThread::Init() {
66 // Disallow IO to make sure NetworkConfigWatcherMacThread's helper thread does
67 // not perform blocking operations.
68 base::ThreadRestrictions::SetIOAllowed(false);
evanm 2011/01/20 22:07:29 Isn't this ok? It's a helper thread, no?
Raghu Simha 2011/01/20 22:17:45 Per email from willchan: "Add a ScopedAllowIO in
willchan no longer on Chromium 2011/01/20 22:47:10 I think we should add it, because if we're going t
69
61 // TODO(willchan): Look to see if there's a better signal for when it's ok to 70 // 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. 71 // initialize this, rather than just delaying it by a fixed time.
63 const int kInitializationDelayMS = 1000; 72 const int kInitializationDelayMS = 1000;
64 message_loop()->PostDelayedTask( 73 message_loop()->PostDelayedTask(
65 FROM_HERE, 74 FROM_HERE,
66 method_factory_.NewRunnableMethod( 75 method_factory_.NewRunnableMethod(
67 &NetworkConfigWatcherMacThread::InitNotifications), 76 &NetworkConfigWatcherMacThread::InitNotifications),
68 kInitializationDelayMS); 77 kInitializationDelayMS);
69 } 78 }
70 79
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // We create this notifier thread because the notification implementation 113 // We create this notifier thread because the notification implementation
105 // needs a thread with a CFRunLoop, and there's no guarantee that 114 // needs a thread with a CFRunLoop, and there's no guarantee that
106 // MessageLoop::current() meets that criterion. 115 // MessageLoop::current() meets that criterion.
107 base::Thread::Options thread_options(MessageLoop::TYPE_UI, 0); 116 base::Thread::Options thread_options(MessageLoop::TYPE_UI, 0);
108 notifier_thread_->StartWithOptions(thread_options); 117 notifier_thread_->StartWithOptions(thread_options);
109 } 118 }
110 119
111 NetworkConfigWatcherMac::~NetworkConfigWatcherMac() {} 120 NetworkConfigWatcherMac::~NetworkConfigWatcherMac() {}
112 121
113 } // namespace net 122 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698