1 // Copyright 2014 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.
5 #include "components/storage_monitor/test_storage_monitor.h"
7 #include "base/run_loop.h"
8 #include "base/synchronization/waitable_event.h"
9 #include "components/storage_monitor/storage_info.h"
12 #include "components/storage_monitor/test_media_transfer_protocol_manager_linux.h"
13 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
16 namespace storage_monitor
{
18 TestStorageMonitor::TestStorageMonitor()
22 media_transfer_protocol_manager_
.reset(
23 new TestMediaTransferProtocolManagerLinux());
27 TestStorageMonitor::~TestStorageMonitor() {}
30 TestStorageMonitor
* TestStorageMonitor::CreateAndInstall() {
31 TestStorageMonitor
* monitor
= new TestStorageMonitor();
32 scoped_ptr
<StorageMonitor
> pass_monitor(monitor
);
34 monitor
->MarkInitialized();
36 if (StorageMonitor::GetInstance() == NULL
) {
37 StorageMonitor::SetStorageMonitorForTesting(pass_monitor
.Pass());
45 TestStorageMonitor
* TestStorageMonitor::CreateForBrowserTests() {
46 TestStorageMonitor
* monitor
= new TestStorageMonitor();
48 monitor
->MarkInitialized();
50 scoped_ptr
<StorageMonitor
> pass_monitor(monitor
);
51 StorageMonitor::SetStorageMonitorForTesting(pass_monitor
.Pass());
57 void TestStorageMonitor::SyncInitialize() {
58 StorageMonitor
* monitor
= StorageMonitor::GetInstance();
59 if (monitor
->IsInitialized())
62 base::WaitableEvent
event(true, false);
63 monitor
->EnsureInitialized(base::Bind(&base::WaitableEvent::Signal
,
64 base::Unretained(&event
)));
65 while (!event
.IsSignaled()) {
66 base::RunLoop().RunUntilIdle();
68 DCHECK(monitor
->IsInitialized());
71 void TestStorageMonitor::Init() {
75 void TestStorageMonitor::MarkInitialized() {
76 StorageMonitor::MarkInitialized();
79 bool TestStorageMonitor::GetStorageInfoForPath(
80 const base::FilePath
& path
,
81 StorageInfo
* device_info
) const {
84 if (!path
.IsAbsolute())
87 std::string device_id
= StorageInfo::MakeDeviceId(
88 StorageInfo::FIXED_MASS_STORAGE
, path
.AsUTF8Unsafe());
90 StorageInfo(device_id
, path
.value(), base::string16(), base::string16(),
96 bool TestStorageMonitor::GetMTPStorageInfoFromDeviceId(
97 const std::string
& storage_device_id
,
98 base::string16
* device_location
,
99 base::string16
* storage_object_id
) const {
104 #if defined(OS_LINUX)
105 device::MediaTransferProtocolManager
*
106 TestStorageMonitor::media_transfer_protocol_manager() {
107 return media_transfer_protocol_manager_
.get();
111 StorageMonitor::Receiver
* TestStorageMonitor::receiver() const {
112 return StorageMonitor::receiver();
115 void TestStorageMonitor::EjectDevice(
116 const std::string
& device_id
,
117 base::Callback
<void(EjectStatus
)> callback
) {
118 ejected_device_
= device_id
;
119 callback
.Run(EJECT_OK
);
122 } // namespace storage_monitor