• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/logging.h"
9 #include "base/message_loop/message_loop.h"
10 
11 namespace chromeos {
12 
FakeCrosDisksClient()13 FakeCrosDisksClient::FakeCrosDisksClient()
14     : unmount_call_count_(0),
15       unmount_success_(true),
16       format_call_count_(0),
17       format_success_(true) {
18 }
19 
~FakeCrosDisksClient()20 FakeCrosDisksClient::~FakeCrosDisksClient() {
21 }
22 
Init(dbus::Bus * bus)23 void FakeCrosDisksClient::Init(dbus::Bus* bus) {
24 }
25 
Mount(const std::string & source_path,const std::string & source_format,const std::string & mount_label,const base::Closure & callback,const base::Closure & error_callback)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) {
31 }
32 
Unmount(const std::string & device_path,UnmountOptions options,const base::Closure & callback,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());
39 
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();
47 }
48 
EnumerateAutoMountableDevices(const EnumerateAutoMountableDevicesCallback & callback,const base::Closure & error_callback)49 void FakeCrosDisksClient::EnumerateAutoMountableDevices(
50     const EnumerateAutoMountableDevicesCallback& callback,
51     const base::Closure& error_callback) {
52 }
53 
EnumerateMountEntries(const EnumerateMountEntriesCallback & callback,const base::Closure & error_callback)54 void FakeCrosDisksClient::EnumerateMountEntries(
55     const EnumerateMountEntriesCallback& callback,
56     const base::Closure& error_callback) {
57 }
58 
Format(const std::string & device_path,const std::string & filesystem,const base::Closure & callback,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());
65 
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);
73   }
74 }
75 
GetDeviceProperties(const std::string & device_path,const GetDevicePropertiesCallback & callback,const base::Closure & error_callback)76 void FakeCrosDisksClient::GetDeviceProperties(
77     const std::string& device_path,
78     const GetDevicePropertiesCallback& callback,
79     const base::Closure& error_callback) {
80 }
81 
SetMountEventHandler(const MountEventHandler & mount_event_handler)82 void FakeCrosDisksClient::SetMountEventHandler(
83     const MountEventHandler& mount_event_handler) {
84   mount_event_handler_ = mount_event_handler;
85 }
86 
SetMountCompletedHandler(const MountCompletedHandler & mount_completed_handler)87 void FakeCrosDisksClient::SetMountCompletedHandler(
88     const MountCompletedHandler& mount_completed_handler) {
89   mount_completed_handler_ = mount_completed_handler;
90 }
91 
SetFormatCompletedHandler(const FormatCompletedHandler & format_completed_handler)92 void FakeCrosDisksClient::SetFormatCompletedHandler(
93     const FormatCompletedHandler& format_completed_handler) {
94   format_completed_handler_ = format_completed_handler;
95 }
96 
SendMountEvent(MountEventType event,const std::string & path)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;
103 }
104 
SendMountCompletedEvent(MountError error_code,const std::string & source_path,MountType mount_type,const std::string & mount_path)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;
115 }
116 
SendFormatCompletedEvent(FormatError error_code,const std::string & device_path)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;
124 }
125 
126 }  // namespace chromeos
127