test_browser_thread.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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. 4 5#include "content/public/test/test_browser_thread.h" 6 7#include "base/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" 11 12namespace content { 13 14class TestBrowserThreadImpl : public BrowserThreadImpl { 15 public: 16 explicit TestBrowserThreadImpl(BrowserThread::ID identifier) 17 : BrowserThreadImpl(identifier), 18 notification_service_(NULL) { 19 } 20 21 TestBrowserThreadImpl(BrowserThread::ID identifier, 22 MessageLoop* message_loop) 23 : BrowserThreadImpl(identifier, message_loop), 24 notification_service_(NULL) { 25 } 26 27 virtual ~TestBrowserThreadImpl() { 28 Stop(); 29 } 30 31 virtual void Init() OVERRIDE { 32 notification_service_ = new NotificationServiceImpl; 33 BrowserThreadImpl::Init(); 34 } 35 36 virtual void CleanUp() OVERRIDE { 37 delete notification_service_; 38 notification_service_ = NULL; 39 BrowserThreadImpl::CleanUp(); 40 } 41 42 private: 43 NotificationService* notification_service_; 44 45 DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl); 46}; 47 48TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier) 49 : impl_(new TestBrowserThreadImpl(identifier)) { 50} 51 52TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier, 53 MessageLoop* message_loop) 54 : impl_(new TestBrowserThreadImpl(identifier, message_loop)) { 55} 56 57TestBrowserThread::~TestBrowserThread() { 58 Stop(); 59} 60 61bool TestBrowserThread::Start() { 62 return impl_->Start(); 63} 64 65bool TestBrowserThread::StartIOThread() { 66 base::Thread::Options options; 67 options.message_loop_type = MessageLoop::TYPE_IO; 68 return impl_->StartWithOptions(options); 69} 70 71void TestBrowserThread::Stop() { 72 impl_->Stop(); 73} 74 75bool TestBrowserThread::IsRunning() { 76 return impl_->IsRunning(); 77} 78 79base::Thread* TestBrowserThread::DeprecatedGetThreadObject() { 80 return impl_.get(); 81} 82 83} // namespace content 84