OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/dbus/cros_disks_client.h" | 5 #include "chrome/browser/chromeos/dbus/cros_disks_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/chromeos/system/runtime_environment.h" | 9 #include "chrome/browser/chromeos/system/runtime_environment.h" |
10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
11 #include "dbus/message.h" | 11 #include "dbus/message.h" |
12 #include "dbus/object_proxy.h" | 12 #include "dbus/object_proxy.h" |
13 #include "third_party/cros_system_api/dbus/service_constants.h" | 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
14 | 14 |
15 namespace chromeos { | 15 namespace chromeos { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 const char* kDefaultMountOptions[] = { | 19 const char* kDefaultMountOptions[] = { |
20 "rw", | 20 "rw", |
21 "nodev", | 21 "nodev", |
22 "noexec", | 22 "noexec", |
23 "nosuid", | 23 "nosuid", |
24 }; | 24 }; |
25 | 25 |
26 const char* kDefaultUnmountOptions[] = { | 26 const char* kDefaultUnmountOptions[] = { |
27 "force", | 27 "force", |
28 }; | 28 }; |
29 | 29 |
30 // Returns the device type from the given arguments. | 30 // Translate enum used in cros-disks to enum used in Chrome. |
satorux1
2012/01/23 22:18:55
"Translates" per C++ style guide.
tbarzic
2012/01/23 22:42:40
Done.
| |
31 DeviceType GetDeviceType(bool is_optical, bool is_rotational) { | 31 // Note that we could just do static_cast, but this is less sensitive to |
32 if (is_optical) | 32 // changes in cros-disks. |
33 return OPTICAL; | 33 DeviceType DeviceMediaTypeToDeviceType(cros_disks::DeviceMediaType type) { |
34 if (is_rotational) | 34 switch (type) { |
35 return HDD; | 35 case(cros_disks::DEVICE_MEDIA_UNKNOWN): |
36 return FLASH; | 36 return DEVICE_TYPE_UNKNOWN; |
37 case(cros_disks::DEVICE_MEDIA_USB): | |
38 return DEVICE_TYPE_USB; | |
39 case(cros_disks::DEVICE_MEDIA_SD): | |
40 return DEVICE_TYPE_SD; | |
41 case(cros_disks::DEVICE_MEDIA_OPTICAL_DISC): | |
42 return DEVICE_TYPE_OPTICAL; | |
satorux1
2012/01/23 22:18:55
DEVICE_TYPE_OPTICAL_DISC would be better for consi
tbarzic
2012/01/23 22:42:40
Done.
| |
43 case(cros_disks::DEVICE_MEDIA_MOBILE): | |
44 return DEVICE_TYPE_MOBILE; | |
45 default: | |
46 return DEVICE_TYPE_UNKNOWN; | |
47 } | |
48 } | |
49 | |
50 // Check if retrieved media type is in boundaries of DeviceMediaType. | |
satorux1
2012/01/23 22:18:55
Checks
tbarzic
2012/01/23 22:42:40
Done.
| |
51 bool MediaTypeInBoundaries(uint32 type) { | |
satorux1
2012/01/23 22:18:55
maybe IsValidMediaType() would be a bit better nam
tbarzic
2012/01/23 22:42:40
Done.
| |
52 return type < static_cast<uint32>(cros_disks::DEVICE_MEDIA_NUM_VALUES) && | |
53 type >= 0; | |
54 } | |
55 | |
56 // Pop unit32 value and converts it to DeviceMediaType when |reader| is not | |
satorux1
2012/01/23 22:18:55
Pops
tbarzic
2012/01/23 22:42:40
Done.
| |
57 // NULL. Returns true iff value is popped and converted. | |
58 bool MaybePopDeviceType(dbus::MessageReader* reader, DeviceType* type) { | |
59 if (!reader) | |
60 return false; | |
61 | |
62 uint32 media_type_uint32; | |
satorux1
2012/01/23 22:18:55
uint32 media_type_uint32 = 0;
just in case.
tbarzic
2012/01/23 22:42:40
Done.
| |
63 bool success = reader->PopUint32(&media_type_uint32); | |
64 | |
65 if (!success || !MediaTypeInBoundaries(media_type_uint32)) | |
66 return false; | |
67 | |
68 *type = DeviceMediaTypeToDeviceType( | |
69 cros_disks::DeviceMediaType(media_type_uint32)); | |
70 return success; | |
37 } | 71 } |
38 | 72 |
39 // Pops a bool value when |reader| is not NULL. | 73 // Pops a bool value when |reader| is not NULL. |
40 // Returns true when a value is popped, false otherwise. | 74 // Returns true when a value is popped, false otherwise. |
41 bool MaybePopBool(dbus::MessageReader* reader, bool* value) { | 75 bool MaybePopBool(dbus::MessageReader* reader, bool* value) { |
42 if (!reader) | 76 if (!reader) |
43 return false; | 77 return false; |
44 return reader->PopBool(value); | 78 return reader->PopBool(value); |
45 } | 79 } |
46 | 80 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 } // namespace | 402 } // namespace |
369 | 403 |
370 //////////////////////////////////////////////////////////////////////////////// | 404 //////////////////////////////////////////////////////////////////////////////// |
371 // DiskInfo | 405 // DiskInfo |
372 | 406 |
373 DiskInfo::DiskInfo(const std::string& device_path, dbus::Response* response) | 407 DiskInfo::DiskInfo(const std::string& device_path, dbus::Response* response) |
374 : device_path_(device_path), | 408 : device_path_(device_path), |
375 is_drive_(false), | 409 is_drive_(false), |
376 has_media_(false), | 410 has_media_(false), |
377 on_boot_device_(false), | 411 on_boot_device_(false), |
378 device_type_(UNDEFINED), | 412 device_type_(DEVICE_TYPE_UNKNOWN), |
379 total_size_in_bytes_(0), | 413 total_size_in_bytes_(0), |
380 is_read_only_(false), | 414 is_read_only_(false), |
381 is_hidden_(true) { | 415 is_hidden_(true) { |
382 InitializeFromResponse(response); | 416 InitializeFromResponse(response); |
383 } | 417 } |
384 | 418 |
385 DiskInfo::~DiskInfo() { | 419 DiskInfo::~DiskInfo() { |
386 } | 420 } |
387 | 421 |
388 // Initialize |this| from |response| given by the cros-disks service. | 422 // Initialize |this| from |response| given by the cros-disks service. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 MaybePopBool(properties[cros_disks::kDeviceIsReadOnly], &is_read_only_); | 528 MaybePopBool(properties[cros_disks::kDeviceIsReadOnly], &is_read_only_); |
495 MaybePopBool(properties[cros_disks::kDevicePresentationHide], &is_hidden_); | 529 MaybePopBool(properties[cros_disks::kDevicePresentationHide], &is_hidden_); |
496 MaybePopBool(properties[cros_disks::kDeviceIsMediaAvailable], &has_media_); | 530 MaybePopBool(properties[cros_disks::kDeviceIsMediaAvailable], &has_media_); |
497 MaybePopBool(properties[cros_disks::kDeviceIsOnBootDevice], | 531 MaybePopBool(properties[cros_disks::kDeviceIsOnBootDevice], |
498 &on_boot_device_); | 532 &on_boot_device_); |
499 MaybePopString(properties[cros_disks::kNativePath], &system_path_); | 533 MaybePopString(properties[cros_disks::kNativePath], &system_path_); |
500 MaybePopString(properties[cros_disks::kDeviceFile], &file_path_); | 534 MaybePopString(properties[cros_disks::kDeviceFile], &file_path_); |
501 MaybePopString(properties[cros_disks::kDriveModel], &drive_model_); | 535 MaybePopString(properties[cros_disks::kDriveModel], &drive_model_); |
502 MaybePopString(properties[cros_disks::kIdLabel], &label_); | 536 MaybePopString(properties[cros_disks::kIdLabel], &label_); |
503 MaybePopUint64(properties[cros_disks::kDeviceSize], &total_size_in_bytes_); | 537 MaybePopUint64(properties[cros_disks::kDeviceSize], &total_size_in_bytes_); |
538 MaybePopDeviceType(properties[cros_disks::kDeviceMediaType], &device_type_); | |
504 | 539 |
505 std::vector<std::string> mount_paths; | 540 std::vector<std::string> mount_paths; |
506 if (MaybePopArrayOfStrings(properties[cros_disks::kDeviceMountPaths], | 541 if (MaybePopArrayOfStrings(properties[cros_disks::kDeviceMountPaths], |
507 &mount_paths) && !mount_paths.empty()) | 542 &mount_paths) && !mount_paths.empty()) |
508 mount_path_ = mount_paths[0]; | 543 mount_path_ = mount_paths[0]; |
509 | |
510 bool is_rotational = false; | |
511 bool is_optical = false; | |
512 if (MaybePopBool(properties[cros_disks::kDriveIsRotational], | |
513 &is_rotational) && | |
514 MaybePopBool(properties[cros_disks::kDeviceIsOpticalDisc], | |
515 &is_optical)) | |
516 device_type_ = GetDeviceType(is_optical, is_rotational); | |
517 } | 544 } |
518 | 545 |
519 //////////////////////////////////////////////////////////////////////////////// | 546 //////////////////////////////////////////////////////////////////////////////// |
520 // CrosDisksClient | 547 // CrosDisksClient |
521 | 548 |
522 CrosDisksClient::CrosDisksClient() {} | 549 CrosDisksClient::CrosDisksClient() {} |
523 | 550 |
524 CrosDisksClient::~CrosDisksClient() {} | 551 CrosDisksClient::~CrosDisksClient() {} |
525 | 552 |
526 // static | 553 // static |
527 CrosDisksClient* CrosDisksClient::Create(dbus::Bus* bus) { | 554 CrosDisksClient* CrosDisksClient::Create(dbus::Bus* bus) { |
528 if (system::runtime_environment::IsRunningOnChromeOS()) | 555 if (system::runtime_environment::IsRunningOnChromeOS()) |
529 return new CrosDisksClientImpl(bus); | 556 return new CrosDisksClientImpl(bus); |
530 else | 557 else |
531 return new CrosDisksClientStubImpl(); | 558 return new CrosDisksClientStubImpl(); |
532 } | 559 } |
533 | 560 |
534 } // namespace chromeos | 561 } // namespace chromeos |
OLD | NEW |