[Eraser strings] Remove/replace some supervised user strings
[chromium-blink-merge.git] / components / storage_monitor / test_storage_monitor.cc
blob95a8198112ee6fe14d7eb687d07ab3c1f0c7acf8
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 bool is_removable = false;
88 for (const base::FilePath& removable : removable_paths_) {
89 if (path == removable || removable.IsParent(path)) {
90 is_removable = true;
91 break;
95 std::string device_id = StorageInfo::MakeDeviceId(
96 is_removable ? StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM
97 : StorageInfo::FIXED_MASS_STORAGE,
98 path.AsUTF8Unsafe());
99 *device_info =
100 StorageInfo(device_id, path.value(), base::string16(), base::string16(),
101 base::string16(), 0);
102 return true;
105 #if defined(OS_WIN)
106 bool TestStorageMonitor::GetMTPStorageInfoFromDeviceId(
107 const std::string& storage_device_id,
108 base::string16* device_location,
109 base::string16* storage_object_id) const {
110 return false;
112 #endif
114 #if defined(OS_LINUX)
115 device::MediaTransferProtocolManager*
116 TestStorageMonitor::media_transfer_protocol_manager() {
117 return media_transfer_protocol_manager_.get();
119 #endif
121 StorageMonitor::Receiver* TestStorageMonitor::receiver() const {
122 return StorageMonitor::receiver();
125 void TestStorageMonitor::EjectDevice(
126 const std::string& device_id,
127 base::Callback<void(EjectStatus)> callback) {
128 ejected_device_ = device_id;
129 callback.Run(EJECT_OK);
132 void TestStorageMonitor::AddRemovablePath(const base::FilePath& path) {
133 CHECK(path.IsAbsolute());
134 removable_paths_.push_back(path);
137 } // namespace storage_monitor