| Index: remoting/base/auto_thread.h
|
| diff --git a/remoting/base/auto_thread.h b/remoting/base/auto_thread.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0a033d98ef12a080965db31019c7615322614446
|
| --- /dev/null
|
| +++ b/remoting/base/auto_thread.h
|
| @@ -0,0 +1,56 @@
|
| +// Copyright (c) 2012 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.
|
| +
|
| +#ifndef REMOTING_BASE_AUTO_THREAD_H_
|
| +#define REMOTING_BASE_AUTO_THREAD_H_
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/single_thread_task_runner.h"
|
| +#include "base/threading/thread.h"
|
| +
|
| +namespace remoting {
|
| +
|
| +// This class along with |scoped_refptr| provides automatic life time management
|
| +// for a thread running a message loop. The thread is stopped on the parent's
|
| +// message loop when the last |scoped_refptr| reference to |AutoThread| is
|
| +// deleted.
|
| +class AutoThread : public base::SingleThreadTaskRunner {
|
| + public:
|
| + AutoThread(
|
| + const char* name,
|
| + scoped_refptr<base::SingleThreadTaskRunner> parent);
|
| + virtual ~AutoThread();
|
| +
|
| + // Wrappers around the corresponding methods of |base::Thread|.
|
| + bool Start();
|
| + bool StartWithOptions(const base::Thread::Options& options);
|
| +
|
| + // SingleThreadTaskRunner implementation
|
| + virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + base::TimeDelta delay) OVERRIDE;
|
| + virtual bool PostNonNestableDelayedTask(
|
| + const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + base::TimeDelta delay) OVERRIDE;
|
| + virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
|
| +
|
| + protected:
|
| + // Stops the thread and deletes itself.
|
| + virtual void OnDestruct() const OVERRIDE;
|
| +
|
| + private:
|
| + // Parent task runner that will be used to destroy |this|.
|
| + scoped_refptr<base::SingleThreadTaskRunner> parent_;
|
| +
|
| + // Wrapper thread object.
|
| + base::Thread thread_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AutoThread);
|
| +};
|
| +
|
| +} // namespace remoting
|
| +
|
| +#endif // REMOTING_BASE_AUTO_THREAD_H_
|
|
|