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

Side by Side Diff: device/bluetooth/bluetooth_socket_thread.cc

Issue 276573004: Bluetooth: Implement new socket API for Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DCHECK nits Created 6 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
« no previous file with comments | « device/bluetooth/bluetooth_socket_thread.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "device/bluetooth/bluetooth_socket_thread.h" 5 #include "device/bluetooth/bluetooth_socket_thread.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/sequenced_task_runner.h" 8 #include "base/sequenced_task_runner.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 10
11 namespace device { 11 namespace device {
12 12
13 base::LazyInstance<scoped_refptr<BluetoothSocketThread> > g_instance = 13 base::LazyInstance<scoped_refptr<BluetoothSocketThread> > g_instance =
14 LAZY_INSTANCE_INITIALIZER; 14 LAZY_INSTANCE_INITIALIZER;
15 15
16 // static 16 // static
17 scoped_refptr<BluetoothSocketThread> BluetoothSocketThread::Get() { 17 scoped_refptr<BluetoothSocketThread> BluetoothSocketThread::Get() {
18 if (!g_instance.Get().get()) { 18 if (!g_instance.Get().get()) {
19 g_instance.Get() = new BluetoothSocketThread(); 19 g_instance.Get() = new BluetoothSocketThread();
20 } 20 }
21 return g_instance.Get(); 21 return g_instance.Get();
22 } 22 }
23 23
24 // static
25 void BluetoothSocketThread::CleanupForTesting() {
26 DCHECK(g_instance.Get());
27 g_instance.Get() = NULL;
28 }
29
24 BluetoothSocketThread::BluetoothSocketThread() 30 BluetoothSocketThread::BluetoothSocketThread()
25 : active_socket_count_(0) {} 31 : active_socket_count_(0) {}
26 32
27 BluetoothSocketThread::~BluetoothSocketThread() {} 33 BluetoothSocketThread::~BluetoothSocketThread() {
34 if (thread_) {
35 thread_->Stop();
36 thread_.reset(NULL);
37 task_runner_ = NULL;
38 }
39 }
28 40
29 void BluetoothSocketThread::OnSocketActivate() { 41 void BluetoothSocketThread::OnSocketActivate() {
30 DCHECK(thread_checker_.CalledOnValidThread()); 42 DCHECK(thread_checker_.CalledOnValidThread());
31 active_socket_count_++; 43 active_socket_count_++;
32 EnsureStarted(); 44 EnsureStarted();
33 } 45 }
34 46
35 void BluetoothSocketThread::OnSocketDeactivate() { 47 void BluetoothSocketThread::OnSocketDeactivate() {
36 DCHECK(thread_checker_.CalledOnValidThread()); 48 DCHECK(thread_checker_.CalledOnValidThread());
37 active_socket_count_--; 49 active_socket_count_--;
(...skipping 19 matching lines...) Expand all
57 scoped_refptr<base::SequencedTaskRunner> BluetoothSocketThread::task_runner() 69 scoped_refptr<base::SequencedTaskRunner> BluetoothSocketThread::task_runner()
58 const { 70 const {
59 DCHECK(active_socket_count_ > 0); 71 DCHECK(active_socket_count_ > 0);
60 DCHECK(thread_); 72 DCHECK(thread_);
61 DCHECK(task_runner_); 73 DCHECK(task_runner_);
62 74
63 return task_runner_; 75 return task_runner_;
64 } 76 }
65 77
66 } // namespace device 78 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_socket_thread.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698