Regression: Search+Key pops up app launcher
[chromium-blink-merge.git] / components / storage_monitor / test_storage_monitor.cc
blobfb5cc57b1b92f899e1b0b97c971feb456e2af8b5
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"
11 #if defined(OS_LINUX)
12 #include "components/storage_monitor/test_media_transfer_protocol_manager_linux.h"
13 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
14 #endif
16 namespace storage_monitor {
18 TestStorageMonitor::TestStorageMonitor()
19 : StorageMonitor(),
20 init_called_(false) {
21 #if defined(OS_LINUX)
22 media_transfer_protocol_manager_.reset(
23 new TestMediaTransferProtocolManagerLinux());
24 #endif
27 TestStorageMonitor::~TestStorageMonitor() {}
29 // static
30 TestStorageMonitor* TestStorageMonitor::CreateAndInstall() {
31 TestStorageMonitor* monitor = new TestStorageMonitor();
32 scoped_ptr<StorageMonitor> pass_monitor(monitor);
33 monitor->Init();
34 monitor->MarkInitialized();
36 if (StorageMonitor::GetInstance() == NULL) {
37 StorageMonitor::SetStorageMonitorForTesting(pass_monitor.Pass());
38 return monitor;
41 return NULL;
44 // static
45 TestStorageMonitor* TestStorageMonitor::CreateForBrowserTests() {
46 TestStorageMonitor* monitor = new TestStorageMonitor();
47 monitor->Init();
48 monitor->MarkInitialized();
50 scoped_ptr<StorageMonitor> pass_monitor(monitor);
51 StorageMonitor::SetStorageMonitorForTesting(pass_monitor.Pass());
53 return monitor;
56 // static
57 void TestStorageMonitor::SyncInitialize() {
58 StorageMonitor* monitor = StorageMonitor::GetInstance();
59 if (monitor->IsInitialized())
60 return;
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() {
72 init_called_ = true;
75 void TestStorageMonitor::MarkInitialized() {
76 StorageMonitor::MarkInitialized();
79 bool TestStorageMonitor::GetStorageInfoForPath(
80 const base::FilePath& path,
81 StorageInfo* device_info) const {
82 DCHECK(device_info);
84 if (!path.IsAbsolute())
85 return false;
87 std::string device_id = StorageInfo::MakeDeviceId(
88 StorageInfo::FIXED_MASS_STORAGE, path.AsUTF8Unsafe());
89 *device_info =
90 StorageInfo(device_id, path.value(), base::string16(), base::string16(),
91 base::string16(), 0);
92 return true;
95 #if defined(OS_WIN)
96 bool TestStorageMonitor::GetMTPStorageInfoFromDeviceId(
97 const std::string& storage_device_id,
98 base::string16* device_location,
99 base::string16* storage_object_id) const {
100 return false;
102 #endif
104 #if defined(OS_LINUX)
105 device::MediaTransferProtocolManager*
106 TestStorageMonitor::media_transfer_protocol_manager() {
107 return media_transfer_protocol_manager_.get();
109 #endif
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