Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 "chrome/browser/devtools/refcounted_adb_thread.h" | |
| 6 | |
| 7 #include "content/public/browser/browser_thread.h" | |
| 8 | |
| 9 using content::BrowserThread; | |
| 10 | |
| 11 const char kDevToolsAdbBridgeThreadName[] = "Chrome_DevToolsADBThread"; | |
| 12 | |
| 13 // DevToolsAdbBridge::RefCountedAdbThread ------------------------------------- | |
|
Vladislav Kaznacheev
2013/10/17 20:17:37
Please delete this line
Dmitry Zvorygin
2013/10/21 07:40:29
Done.
| |
| 14 RefCountedAdbThread* RefCountedAdbThread::instance_ = NULL; | |
| 15 | |
| 16 // static | |
| 17 scoped_refptr<RefCountedAdbThread> RefCountedAdbThread::GetInstance() { | |
| 18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 19 if (!instance_) | |
| 20 new RefCountedAdbThread(); | |
| 21 return instance_; | |
| 22 } | |
| 23 | |
| 24 RefCountedAdbThread::RefCountedAdbThread() { | |
| 25 instance_ = this; | |
| 26 thread_ = new base::Thread(kDevToolsAdbBridgeThreadName); | |
| 27 base::Thread::Options options; | |
| 28 options.message_loop_type = base::MessageLoop::TYPE_IO; | |
| 29 if (!thread_->StartWithOptions(options)) { | |
| 30 delete thread_; | |
| 31 thread_ = NULL; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 base::MessageLoop* RefCountedAdbThread::message_loop() { | |
| 36 return thread_ ? thread_->message_loop() : NULL; | |
| 37 } | |
| 38 | |
| 39 // static | |
| 40 void RefCountedAdbThread::StopThread(base::Thread* thread) { | |
| 41 thread->Stop(); | |
| 42 } | |
| 43 | |
| 44 RefCountedAdbThread::~RefCountedAdbThread() { | |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 46 instance_ = NULL; | |
| 47 if (!thread_) | |
| 48 return; | |
| 49 // Shut down thread on FILE thread to join into IO. | |
| 50 BrowserThread::PostTask( | |
| 51 BrowserThread::FILE, FROM_HERE, | |
| 52 base::Bind(&RefCountedAdbThread::StopThread, thread_)); | |
| 53 } | |
| OLD | NEW |