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

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

Issue 1540803002: Switch to standard integer types in chromeos/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more includes Created 5 years 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
« no previous file with comments | « chromeos/dbus/cros_disks_client.h ('k') | chromeos/dbus/cros_disks_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h>
8 #include <stdint.h>
9
7 #include <map> 10 #include <map>
8 11
9 #include "base/bind.h" 12 #include "base/bind.h"
10 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
12 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/macros.h"
13 #include "base/stl_util.h" 17 #include "base/stl_util.h"
14 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
15 #include "base/sys_info.h" 19 #include "base/sys_info.h"
16 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
17 #include "base/threading/worker_pool.h" 21 #include "base/threading/worker_pool.h"
18 #include "base/values.h" 22 #include "base/values.h"
19 #include "chromeos/dbus/fake_cros_disks_client.h" 23 #include "chromeos/dbus/fake_cros_disks_client.h"
20 #include "dbus/bus.h" 24 #include "dbus/bus.h"
21 #include "dbus/message.h" 25 #include "dbus/message.h"
22 #include "dbus/object_path.h" 26 #include "dbus/object_path.h"
(...skipping 14 matching lines...) Expand all
37 41
38 const char* kDefaultUnmountOptions[] = { 42 const char* kDefaultUnmountOptions[] = {
39 "force", 43 "force",
40 }; 44 };
41 45
42 const char kLazyUnmountOption[] = "lazy"; 46 const char kLazyUnmountOption[] = "lazy";
43 47
44 const char kMountLabelOption[] = "mountlabel"; 48 const char kMountLabelOption[] = "mountlabel";
45 49
46 // Checks if retrieved media type is in boundaries of DeviceMediaType. 50 // Checks if retrieved media type is in boundaries of DeviceMediaType.
47 bool IsValidMediaType(uint32 type) { 51 bool IsValidMediaType(uint32_t type) {
48 return type < static_cast<uint32>(cros_disks::DEVICE_MEDIA_NUM_VALUES); 52 return type < static_cast<uint32_t>(cros_disks::DEVICE_MEDIA_NUM_VALUES);
49 } 53 }
50 54
51 // Translates enum used in cros-disks to enum used in Chrome. 55 // Translates enum used in cros-disks to enum used in Chrome.
52 // Note that we could just do static_cast, but this is less sensitive to 56 // Note that we could just do static_cast, but this is less sensitive to
53 // changes in cros-disks. 57 // changes in cros-disks.
54 DeviceType DeviceMediaTypeToDeviceType(uint32 media_type_uint32) { 58 DeviceType DeviceMediaTypeToDeviceType(uint32_t media_type_uint32) {
55 if (!IsValidMediaType(media_type_uint32)) 59 if (!IsValidMediaType(media_type_uint32))
56 return DEVICE_TYPE_UNKNOWN; 60 return DEVICE_TYPE_UNKNOWN;
57 61
58 cros_disks::DeviceMediaType media_type = 62 cros_disks::DeviceMediaType media_type =
59 cros_disks::DeviceMediaType(media_type_uint32); 63 cros_disks::DeviceMediaType(media_type_uint32);
60 64
61 switch (media_type) { 65 switch (media_type) {
62 case(cros_disks::DEVICE_MEDIA_UNKNOWN): 66 case(cros_disks::DEVICE_MEDIA_UNKNOWN):
63 return DEVICE_TYPE_UNKNOWN; 67 return DEVICE_TYPE_UNKNOWN;
64 case(cros_disks::DEVICE_MEDIA_USB): 68 case(cros_disks::DEVICE_MEDIA_USB):
65 return DEVICE_TYPE_USB; 69 return DEVICE_TYPE_USB;
66 case(cros_disks::DEVICE_MEDIA_SD): 70 case(cros_disks::DEVICE_MEDIA_SD):
67 return DEVICE_TYPE_SD; 71 return DEVICE_TYPE_SD;
68 case(cros_disks::DEVICE_MEDIA_OPTICAL_DISC): 72 case(cros_disks::DEVICE_MEDIA_OPTICAL_DISC):
69 return DEVICE_TYPE_OPTICAL_DISC; 73 return DEVICE_TYPE_OPTICAL_DISC;
70 case(cros_disks::DEVICE_MEDIA_MOBILE): 74 case(cros_disks::DEVICE_MEDIA_MOBILE):
71 return DEVICE_TYPE_MOBILE; 75 return DEVICE_TYPE_MOBILE;
72 case(cros_disks::DEVICE_MEDIA_DVD): 76 case(cros_disks::DEVICE_MEDIA_DVD):
73 return DEVICE_TYPE_DVD; 77 return DEVICE_TYPE_DVD;
74 default: 78 default:
75 return DEVICE_TYPE_UNKNOWN; 79 return DEVICE_TYPE_UNKNOWN;
76 } 80 }
77 } 81 }
78 82
79 bool ReadMountEntryFromDbus(dbus::MessageReader* reader, MountEntry* entry) { 83 bool ReadMountEntryFromDbus(dbus::MessageReader* reader, MountEntry* entry) {
80 uint32 error_code = 0; 84 uint32_t error_code = 0;
81 std::string source_path; 85 std::string source_path;
82 uint32 mount_type = 0; 86 uint32_t mount_type = 0;
83 std::string mount_path; 87 std::string mount_path;
84 if (!reader->PopUint32(&error_code) || 88 if (!reader->PopUint32(&error_code) ||
85 !reader->PopString(&source_path) || 89 !reader->PopString(&source_path) ||
86 !reader->PopUint32(&mount_type) || 90 !reader->PopUint32(&mount_type) ||
87 !reader->PopString(&mount_path)) { 91 !reader->PopString(&mount_path)) {
88 return false; 92 return false;
89 } 93 }
90 *entry = MountEntry(static_cast<MountError>(error_code), source_path, 94 *entry = MountEntry(static_cast<MountError>(error_code), source_path,
91 static_cast<MountType>(mount_type), mount_path); 95 static_cast<MountType>(mount_type), mount_path);
92 return true; 96 return true;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 307
304 // Temporarly allow Unmount method to report failure both by setting dbus 308 // Temporarly allow Unmount method to report failure both by setting dbus
305 // error (in which case response is not set) and by returning mount error 309 // error (in which case response is not set) and by returning mount error
306 // different from MOUNT_ERROR_NONE. This is done so we can change Unmount 310 // different from MOUNT_ERROR_NONE. This is done so we can change Unmount
307 // method to return mount error (http://crbug.com/288974) without breaking 311 // method to return mount error (http://crbug.com/288974) without breaking
308 // Chrome. 312 // Chrome.
309 // TODO(tbarzic): When Unmount implementation is changed on cros disks side, 313 // TODO(tbarzic): When Unmount implementation is changed on cros disks side,
310 // make this fail if reader is not able to read the error code value from 314 // make this fail if reader is not able to read the error code value from
311 // the response. 315 // the response.
312 dbus::MessageReader reader(response); 316 dbus::MessageReader reader(response);
313 uint32 error_code = 0; 317 uint32_t error_code = 0;
314 if (reader.PopUint32(&error_code) && 318 if (reader.PopUint32(&error_code) &&
315 static_cast<MountError>(error_code) != MOUNT_ERROR_NONE) { 319 static_cast<MountError>(error_code) != MOUNT_ERROR_NONE) {
316 error_callback.Run(); 320 error_callback.Run();
317 return; 321 return;
318 } 322 }
319 323
320 callback.Run(); 324 callback.Run();
321 } 325 }
322 326
323 // Handles the result of EnumerateAutoMountableDevices and calls |callback| or 327 // Handles the result of EnumerateAutoMountableDevices and calls |callback| or
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 if (!ReadMountEntryFromDbus(&reader, &entry)) { 423 if (!ReadMountEntryFromDbus(&reader, &entry)) {
420 LOG(ERROR) << "Invalid signal: " << signal->ToString(); 424 LOG(ERROR) << "Invalid signal: " << signal->ToString();
421 return; 425 return;
422 } 426 }
423 handler.Run(entry); 427 handler.Run(entry);
424 } 428 }
425 429
426 // Handles FormatCompleted signal and calls |handler|. 430 // Handles FormatCompleted signal and calls |handler|.
427 void OnFormatCompleted(FormatCompletedHandler handler, dbus::Signal* signal) { 431 void OnFormatCompleted(FormatCompletedHandler handler, dbus::Signal* signal) {
428 dbus::MessageReader reader(signal); 432 dbus::MessageReader reader(signal);
429 uint32 error_code = 0; 433 uint32_t error_code = 0;
430 std::string device_path; 434 std::string device_path;
431 if (!reader.PopUint32(&error_code) || !reader.PopString(&device_path)) { 435 if (!reader.PopUint32(&error_code) || !reader.PopString(&device_path)) {
432 LOG(ERROR) << "Invalid signal: " << signal->ToString(); 436 LOG(ERROR) << "Invalid signal: " << signal->ToString();
433 return; 437 return;
434 } 438 }
435 handler.Run(static_cast<FormatError>(error_code), device_path); 439 handler.Run(static_cast<FormatError>(error_code), device_path);
436 } 440 }
437 441
438 // Handles the result of signal connection setup. 442 // Handles the result of signal connection setup.
439 void OnSignalConnected(const std::string& interface, 443 void OnSignalConnected(const std::string& interface,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // dict entry { 516 // dict entry {
513 // string "DeviceIsReadOnly" 517 // string "DeviceIsReadOnly"
514 // variant bool false 518 // variant bool false
515 // } 519 // }
516 // dict entry { 520 // dict entry {
517 // string "DeviceIsVirtual" 521 // string "DeviceIsVirtual"
518 // variant bool false 522 // variant bool false
519 // } 523 // }
520 // dict entry { 524 // dict entry {
521 // string "DeviceMediaType" 525 // string "DeviceMediaType"
522 // variant uint32 1 526 // variant uint32_t 1
523 // } 527 // }
524 // dict entry { 528 // dict entry {
525 // string "DeviceMountPaths" 529 // string "DeviceMountPaths"
526 // variant array [ 530 // variant array [
527 // ] 531 // ]
528 // } 532 // }
529 // dict entry { 533 // dict entry {
530 // string "DevicePresentationHide" 534 // string "DevicePresentationHide"
531 // variant bool true 535 // variant bool true
532 // } 536 // }
533 // dict entry { 537 // dict entry {
534 // string "DeviceSize" 538 // string "DeviceSize"
535 // variant uint64 7998537728 539 // variant uint64_t 7998537728
536 // } 540 // }
537 // dict entry { 541 // dict entry {
538 // string "DriveIsRotational" 542 // string "DriveIsRotational"
539 // variant bool false 543 // variant bool false
540 // } 544 // }
541 // dict entry { 545 // dict entry {
542 // string "VendorId" 546 // string "VendorId"
543 // variant string "18d1" 547 // variant string "18d1"
544 // } 548 // }
545 // dict entry { 549 // dict entry {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 cros_disks::kVendorName, &vendor_name_); 603 cros_disks::kVendorName, &vendor_name_);
600 properties->GetStringWithoutPathExpansion( 604 properties->GetStringWithoutPathExpansion(
601 cros_disks::kProductId, &product_id_); 605 cros_disks::kProductId, &product_id_);
602 properties->GetStringWithoutPathExpansion( 606 properties->GetStringWithoutPathExpansion(
603 cros_disks::kProductName, &product_name_); 607 cros_disks::kProductName, &product_name_);
604 properties->GetStringWithoutPathExpansion( 608 properties->GetStringWithoutPathExpansion(
605 cros_disks::kDriveModel, &drive_model_); 609 cros_disks::kDriveModel, &drive_model_);
606 properties->GetStringWithoutPathExpansion(cros_disks::kIdLabel, &label_); 610 properties->GetStringWithoutPathExpansion(cros_disks::kIdLabel, &label_);
607 properties->GetStringWithoutPathExpansion(cros_disks::kIdUuid, &uuid_); 611 properties->GetStringWithoutPathExpansion(cros_disks::kIdUuid, &uuid_);
608 612
609 // dbus::PopDataAsValue() pops uint64 as double. 613 // dbus::PopDataAsValue() pops uint64_t as double.
610 // The top 11 bits of uint64 are dropped by the use of double. But, this works 614 // The top 11 bits of uint64_t are dropped by the use of double. But, this
615 // works
611 // unless the size exceeds 8 PB. 616 // unless the size exceeds 8 PB.
612 double device_size_double = 0; 617 double device_size_double = 0;
613 if (properties->GetDoubleWithoutPathExpansion(cros_disks::kDeviceSize, 618 if (properties->GetDoubleWithoutPathExpansion(cros_disks::kDeviceSize,
614 &device_size_double)) 619 &device_size_double))
615 total_size_in_bytes_ = device_size_double; 620 total_size_in_bytes_ = device_size_double;
616 621
617 // dbus::PopDataAsValue() pops uint32 as double. 622 // dbus::PopDataAsValue() pops uint32_t as double.
618 double media_type_double = 0; 623 double media_type_double = 0;
619 if (properties->GetDoubleWithoutPathExpansion(cros_disks::kDeviceMediaType, 624 if (properties->GetDoubleWithoutPathExpansion(cros_disks::kDeviceMediaType,
620 &media_type_double)) 625 &media_type_double))
621 device_type_ = DeviceMediaTypeToDeviceType(media_type_double); 626 device_type_ = DeviceMediaTypeToDeviceType(media_type_double);
622 627
623 base::ListValue* mount_paths = NULL; 628 base::ListValue* mount_paths = NULL;
624 if (properties->GetListWithoutPathExpansion(cros_disks::kDeviceMountPaths, 629 if (properties->GetListWithoutPathExpansion(cros_disks::kDeviceMountPaths,
625 &mount_paths)) 630 &mount_paths))
626 mount_paths->GetString(0, &mount_path_); 631 mount_paths->GetString(0, &mount_path_);
627 } 632 }
(...skipping 21 matching lines...) Expand all
649 } 654 }
650 655
651 // static 656 // static
652 base::FilePath CrosDisksClient::GetRemovableDiskMountPoint() { 657 base::FilePath CrosDisksClient::GetRemovableDiskMountPoint() {
653 return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ? 658 return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ?
654 FILE_PATH_LITERAL("/media/removable") : 659 FILE_PATH_LITERAL("/media/removable") :
655 FILE_PATH_LITERAL("/tmp/chromeos/media/removable")); 660 FILE_PATH_LITERAL("/tmp/chromeos/media/removable"));
656 } 661 }
657 662
658 } // namespace chromeos 663 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/cros_disks_client.h ('k') | chromeos/dbus/cros_disks_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698