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::Create() { |
29 TestStorageMonitor::CreateForBrowserTests() { | 34 RemoveSingleton(); |
30 StorageMonitor::RemoveSingletonForTesting(); | 35 TestStorageMonitor* monitor = new TestStorageMonitor(); |
31 return new TestStorageMonitor(); | 36 monitor->Init(); |
37 monitor->MarkInitialized(); | |
38 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal(); | |
vandebo (ex-Chrome)
2013/07/10 16:57:45
This pattern looks like it is repeated in a lot of
Greg Billock
2013/07/10 21:11:16
I do where possible. Perhaps I should split out th
| |
39 if (browser_process) | |
vandebo (ex-Chrome)
2013/07/10 16:57:45
leak
Greg Billock
2013/07/10 21:57:17
Done.
| |
40 browser_process->SetStorageMonitor(monitor); | |
41 | |
42 return monitor; | |
43 } | |
44 | |
45 TestStorageMonitor* TestStorageMonitor::CreateForBrowserTests() { | |
46 TestStorageMonitor* return_monitor = new TestStorageMonitor(); | |
47 return_monitor->Init(); | |
48 return_monitor->MarkInitialized(); | |
49 | |
50 scoped_ptr<StorageMonitor> monitor(return_monitor); | |
51 BrowserProcessImpl* browser_process = | |
52 static_cast<BrowserProcessImpl*>(g_browser_process); | |
53 browser_process->set_storage_monitor_for_test(monitor.Pass()); | |
54 return return_monitor; | |
55 } | |
56 | |
57 void TestStorageMonitor::RemoveSingleton() { | |
58 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal(); | |
59 if (browser_process) | |
60 browser_process->SetStorageMonitor(NULL); | |
61 } | |
62 | |
63 // static | |
64 void TestStorageMonitor::SyncInitialize() { | |
vandebo (ex-Chrome)
2013/07/10 16:57:45
It seems like this method is only used from one te
Greg Billock
2013/07/10 21:11:16
I thought about that, but it seems more a util fix
| |
65 StorageMonitor* monitor = g_browser_process->storage_monitor(); | |
66 if (monitor->IsInitialized()) | |
67 return; | |
68 | |
69 base::WaitableEvent event(true, false); | |
70 monitor->EnsureInitialized(base::Bind(&base::WaitableEvent::Signal, | |
71 base::Unretained(&event))); | |
72 while (!event.IsSignaled()) { | |
73 base::RunLoop().RunUntilIdle(); | |
74 } | |
75 DCHECK(monitor->IsInitialized()); | |
32 } | 76 } |
33 | 77 |
34 void TestStorageMonitor::Init() { | 78 void TestStorageMonitor::Init() { |
35 init_called_ = true; | 79 init_called_ = true; |
36 } | 80 } |
37 | 81 |
38 void TestStorageMonitor::MarkInitialized() { | 82 void TestStorageMonitor::MarkInitialized() { |
39 StorageMonitor::MarkInitialized(); | 83 StorageMonitor::MarkInitialized(); |
40 } | 84 } |
41 | 85 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 | 121 |
78 void TestStorageMonitor::EjectDevice( | 122 void TestStorageMonitor::EjectDevice( |
79 const std::string& device_id, | 123 const std::string& device_id, |
80 base::Callback<void(EjectStatus)> callback) { | 124 base::Callback<void(EjectStatus)> callback) { |
81 ejected_device_ = device_id; | 125 ejected_device_ = device_id; |
82 callback.Run(EJECT_OK); | 126 callback.Run(EJECT_OK); |
83 } | 127 } |
84 | 128 |
85 } // namespace test | 129 } // namespace test |
86 } // namespace chrome | 130 } // namespace chrome |
OLD | NEW |