| Index: chrome/browser/devtools/refcounted_adb_thread.cc
|
| diff --git a/chrome/browser/devtools/refcounted_adb_thread.cc b/chrome/browser/devtools/refcounted_adb_thread.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bc905329a6b5468e288c8076cdcf202e3b2972f7
|
| --- /dev/null
|
| +++ b/chrome/browser/devtools/refcounted_adb_thread.cc
|
| @@ -0,0 +1,52 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/devtools/refcounted_adb_thread.h"
|
| +
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +using content::BrowserThread;
|
| +
|
| +const char kDevToolsAdbBridgeThreadName[] = "Chrome_DevToolsADBThread";
|
| +
|
| +RefCountedAdbThread* RefCountedAdbThread::instance_ = NULL;
|
| +
|
| +// static
|
| +scoped_refptr<RefCountedAdbThread> RefCountedAdbThread::GetInstance() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + if (!instance_)
|
| + new RefCountedAdbThread();
|
| + return instance_;
|
| +}
|
| +
|
| +RefCountedAdbThread::RefCountedAdbThread() {
|
| + instance_ = this;
|
| + thread_ = new base::Thread(kDevToolsAdbBridgeThreadName);
|
| + base::Thread::Options options;
|
| + options.message_loop_type = base::MessageLoop::TYPE_IO;
|
| + if (!thread_->StartWithOptions(options)) {
|
| + delete thread_;
|
| + thread_ = NULL;
|
| + }
|
| +}
|
| +
|
| +base::MessageLoop* RefCountedAdbThread::message_loop() {
|
| + return thread_ ? thread_->message_loop() : NULL;
|
| +}
|
| +
|
| +// static
|
| +void RefCountedAdbThread::StopThread(base::Thread* thread) {
|
| + thread->Stop();
|
| +}
|
| +
|
| +RefCountedAdbThread::~RefCountedAdbThread() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + instance_ = NULL;
|
| + if (!thread_)
|
| + return;
|
| + // Shut down thread on FILE thread to join into IO.
|
| + BrowserThread::PostTask(
|
| + BrowserThread::FILE, FROM_HERE,
|
| + base::Bind(&RefCountedAdbThread::StopThread, thread_));
|
| +}
|
|
|