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.
5 #include "chromeos/dbus/fake_cros_disks_client.h"
8 #include "base/message_loop/message_loop.h"
12 FakeCrosDisksClient::FakeCrosDisksClient()
13 : unmount_call_count_(0),
14 unmount_success_(true),
15 format_device_call_count_(0),
16 format_device_success_(true) {
19 FakeCrosDisksClient::~FakeCrosDisksClient() {
22 void FakeCrosDisksClient::Init(dbus::Bus
* bus
) {
25 void FakeCrosDisksClient::Mount(const std::string
& source_path
,
26 const std::string
& source_format
,
27 const std::string
& mount_label
,
28 const base::Closure
& callback
,
29 const base::Closure
& error_callback
) {
32 void FakeCrosDisksClient::Unmount(const std::string
& device_path
,
33 UnmountOptions options
,
34 const base::Closure
& callback
,
35 const base::Closure
& error_callback
) {
36 DCHECK(!callback
.is_null());
37 DCHECK(!error_callback
.is_null());
39 unmount_call_count_
++;
40 last_unmount_device_path_
= device_path
;
41 last_unmount_options_
= options
;
42 base::MessageLoopProxy::current()->PostTask(
43 FROM_HERE
, unmount_success_
? callback
: error_callback
);
44 if (!unmount_listener_
.is_null())
45 unmount_listener_
.Run();
48 void FakeCrosDisksClient::EnumerateAutoMountableDevices(
49 const EnumerateAutoMountableDevicesCallback
& callback
,
50 const base::Closure
& error_callback
) {
53 void FakeCrosDisksClient::FormatDevice(const std::string
& device_path
,
54 const std::string
& filesystem
,
55 const FormatDeviceCallback
& callback
,
56 const base::Closure
& error_callback
) {
57 DCHECK(!callback
.is_null());
58 DCHECK(!error_callback
.is_null());
60 format_device_call_count_
++;
61 last_format_device_device_path_
= device_path
;
62 last_format_device_filesystem_
= filesystem
;
63 if (format_device_success_
) {
64 base::MessageLoopProxy::current()->PostTask(FROM_HERE
,
65 base::Bind(callback
, true));
67 base::MessageLoopProxy::current()->PostTask(FROM_HERE
, error_callback
);
71 void FakeCrosDisksClient::GetDeviceProperties(
72 const std::string
& device_path
,
73 const GetDevicePropertiesCallback
& callback
,
74 const base::Closure
& error_callback
) {
77 void FakeCrosDisksClient::SetUpConnections(
78 const MountEventHandler
& mount_event_handler
,
79 const MountCompletedHandler
& mount_completed_handler
) {
80 mount_event_handler_
= mount_event_handler
;
81 mount_completed_handler_
= mount_completed_handler
;
84 bool FakeCrosDisksClient::SendMountEvent(MountEventType event
,
85 const std::string
& path
) {
86 if (mount_event_handler_
.is_null())
88 mount_event_handler_
.Run(event
, path
);
92 bool FakeCrosDisksClient::SendMountCompletedEvent(
93 MountError error_code
,
94 const std::string
& source_path
,
96 const std::string
& mount_path
) {
97 if (mount_completed_handler_
.is_null())
99 mount_completed_handler_
.Run(error_code
, source_path
, mount_type
, mount_path
);
103 } // namespace chromeos