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