NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / devtools / refcounted_adb_thread.cc
blob4a202ae9f5c00e79d07c01078f490e606a792af7
1 // Copyright 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.
5 #include "chrome/browser/devtools/refcounted_adb_thread.h"
7 #include "content/public/browser/browser_thread.h"
9 using content::BrowserThread;
11 const char kDevToolsAdbBridgeThreadName[] = "Chrome_DevToolsADBThread";
13 RefCountedAdbThread* RefCountedAdbThread::instance_ = NULL;
15 // static
16 scoped_refptr<RefCountedAdbThread> RefCountedAdbThread::GetInstance() {
17 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
18 if (!instance_)
19 new RefCountedAdbThread();
20 return instance_;
23 RefCountedAdbThread::RefCountedAdbThread() {
24 instance_ = this;
25 thread_ = new base::Thread(kDevToolsAdbBridgeThreadName);
26 base::Thread::Options options;
27 options.message_loop_type = base::MessageLoop::TYPE_IO;
28 if (!thread_->StartWithOptions(options)) {
29 delete thread_;
30 thread_ = NULL;
34 base::MessageLoop* RefCountedAdbThread::message_loop() {
35 return thread_ ? thread_->message_loop() : NULL;
38 // static
39 void RefCountedAdbThread::StopThread(base::Thread* thread) {
40 thread->Stop();
43 RefCountedAdbThread::~RefCountedAdbThread() {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45 instance_ = NULL;
46 if (!thread_)
47 return;
48 // Shut down thread on FILE thread to join into IO.
49 BrowserThread::PostTask(
50 BrowserThread::FILE, FROM_HERE,
51 base::Bind(&RefCountedAdbThread::StopThread, thread_));