Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "remoting/base/auto_thread.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/message_loop.h" | |
| 9 | |
| 10 namespace remoting { | |
| 11 | |
| 12 AutoThread::AutoThread(const char* name, | |
| 13 scoped_refptr<base::SingleThreadTaskRunner> parent) | |
| 14 : parent_(parent), | |
| 15 thread_(name) { | |
| 16 } | |
| 17 | |
| 18 bool AutoThread::Start() { | |
| 19 return thread_.Start(); | |
| 20 } | |
| 21 | |
| 22 bool AutoThread::StartWithOptions(const base::Thread::Options& options) { | |
| 23 return thread_.StartWithOptions(options); | |
| 24 } | |
| 25 | |
| 26 bool AutoThread::PostDelayedTask( | |
| 27 const tracked_objects::Location& from_here, | |
| 28 const base::Closure& task, | |
| 29 base::TimeDelta delay) { | |
| 30 thread_.message_loop()->PostDelayedTask(from_here, task, delay); | |
| 31 return true; | |
| 32 } | |
| 33 | |
| 34 bool AutoThread::PostNonNestableDelayedTask( | |
| 35 const tracked_objects::Location& from_here, | |
| 36 const base::Closure& task, | |
| 37 base::TimeDelta delay) { | |
| 38 thread_.message_loop()->PostNonNestableDelayedTask(from_here, task, delay); | |
| 39 return true; | |
| 40 } | |
| 41 | |
| 42 bool AutoThread::RunsTasksOnCurrentThread() const { | |
| 43 return MessageLoop::current() == thread_.message_loop(); | |
| 44 } | |
| 45 | |
| 46 void AutoThread::OnDestruct() const { | |
| 47 // Deletes |this| on the parent message loop. | |
| 48 parent_->DeleteSoon(FROM_HERE, this); | |
| 49 } | |
| 50 | |
| 51 AutoThread::~AutoThread() { | |
| 52 thread_.Stop(); | |
| 
 
Wez
2012/08/24 21:30:49
This arrangement means that once no-one needs the
 
alexeypa (please no reviews)
2012/08/27 21:19:40
Yeah, it is not good. Taking |thread_| owneship fr
 
 | |
| 53 } | |
| 54 | |
| 55 } // namespace remoting | |
| OLD | NEW |