Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / public / test / test_browser_thread.cc
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:
16   explicit TestBrowserThreadImpl(BrowserThread::ID identifier)
17       : BrowserThreadImpl(identifier),
18         notification_service_(NULL) {
19   }
20
21   TestBrowserThreadImpl(BrowserThread::ID identifier,
22                         base::MessageLoop* message_loop)
23       : BrowserThreadImpl(identifier, message_loop),
24         notification_service_(NULL) {}
25
26   ~TestBrowserThreadImpl() override { Stop(); }
27
28   void Init() override {
29     notification_service_ = new NotificationServiceImpl;
30     BrowserThreadImpl::Init();
31   }
32
33   void CleanUp() override {
34     delete notification_service_;
35     notification_service_ = NULL;
36     BrowserThreadImpl::CleanUp();
37   }
38
39  private:
40   NotificationService* notification_service_;
41
42   DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl);
43 };
44
45 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier)
46     : impl_(new TestBrowserThreadImpl(identifier)) {
47 }
48
49 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier,
50                                      base::MessageLoop* message_loop)
51     : impl_(new TestBrowserThreadImpl(identifier, message_loop)) {}
52
53 TestBrowserThread::~TestBrowserThread() {
54   Stop();
55 }
56
57 bool TestBrowserThread::Start() {
58   return impl_->Start();
59 }
60
61 bool TestBrowserThread::StartIOThread() {
62   base::Thread::Options options;
63   options.message_loop_type = base::MessageLoop::TYPE_IO;
64   return impl_->StartWithOptions(options);
65 }
66
67 void TestBrowserThread::Stop() {
68   impl_->Stop();
69 }
70
71 bool TestBrowserThread::IsRunning() {
72   return impl_->IsRunning();
73 }
74
75 base::Thread* TestBrowserThread::DeprecatedGetThreadObject() {
76   return impl_.get();
77 }
78
79 }  // namespace content