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/logging.h"
9 #include "base/message_loop/message_loop.h"
13 FakeCrosDisksClient::FakeCrosDisksClient()
14 : unmount_call_count_(0),
15 unmount_success_(true),
16 format_device_call_count_(0),
17 format_device_success_(true) {
20 FakeCrosDisksClient::~FakeCrosDisksClient() {
23 void FakeCrosDisksClient::Init(dbus::Bus
* bus
) {
26 void FakeCrosDisksClient::Mount(const std::string
& source_path
,
27 const std::string
& source_format
,
28 const std::string
& mount_label
,
29 const base::Closure
& callback
,
30 const base::Closure
& error_callback
) {
33 void FakeCrosDisksClient::Unmount(const std::string
& device_path
,
34 UnmountOptions options
,
35 const base::Closure
& callback
,
36 const base::Closure
& error_callback
) {
37 DCHECK(!callback
.is_null());
38 DCHECK(!error_callback
.is_null());
40 unmount_call_count_
++;
41 last_unmount_device_path_
= device_path
;
42 last_unmount_options_
= options
;
43 base::MessageLoopProxy::current()->PostTask(
44 FROM_HERE
, unmount_success_
? callback
: error_callback
);
45 if (!unmount_listener_
.is_null())
46 unmount_listener_
.Run();
49 void FakeCrosDisksClient::EnumerateAutoMountableDevices(
50 const EnumerateAutoMountableDevicesCallback
& callback
,
51 const base::Closure
& error_callback
) {
54 void FakeCrosDisksClient::FormatDevice(const std::string
& device_path
,
55 const std::string
& filesystem
,
56 const FormatDeviceCallback
& callback
,
57 const base::Closure
& error_callback
) {
58 DCHECK(!callback
.is_null());
59 DCHECK(!error_callback
.is_null());
61 format_device_call_count_
++;
62 last_format_device_device_path_
= device_path
;
63 last_format_device_filesystem_
= filesystem
;
64 if (format_device_success_
) {
65 base::MessageLoopProxy::current()->PostTask(FROM_HERE
,
66 base::Bind(callback
, true));
68 base::MessageLoopProxy::current()->PostTask(FROM_HERE
, error_callback
);
72 void FakeCrosDisksClient::GetDeviceProperties(
73 const std::string
& device_path
,
74 const GetDevicePropertiesCallback
& callback
,
75 const base::Closure
& error_callback
) {
78 void FakeCrosDisksClient::SetUpConnections(
79 const MountEventHandler
& mount_event_handler
,
80 const MountCompletedHandler
& mount_completed_handler
) {
81 mount_event_handler_
= mount_event_handler
;
82 mount_completed_handler_
= mount_completed_handler
;
85 bool FakeCrosDisksClient::SendMountEvent(MountEventType event
,
86 const std::string
& path
) {
87 if (mount_event_handler_
.is_null())
89 mount_event_handler_
.Run(event
, path
);
93 bool FakeCrosDisksClient::SendMountCompletedEvent(
94 MountError error_code
,
95 const std::string
& source_path
,
97 const std::string
& mount_path
) {
98 if (mount_completed_handler_
.is_null())
100 mount_completed_handler_
.Run(error_code
, source_path
, mount_type
, mount_path
);
104 } // namespace chromeos