OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browser/storage_monitor/test_storage_monitor.h" | 5 #include "chrome/browser/storage_monitor/test_storage_monitor.h" |
6 | 6 |
| 7 #include "base/run_loop.h" |
| 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/browser_process_impl.h" |
7 #include "chrome/browser/storage_monitor/storage_info.h" | 11 #include "chrome/browser/storage_monitor/storage_info.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" |
8 | 13 |
9 #if defined(OS_LINUX) | 14 #if defined(OS_LINUX) |
10 #include "chrome/browser/storage_monitor/test_media_transfer_protocol_manager_li
nux.h" | 15 #include "chrome/browser/storage_monitor/test_media_transfer_protocol_manager_li
nux.h" |
11 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 16 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
12 #endif | 17 #endif |
13 | 18 |
14 namespace chrome { | 19 namespace chrome { |
15 namespace test { | 20 namespace test { |
16 | 21 |
17 TestStorageMonitor::TestStorageMonitor() | 22 TestStorageMonitor::TestStorageMonitor() |
18 : StorageMonitor(), | 23 : StorageMonitor(), |
19 init_called_(false) { | 24 init_called_(false) { |
20 #if defined(OS_LINUX) | 25 #if defined(OS_LINUX) |
21 media_transfer_protocol_manager_.reset( | 26 media_transfer_protocol_manager_.reset( |
22 new TestMediaTransferProtocolManagerLinux()); | 27 new TestMediaTransferProtocolManagerLinux()); |
23 #endif | 28 #endif |
24 } | 29 } |
25 | 30 |
26 TestStorageMonitor::~TestStorageMonitor() {} | 31 TestStorageMonitor::~TestStorageMonitor() {} |
27 | 32 |
28 TestStorageMonitor* | 33 TestStorageMonitor* TestStorageMonitor::CreateAndInstall() { |
29 TestStorageMonitor::CreateForBrowserTests() { | 34 RemoveSingleton(); |
30 StorageMonitor::RemoveSingletonForTesting(); | 35 TestStorageMonitor* monitor = new TestStorageMonitor(); |
31 return new TestStorageMonitor(); | 36 scoped_ptr<StorageMonitor> pass_monitor(monitor); |
| 37 monitor->Init(); |
| 38 monitor->MarkInitialized(); |
| 39 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal(); |
| 40 if (browser_process) { |
| 41 browser_process->SetStorageMonitor(pass_monitor.Pass()); |
| 42 return monitor; |
| 43 } |
| 44 return NULL; |
| 45 } |
| 46 |
| 47 TestStorageMonitor* TestStorageMonitor::CreateForBrowserTests() { |
| 48 TestStorageMonitor* return_monitor = new TestStorageMonitor(); |
| 49 return_monitor->Init(); |
| 50 return_monitor->MarkInitialized(); |
| 51 |
| 52 scoped_ptr<StorageMonitor> monitor(return_monitor); |
| 53 BrowserProcessImpl* browser_process = |
| 54 static_cast<BrowserProcessImpl*>(g_browser_process); |
| 55 DCHECK(browser_process); |
| 56 browser_process->set_storage_monitor_for_test(monitor.Pass()); |
| 57 return return_monitor; |
| 58 } |
| 59 |
| 60 void TestStorageMonitor::RemoveSingleton() { |
| 61 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal(); |
| 62 if (browser_process) |
| 63 browser_process->SetStorageMonitor(scoped_ptr<StorageMonitor>()); |
| 64 } |
| 65 |
| 66 // static |
| 67 void TestStorageMonitor::SyncInitialize() { |
| 68 StorageMonitor* monitor = g_browser_process->storage_monitor(); |
| 69 if (monitor->IsInitialized()) |
| 70 return; |
| 71 |
| 72 base::WaitableEvent event(true, false); |
| 73 monitor->EnsureInitialized(base::Bind(&base::WaitableEvent::Signal, |
| 74 base::Unretained(&event))); |
| 75 while (!event.IsSignaled()) { |
| 76 base::RunLoop().RunUntilIdle(); |
| 77 } |
| 78 DCHECK(monitor->IsInitialized()); |
32 } | 79 } |
33 | 80 |
34 void TestStorageMonitor::Init() { | 81 void TestStorageMonitor::Init() { |
35 init_called_ = true; | 82 init_called_ = true; |
36 } | 83 } |
37 | 84 |
38 void TestStorageMonitor::MarkInitialized() { | 85 void TestStorageMonitor::MarkInitialized() { |
39 StorageMonitor::MarkInitialized(); | 86 StorageMonitor::MarkInitialized(); |
40 } | 87 } |
41 | 88 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 124 |
78 void TestStorageMonitor::EjectDevice( | 125 void TestStorageMonitor::EjectDevice( |
79 const std::string& device_id, | 126 const std::string& device_id, |
80 base::Callback<void(EjectStatus)> callback) { | 127 base::Callback<void(EjectStatus)> callback) { |
81 ejected_device_ = device_id; | 128 ejected_device_ = device_id; |
82 callback.Run(EJECT_OK); | 129 callback.Run(EJECT_OK); |
83 } | 130 } |
84 | 131 |
85 } // namespace test | 132 } // namespace test |
86 } // namespace chrome | 133 } // namespace chrome |
OLD | NEW |