Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: chromeos/dbus/cros_disks_client.cc

Issue 281063002: Add EnumerateMountEntries method in CrosDisksClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/cros_disks_client.h" 5 #include "chromeos/dbus/cros_disks_client.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 cros_disks::kEnumerateAutoMountableDevices); 141 cros_disks::kEnumerateAutoMountableDevices);
142 proxy_->CallMethod( 142 proxy_->CallMethod(
143 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 143 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
144 base::Bind(&CrosDisksClientImpl::OnEnumerateAutoMountableDevices, 144 base::Bind(&CrosDisksClientImpl::OnEnumerateAutoMountableDevices,
145 weak_ptr_factory_.GetWeakPtr(), 145 weak_ptr_factory_.GetWeakPtr(),
146 callback, 146 callback,
147 error_callback)); 147 error_callback));
148 } 148 }
149 149
150 // CrosDisksClient override. 150 // CrosDisksClient override.
151 virtual void EnumerateMountEntries(
152 const EnumerateMountEntriesCallback& callback,
153 const base::Closure& error_callback) OVERRIDE {
154 dbus::MethodCall method_call(cros_disks::kCrosDisksInterface,
155 cros_disks::kEnumerateMountEntries);
156 proxy_->CallMethod(
157 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
158 base::Bind(&CrosDisksClientImpl::OnEnumerateMountEntries,
159 weak_ptr_factory_.GetWeakPtr(),
160 callback,
161 error_callback));
162 }
163
164 // CrosDisksClient override.
151 virtual void Format(const std::string& device_path, 165 virtual void Format(const std::string& device_path,
152 const std::string& filesystem, 166 const std::string& filesystem,
153 const base::Closure& callback, 167 const base::Closure& callback,
154 const base::Closure& error_callback) OVERRIDE { 168 const base::Closure& error_callback) OVERRIDE {
155 dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, 169 dbus::MethodCall method_call(cros_disks::kCrosDisksInterface,
156 cros_disks::kFormat); 170 cros_disks::kFormat);
157 dbus::MessageWriter writer(&method_call); 171 dbus::MessageWriter writer(&method_call);
158 writer.AppendString(device_path); 172 writer.AppendString(device_path);
159 writer.AppendString(filesystem); 173 writer.AppendString(filesystem);
160 // No format option is currently specified, but we can later use this 174 // No format option is currently specified, but we can later use this
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 void OnMount(const base::Closure& callback, 271 void OnMount(const base::Closure& callback,
258 const base::Closure& error_callback, 272 const base::Closure& error_callback,
259 dbus::Response* response) { 273 dbus::Response* response) {
260 if (!response) { 274 if (!response) {
261 error_callback.Run(); 275 error_callback.Run();
262 return; 276 return;
263 } 277 }
264 callback.Run(); 278 callback.Run();
265 } 279 }
266 280
267 // Handles the result of Unount and calls |callback| or |error_callback|. 281 // Handles the result of Unmount and calls |callback| or |error_callback|.
268 void OnUnmount(const base::Closure& callback, 282 void OnUnmount(const base::Closure& callback,
269 const base::Closure& error_callback, 283 const base::Closure& error_callback,
270 dbus::Response* response) { 284 dbus::Response* response) {
271 if (!response) { 285 if (!response) {
272 error_callback.Run(); 286 error_callback.Run();
273 return; 287 return;
274 } 288 }
275 289
276 // Temporarly allow Unmount method to report failure both by setting dbus 290 // Temporarly allow Unmount method to report failure both by setting dbus
277 // error (in which case response is not set) and by returning mount error 291 // error (in which case response is not set) and by returning mount error
(...skipping 27 matching lines...) Expand all
305 dbus::MessageReader reader(response); 319 dbus::MessageReader reader(response);
306 std::vector<std::string> device_paths; 320 std::vector<std::string> device_paths;
307 if (!reader.PopArrayOfStrings(&device_paths)) { 321 if (!reader.PopArrayOfStrings(&device_paths)) {
308 LOG(ERROR) << "Invalid response: " << response->ToString(); 322 LOG(ERROR) << "Invalid response: " << response->ToString();
309 error_callback.Run(); 323 error_callback.Run();
310 return; 324 return;
311 } 325 }
312 callback.Run(device_paths); 326 callback.Run(device_paths);
313 } 327 }
314 328
329 // Handles the result of EnumerateMountEntries and calls |callback| or
330 // |error_callback|.
331 void OnEnumerateMountEntries(
332 const EnumerateMountEntriesCallback& callback,
333 const base::Closure& error_callback,
334 dbus::Response* response) {
335 if (!response) {
336 error_callback.Run();
337 return;
338 }
339
340 dbus::MessageReader reader(response);
341 dbus::MessageReader array_reader(NULL);
342 if (!reader.PopArray(&array_reader)) {
343 LOG(ERROR) << "Invalid response: " << response->ToString();
344 error_callback.Run();
345 return;
346 }
347
348 std::vector<MountEntry> entries;
349 while (array_reader.HasMoreData()) {
350 MountEntry entry;
351 dbus::MessageReader sub_reader(NULL);
352 if (!array_reader.PopStruct(&sub_reader) ||
353 !MountEntry::ReadFromDbus(&sub_reader, &entry)) {
354 LOG(ERROR) << "Invalid response: " << response->ToString();
355 error_callback.Run();
356 return;
357 }
358 entries.push_back(entry);
359 }
360 callback.Run(entries);
361 }
362
315 // Handles the result of Format and calls |callback| or |error_callback|. 363 // Handles the result of Format and calls |callback| or |error_callback|.
316 void OnFormat(const base::Closure& callback, 364 void OnFormat(const base::Closure& callback,
317 const base::Closure& error_callback, 365 const base::Closure& error_callback,
318 dbus::Response* response) { 366 dbus::Response* response) {
319 if (!response) { 367 if (!response) {
320 error_callback.Run(); 368 error_callback.Run();
321 return; 369 return;
322 } 370 }
323 callback.Run(); 371 callback.Run();
324 } 372 }
(...skipping 21 matching lines...) Expand all
346 if (!reader.PopString(&device)) { 394 if (!reader.PopString(&device)) {
347 LOG(ERROR) << "Invalid signal: " << signal->ToString(); 395 LOG(ERROR) << "Invalid signal: " << signal->ToString();
348 return; 396 return;
349 } 397 }
350 handler.Run(event_type, device); 398 handler.Run(event_type, device);
351 } 399 }
352 400
353 // Handles MountCompleted signal and calls |handler|. 401 // Handles MountCompleted signal and calls |handler|.
354 void OnMountCompleted(MountCompletedHandler handler, dbus::Signal* signal) { 402 void OnMountCompleted(MountCompletedHandler handler, dbus::Signal* signal) {
355 dbus::MessageReader reader(signal); 403 dbus::MessageReader reader(signal);
356 uint32 error_code = 0; 404 MountEntry entry;
357 std::string source_path; 405 if (!MountEntry::ReadFromDbus(&reader, &entry)) {
358 uint32 mount_type = 0;
359 std::string mount_path;
360 if (!reader.PopUint32(&error_code) ||
361 !reader.PopString(&source_path) ||
362 !reader.PopUint32(&mount_type) ||
363 !reader.PopString(&mount_path)) {
364 LOG(ERROR) << "Invalid signal: " << signal->ToString(); 406 LOG(ERROR) << "Invalid signal: " << signal->ToString();
365 return; 407 return;
366 } 408 }
367 handler.Run(static_cast<MountError>(error_code), source_path, 409 handler.Run(entry);
368 static_cast<MountType>(mount_type), mount_path);
369 } 410 }
370 411
371 // Handles FormatCompleted signal and calls |handler|. 412 // Handles FormatCompleted signal and calls |handler|.
372 void OnFormatCompleted(FormatCompletedHandler handler, dbus::Signal* signal) { 413 void OnFormatCompleted(FormatCompletedHandler handler, dbus::Signal* signal) {
373 dbus::MessageReader reader(signal); 414 dbus::MessageReader reader(signal);
374 uint32 error_code = 0; 415 uint32 error_code = 0;
375 std::string device_path; 416 std::string device_path;
376 if (!reader.PopUint32(&error_code) || !reader.PopString(&device_path)) { 417 if (!reader.PopUint32(&error_code) || !reader.PopString(&device_path)) {
377 LOG(ERROR) << "Invalid signal: " << signal->ToString(); 418 LOG(ERROR) << "Invalid signal: " << signal->ToString();
378 return; 419 return;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } 502 }
462 503
463 virtual void EnumerateAutoMountableDevices( 504 virtual void EnumerateAutoMountableDevices(
464 const EnumerateAutoMountableDevicesCallback& callback, 505 const EnumerateAutoMountableDevicesCallback& callback,
465 const base::Closure& error_callback) OVERRIDE { 506 const base::Closure& error_callback) OVERRIDE {
466 std::vector<std::string> device_paths; 507 std::vector<std::string> device_paths;
467 base::MessageLoopProxy::current()->PostTask( 508 base::MessageLoopProxy::current()->PostTask(
468 FROM_HERE, base::Bind(callback, device_paths)); 509 FROM_HERE, base::Bind(callback, device_paths));
469 } 510 }
470 511
512 virtual void EnumerateMountEntries(
513 const EnumerateMountEntriesCallback& callback,
514 const base::Closure& error_callback) OVERRIDE {
515 std::vector<MountEntry> entries;
516 base::MessageLoopProxy::current()->PostTask(
517 FROM_HERE, base::Bind(callback, entries));
518 }
519
471 virtual void Format(const std::string& device_path, 520 virtual void Format(const std::string& device_path,
472 const std::string& filesystem, 521 const std::string& filesystem,
473 const base::Closure& callback, 522 const base::Closure& callback,
474 const base::Closure& error_callback) OVERRIDE { 523 const base::Closure& error_callback) OVERRIDE {
475 base::MessageLoopProxy::current()->PostTask(FROM_HERE, error_callback); 524 base::MessageLoopProxy::current()->PostTask(FROM_HERE, error_callback);
476 } 525 }
477 526
478 virtual void GetDeviceProperties( 527 virtual void GetDeviceProperties(
479 const std::string& device_path, 528 const std::string& device_path,
480 const GetDevicePropertiesCallback& callback, 529 const GetDevicePropertiesCallback& callback,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 void FinishMount(MountError error, 597 void FinishMount(MountError error,
549 const std::string& source_path, 598 const std::string& source_path,
550 MountType type, 599 MountType type,
551 const std::string& mounted_path, 600 const std::string& mounted_path,
552 const base::Closure& callback) { 601 const base::Closure& callback) {
553 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback); 602 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback);
554 if (!mount_completed_handler_.is_null()) { 603 if (!mount_completed_handler_.is_null()) {
555 base::MessageLoopProxy::current()->PostTask( 604 base::MessageLoopProxy::current()->PostTask(
556 FROM_HERE, 605 FROM_HERE,
557 base::Bind(mount_completed_handler_, 606 base::Bind(mount_completed_handler_,
558 error, source_path, type, mounted_path)); 607 MountEntry(error, source_path, type, mounted_path)));
559 } 608 }
560 } 609 }
561 610
562 // Mounted path to source path map. 611 // Mounted path to source path map.
563 std::map<std::string, std::string> mounted_to_source_path_map_; 612 std::map<std::string, std::string> mounted_to_source_path_map_;
564 613
565 MountEventHandler mount_event_handler_; 614 MountEventHandler mount_event_handler_;
566 MountCompletedHandler mount_completed_handler_; 615 MountCompletedHandler mount_completed_handler_;
567 FormatCompletedHandler format_completed_handler_; 616 FormatCompletedHandler format_completed_handler_;
568 617
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 &media_type_double)) 781 &media_type_double))
733 device_type_ = DeviceMediaTypeToDeviceType(media_type_double); 782 device_type_ = DeviceMediaTypeToDeviceType(media_type_double);
734 783
735 base::ListValue* mount_paths = NULL; 784 base::ListValue* mount_paths = NULL;
736 if (properties->GetListWithoutPathExpansion(cros_disks::kDeviceMountPaths, 785 if (properties->GetListWithoutPathExpansion(cros_disks::kDeviceMountPaths,
737 &mount_paths)) 786 &mount_paths))
738 mount_paths->GetString(0, &mount_path_); 787 mount_paths->GetString(0, &mount_path_);
739 } 788 }
740 789
741 //////////////////////////////////////////////////////////////////////////////// 790 ////////////////////////////////////////////////////////////////////////////////
791 // MountEntry
792
793 MountEntry::MountEntry()
794 : error_code_(MOUNT_ERROR_UNKNOWN), mount_type_(MOUNT_TYPE_INVALID) {
795 }
796
797 MountEntry::MountEntry(MountError error_code,
798 const std::string& source_path,
799 MountType mount_type,
800 const std::string& mount_path)
801 : error_code_(error_code),
802 source_path_(source_path),
803 mount_type_(mount_type),
804 mount_path_(mount_path) {
805 }
806
807 MountEntry::~MountEntry() {
808 }
809
810 // static
811 bool MountEntry::ReadFromDbus(dbus::MessageReader* reader, MountEntry* entry) {
stevenjb 2014/05/14 17:45:11 If this is only used in this file we can just make
kinaba 2014/05/15 02:14:59 Done.
812 uint32 error_code = 0;
813 std::string source_path;
814 uint32 mount_type = 0;
815 std::string mount_path;
816 if (!reader->PopUint32(&error_code) ||
817 !reader->PopString(&source_path) ||
818 !reader->PopUint32(&mount_type) ||
819 !reader->PopString(&mount_path)) {
820 return false;
821 }
822 *entry = MountEntry(static_cast<MountError>(error_code), source_path,
823 static_cast<MountType>(mount_type), mount_path);
824 return true;
825 }
826
827 ////////////////////////////////////////////////////////////////////////////////
742 // CrosDisksClient 828 // CrosDisksClient
743 829
744 CrosDisksClient::CrosDisksClient() {} 830 CrosDisksClient::CrosDisksClient() {}
745 831
746 CrosDisksClient::~CrosDisksClient() {} 832 CrosDisksClient::~CrosDisksClient() {}
747 833
748 // static 834 // static
749 CrosDisksClient* CrosDisksClient::Create(DBusClientImplementationType type) { 835 CrosDisksClient* CrosDisksClient::Create(DBusClientImplementationType type) {
750 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 836 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
751 return new CrosDisksClientImpl(); 837 return new CrosDisksClientImpl();
752 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 838 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
753 return new CrosDisksClientStubImpl(); 839 return new CrosDisksClientStubImpl();
754 } 840 }
755 841
756 // static 842 // static
757 base::FilePath CrosDisksClient::GetArchiveMountPoint() { 843 base::FilePath CrosDisksClient::GetArchiveMountPoint() {
758 return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ? 844 return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ?
759 FILE_PATH_LITERAL("/media/archive") : 845 FILE_PATH_LITERAL("/media/archive") :
760 FILE_PATH_LITERAL("/tmp/chromeos/media/archive")); 846 FILE_PATH_LITERAL("/tmp/chromeos/media/archive"));
761 } 847 }
762 848
763 // static 849 // static
764 base::FilePath CrosDisksClient::GetRemovableDiskMountPoint() { 850 base::FilePath CrosDisksClient::GetRemovableDiskMountPoint() {
765 return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ? 851 return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ?
766 FILE_PATH_LITERAL("/media/removable") : 852 FILE_PATH_LITERAL("/media/removable") :
767 FILE_PATH_LITERAL("/tmp/chromeos/media/removable")); 853 FILE_PATH_LITERAL("/tmp/chromeos/media/removable"));
768 } 854 }
769 855
770 } // namespace chromeos 856 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698