QUIC - Record reject reasons for CHLO message.
[chromium-blink-merge.git] / chromeos / dbus / fake_cros_disks_client.cc
blobe298013665872cbf7a89406dbb3c98313125e8e7
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"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
11 namespace chromeos {
13 FakeCrosDisksClient::FakeCrosDisksClient()
14 : unmount_call_count_(0),
15 unmount_success_(true),
16 format_call_count_(0),
17 format_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::EnumerateMountEntries(
55 const EnumerateMountEntriesCallback& callback,
56 const base::Closure& error_callback) {
59 void FakeCrosDisksClient::Format(const std::string& device_path,
60 const std::string& filesystem,
61 const base::Closure& callback,
62 const base::Closure& error_callback) {
63 DCHECK(!callback.is_null());
64 DCHECK(!error_callback.is_null());
66 format_call_count_++;
67 last_format_device_path_ = device_path;
68 last_format_filesystem_ = filesystem;
69 if (format_success_) {
70 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback);
71 } else {
72 base::MessageLoopProxy::current()->PostTask(FROM_HERE, error_callback);
76 void FakeCrosDisksClient::GetDeviceProperties(
77 const std::string& device_path,
78 const GetDevicePropertiesCallback& callback,
79 const base::Closure& error_callback) {
82 void FakeCrosDisksClient::SetMountEventHandler(
83 const MountEventHandler& mount_event_handler) {
84 mount_event_handler_ = mount_event_handler;
87 void FakeCrosDisksClient::SetMountCompletedHandler(
88 const MountCompletedHandler& mount_completed_handler) {
89 mount_completed_handler_ = mount_completed_handler;
92 void FakeCrosDisksClient::SetFormatCompletedHandler(
93 const FormatCompletedHandler& format_completed_handler) {
94 format_completed_handler_ = format_completed_handler;
97 bool FakeCrosDisksClient::SendMountEvent(MountEventType event,
98 const std::string& path) {
99 if (mount_event_handler_.is_null())
100 return false;
101 mount_event_handler_.Run(event, path);
102 return true;
105 bool FakeCrosDisksClient::SendMountCompletedEvent(
106 MountError error_code,
107 const std::string& source_path,
108 MountType mount_type,
109 const std::string& mount_path) {
110 if (mount_completed_handler_.is_null())
111 return false;
112 mount_completed_handler_.Run(
113 MountEntry(error_code, source_path, mount_type, mount_path));
114 return true;
117 bool FakeCrosDisksClient::SendFormatCompletedEvent(
118 FormatError error_code,
119 const std::string& device_path) {
120 if (format_completed_handler_.is_null())
121 return false;
122 format_completed_handler_.Run(error_code, device_path);
123 return true;
126 } // namespace chromeos