Tab Audio Mirroring: WebContentsAudioInputStream is a new implementation which repres...
[chromium-blink-merge.git] / base / thread_task_runner_handle.cc
blobd1b07aaaf012f9f63a7282de5fb758b6a8503e7d
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.
5 #include "base/thread_task_runner_handle.h"
7 #include "base/lazy_instance.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/threading/thread_local.h"
11 namespace base {
13 namespace {
15 base::LazyInstance<base::ThreadLocalPointer<ThreadTaskRunnerHandle> >
16 lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER;
18 } // namespace
20 // static
21 scoped_refptr<SingleThreadTaskRunner> ThreadTaskRunnerHandle::Get() {
22 ThreadTaskRunnerHandle* current = lazy_tls_ptr.Pointer()->Get();
23 DCHECK(current);
24 return current->task_runner_;
27 ThreadTaskRunnerHandle::ThreadTaskRunnerHandle(
28 const scoped_refptr<SingleThreadTaskRunner>& task_runner)
29 : task_runner_(task_runner) {
30 DCHECK(task_runner_->BelongsToCurrentThread());
31 DCHECK(!lazy_tls_ptr.Pointer()->Get());
32 lazy_tls_ptr.Pointer()->Set(this);
35 ThreadTaskRunnerHandle::~ThreadTaskRunnerHandle() {
36 DCHECK(task_runner_->BelongsToCurrentThread());
37 DCHECK_EQ(lazy_tls_ptr.Pointer()->Get(), this);
38 lazy_tls_ptr.Pointer()->Set(NULL);
41 } // namespace base