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 TestStorageMonitor::TestStorageMonitor()
20 media_transfer_protocol_manager_.reset(
21 new TestMediaTransferProtocolManagerLinux());
25 TestStorageMonitor::~TestStorageMonitor() {}
28 TestStorageMonitor* TestStorageMonitor::CreateAndInstall() {
29 TestStorageMonitor* monitor = new TestStorageMonitor();
30 scoped_ptr<StorageMonitor> pass_monitor(monitor);
32 monitor->MarkInitialized();
34 if (StorageMonitor::GetInstance() == NULL) {
35 StorageMonitor::SetStorageMonitorForTesting(pass_monitor.Pass());
43 TestStorageMonitor* TestStorageMonitor::CreateForBrowserTests() {
44 TestStorageMonitor* monitor = new TestStorageMonitor();
46 monitor->MarkInitialized();
48 scoped_ptr<StorageMonitor> pass_monitor(monitor);
49 StorageMonitor::SetStorageMonitorForTesting(pass_monitor.Pass());
55 void TestStorageMonitor::SyncInitialize() {
56 StorageMonitor* monitor = StorageMonitor::GetInstance();
57 if (monitor->IsInitialized())
60 base::WaitableEvent event(true, false);
61 monitor->EnsureInitialized(base::Bind(&base::WaitableEvent::Signal,
62 base::Unretained(&event)));
63 while (!event.IsSignaled()) {
64 base::RunLoop().RunUntilIdle();
66 DCHECK(monitor->IsInitialized());
69 void TestStorageMonitor::Init() {
73 void TestStorageMonitor::MarkInitialized() {
74 StorageMonitor::MarkInitialized();
77 bool TestStorageMonitor::GetStorageInfoForPath(
78 const base::FilePath& path,
79 StorageInfo* device_info) const {
82 if (!path.IsAbsolute())
85 std::string device_id = StorageInfo::MakeDeviceId(
86 StorageInfo::FIXED_MASS_STORAGE, path.AsUTF8Unsafe());
88 StorageInfo(device_id, path.BaseName().LossyDisplayName(), path.value(),
89 base::string16(), base::string16(), base::string16(), 0);
94 bool TestStorageMonitor::GetMTPStorageInfoFromDeviceId(
95 const std::string& storage_device_id,
96 base::string16* device_location,
97 base::string16* storage_object_id) const {
102 #if defined(OS_LINUX)
103 device::MediaTransferProtocolManager*
104 TestStorageMonitor::media_transfer_protocol_manager() {
105 return media_transfer_protocol_manager_.get();
109 StorageMonitor::Receiver* TestStorageMonitor::receiver() const {
110 return StorageMonitor::receiver();
113 void TestStorageMonitor::EjectDevice(
114 const std::string& device_id,
115 base::Callback<void(EjectStatus)> callback) {
116 ejected_device_ = device_id;
117 callback.Run(EJECT_OK);