| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/base/testing_io_thread_state.h" | 5 #include "chrome/test/base/testing_io_thread_state.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/time/tick_clock.h" | 11 #include "base/time/tick_clock.h" |
| 12 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
| 13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 | 15 |
| 16 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
| 17 #include "chromeos/dbus/dbus_thread_manager.h" | 17 #include "chromeos/dbus/dbus_thread_manager.h" |
| 18 #include "chromeos/network/network_handler.h" | 18 #include "chromeos/network/network_handler.h" |
| 19 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 19 #endif | 20 #endif |
| 20 | 21 |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 base::Closure ThreadSafeQuit(base::RunLoop* run_loop) { | 26 base::Closure ThreadSafeQuit(base::RunLoop* run_loop) { |
| 26 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 27 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 27 return run_loop->QuitClosure(); | 28 return run_loop->QuitClosure(); |
| 28 } else { | 29 } else { |
| 29 using base::Bind; | 30 using base::Bind; |
| 30 using base::IgnoreResult; | 31 using base::IgnoreResult; |
| 31 return Bind(IgnoreResult(&base::SingleThreadTaskRunner::PostTask), | 32 return Bind(IgnoreResult(&base::SingleThreadTaskRunner::PostTask), |
| 32 base::ThreadTaskRunnerHandle::Get(), FROM_HERE, | 33 base::ThreadTaskRunnerHandle::Get(), FROM_HERE, |
| 33 run_loop->QuitClosure()); | 34 run_loop->QuitClosure()); |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 | 37 |
| 37 } // namespace | 38 } // namespace |
| 38 | 39 |
| 39 namespace chrome { | 40 namespace chrome { |
| 40 | 41 |
| 41 TestingIOThreadState::TestingIOThreadState() { | 42 TestingIOThreadState::TestingIOThreadState() { |
| 42 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
| 43 // Needed by IOThread constructor. | 44 // Needed by IOThread constructor. |
| 44 chromeos::DBusThreadManager::Initialize(); | 45 chromeos::DBusThreadManager::Initialize(); |
| 46 bluez::BluezDBusManager::Initialize( |
| 47 chromeos::DBusThreadManager::Get()->GetSystemBus(), |
| 48 chromeos::DBusThreadManager::Get()->IsUsingStub( |
| 49 chromeos::DBusClientBundle::BLUETOOTH)); |
| 45 chromeos::NetworkHandler::Initialize(); | 50 chromeos::NetworkHandler::Initialize(); |
| 46 #endif | 51 #endif |
| 47 | 52 |
| 48 io_thread_state_.reset( | 53 io_thread_state_.reset( |
| 49 new IOThread(TestingBrowserProcess::GetGlobal()->local_state(), | 54 new IOThread(TestingBrowserProcess::GetGlobal()->local_state(), |
| 50 TestingBrowserProcess::GetGlobal()->policy_service(), | 55 TestingBrowserProcess::GetGlobal()->policy_service(), |
| 51 NULL, NULL)); | 56 NULL, NULL)); |
| 52 | 57 |
| 53 // Safe because there are no virtuals. | 58 // Safe because there are no virtuals. |
| 54 base::RunLoop run_loop; | 59 base::RunLoop run_loop; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 68 base::Bind(&TestingIOThreadState::Shutdown, | 73 base::Bind(&TestingIOThreadState::Shutdown, |
| 69 base::Unretained(this), | 74 base::Unretained(this), |
| 70 ThreadSafeQuit(&run_loop)))); | 75 ThreadSafeQuit(&run_loop)))); |
| 71 run_loop.Run(); | 76 run_loop.Run(); |
| 72 TestingBrowserProcess::GetGlobal()->SetIOThread(NULL); | 77 TestingBrowserProcess::GetGlobal()->SetIOThread(NULL); |
| 73 | 78 |
| 74 io_thread_state_.reset(); | 79 io_thread_state_.reset(); |
| 75 | 80 |
| 76 #if defined(OS_CHROMEOS) | 81 #if defined(OS_CHROMEOS) |
| 77 chromeos::NetworkHandler::Shutdown(); | 82 chromeos::NetworkHandler::Shutdown(); |
| 83 bluez::BluezDBusManager::Shutdown(); |
| 78 chromeos::DBusThreadManager::Shutdown(); | 84 chromeos::DBusThreadManager::Shutdown(); |
| 79 #endif | 85 #endif |
| 80 } | 86 } |
| 81 | 87 |
| 82 void TestingIOThreadState::Initialize(const base::Closure& done) { | 88 void TestingIOThreadState::Initialize(const base::Closure& done) { |
| 83 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 89 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 84 | 90 |
| 85 io_thread_state_->SetGlobalsForTesting(new IOThread::Globals()); | 91 io_thread_state_->SetGlobalsForTesting(new IOThread::Globals()); |
| 86 | 92 |
| 87 done.Run(); | 93 done.Run(); |
| 88 } | 94 } |
| 89 | 95 |
| 90 void TestingIOThreadState::Shutdown(const base::Closure& done) { | 96 void TestingIOThreadState::Shutdown(const base::Closure& done) { |
| 91 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 97 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 92 | 98 |
| 93 delete io_thread_state_->globals(); | 99 delete io_thread_state_->globals(); |
| 94 io_thread_state_->SetGlobalsForTesting(NULL); | 100 io_thread_state_->SetGlobalsForTesting(NULL); |
| 95 done.Run(); | 101 done.Run(); |
| 96 } | 102 } |
| 97 | 103 |
| 98 } // namespace chrome | 104 } // namespace chrome |
| OLD | NEW |