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