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 3 // found in the LICENSE file. 4 5 #include "chromeos/dbus/fake_cros_disks_client.h" 6 7 #include "base/bind.h" 8 #include "base/message_loop/message_loop.h" 9 10 namespace chromeos { 11 12 FakeCrosDisksClient::FakeCrosDisksClient() 13 : unmount_call_count_(0), 14 unmount_success_(true), 15 format_device_call_count_(0), 16 format_device_success_(true) { 17 } 18 19 FakeCrosDisksClient::~FakeCrosDisksClient() {} 20 21 void FakeCrosDisksClient::Mount(const std::string& source_path, 22 const std::string& source_format, 23 const std::string& mount_label, 24 const base::Closure& callback, 25 const base::Closure& error_callback) { 26 } 27 28 void FakeCrosDisksClient::Unmount(const std::string& device_path, 29 UnmountOptions options, 30 const base::Closure& callback, 31 const base::Closure& error_callback) { 32 DCHECK(!callback.is_null()); 33 DCHECK(!error_callback.is_null()); 34 35 unmount_call_count_++; 36 last_unmount_device_path_ = device_path; 37 last_unmount_options_ = options; 38 base::MessageLoopProxy::current()->PostTask( 39 FROM_HERE, unmount_success_ ? callback : error_callback); 40 if(!unmount_listener_.is_null()) 41 unmount_listener_.Run(); 42 } 43 44 void FakeCrosDisksClient::EnumerateAutoMountableDevices( 45 const EnumerateAutoMountableDevicesCallback& callback, 46 const base::Closure& error_callback) { 47 } 48 49 void FakeCrosDisksClient::FormatDevice(const std::string& device_path, 50 const std::string& filesystem, 51 const FormatDeviceCallback& callback, 52 const base::Closure& error_callback) { 53 DCHECK(!callback.is_null()); 54 DCHECK(!error_callback.is_null()); 55 56 format_device_call_count_++; 57 last_format_device_device_path_ = device_path; 58 last_format_device_filesystem_ = filesystem; 59 if (format_device_success_) { 60 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 61 base::Bind(callback, true)); 62 } else { 63 base::MessageLoopProxy::current()->PostTask(FROM_HERE, error_callback); 64 } 65 } 66 67 void FakeCrosDisksClient::GetDeviceProperties( 68 const std::string& device_path, 69 const GetDevicePropertiesCallback& callback, 70 const base::Closure& error_callback) { 71 } 72 73 void FakeCrosDisksClient::SetUpConnections( 74 const MountEventHandler& mount_event_handler, 75 const MountCompletedHandler& mount_completed_handler) { 76 mount_event_handler_ = mount_event_handler; 77 mount_completed_handler_ = mount_completed_handler; 78 } 79 80 bool FakeCrosDisksClient::SendMountEvent(MountEventType event, 81 const std::string& path) { 82 if (mount_event_handler_.is_null()) 83 return false; 84 mount_event_handler_.Run(event, path); 85 return true; 86 } 87 88 bool FakeCrosDisksClient::SendMountCompletedEvent( 89 MountError error_code, 90 const std::string& source_path, 91 MountType mount_type, 92 const std::string& mount_path) { 93 if (mount_completed_handler_.is_null()) 94 return false; 95 mount_completed_handler_.Run(error_code, source_path, mount_type, mount_path); 96 return true; 97 } 98 99 } // namespace chromeos 100