Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / public / test / test_browser_thread.cc
blobac67480fe5cd36b6cd515d866656e2687983a9f1
1 // Copyright (c) 2011 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 "content/public/test/test_browser_thread.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/threading/thread.h"
9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/notification_service_impl.h"
12 namespace content {
14 class TestBrowserThreadImpl : public BrowserThreadImpl {
15 public:
16 explicit TestBrowserThreadImpl(BrowserThread::ID identifier)
17 : BrowserThreadImpl(identifier),
18 notification_service_(NULL) {
21 TestBrowserThreadImpl(BrowserThread::ID identifier,
22 base::MessageLoop* message_loop)
23 : BrowserThreadImpl(identifier, message_loop),
24 notification_service_(NULL) {}
26 ~TestBrowserThreadImpl() override { Stop(); }
28 void Init() override {
29 notification_service_ = new NotificationServiceImpl;
30 BrowserThreadImpl::Init();
33 void CleanUp() override {
34 delete notification_service_;
35 notification_service_ = NULL;
36 BrowserThreadImpl::CleanUp();
39 private:
40 NotificationService* notification_service_;
42 DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl);
45 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier)
46 : impl_(new TestBrowserThreadImpl(identifier)) {
49 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier,
50 base::MessageLoop* message_loop)
51 : impl_(new TestBrowserThreadImpl(identifier, message_loop)) {}
53 TestBrowserThread::~TestBrowserThread() {
54 Stop();
57 bool TestBrowserThread::Start() {
58 return impl_->Start();
61 bool TestBrowserThread::StartIOThread() {
62 base::Thread::Options options;
63 options.message_loop_type = base::MessageLoop::TYPE_IO;
64 return impl_->StartWithOptions(options);
67 void TestBrowserThread::Stop() {
68 impl_->Stop();
71 bool TestBrowserThread::IsRunning() {
72 return impl_->IsRunning();
75 base::Thread* TestBrowserThread::DeprecatedGetThreadObject() {
76 return impl_.get();
79 } // namespace content