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

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

Issue 9019002: [CrosDisksClient] Determine device type from DeviceMediaType property sent by cros-disks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 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) 2011 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 "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 // Checks if retrieved media type is in boundaries of DeviceMediaType.
31 DeviceType GetDeviceType(bool is_optical, bool is_rotational) { 31 bool IsValidMediaType(uint32 type) {
32 if (is_optical) 32 return type < static_cast<uint32>(cros_disks::DEVICE_MEDIA_NUM_VALUES);
33 return OPTICAL; 33 }
34 if (is_rotational) 34
35 return HDD; 35
36 return FLASH; 36 // Translates enum used in cros-disks to enum used in Chrome.
37 // Note that we could just do static_cast, but this is less sensitive to
38 // changes in cros-disks.
39 DeviceType DeviceMediaTypeToDeviceType(uint32 media_type_uint32) {
40 if (!IsValidMediaType(media_type_uint32))
41 return DEVICE_TYPE_UNKNOWN;
42
43 cros_disks::DeviceMediaType media_type =
44 cros_disks::DeviceMediaType(media_type_uint32);
45
46 switch (media_type) {
47 case(cros_disks::DEVICE_MEDIA_UNKNOWN):
48 return DEVICE_TYPE_UNKNOWN;
49 case(cros_disks::DEVICE_MEDIA_USB):
50 return DEVICE_TYPE_USB;
51 case(cros_disks::DEVICE_MEDIA_SD):
52 return DEVICE_TYPE_SD;
53 case(cros_disks::DEVICE_MEDIA_OPTICAL_DISC):
54 return DEVICE_TYPE_OPTICAL_DISC;
55 case(cros_disks::DEVICE_MEDIA_MOBILE):
56 return DEVICE_TYPE_MOBILE;
57 default:
58 return DEVICE_TYPE_UNKNOWN;
59 }
37 } 60 }
38 61
39 // Pops a bool value when |reader| is not NULL. 62 // Pops a bool value when |reader| is not NULL.
40 // Returns true when a value is popped, false otherwise. 63 // Returns true when a value is popped, false otherwise.
41 bool MaybePopBool(dbus::MessageReader* reader, bool* value) { 64 bool MaybePopBool(dbus::MessageReader* reader, bool* value) {
42 if (!reader) 65 if (!reader)
43 return false; 66 return false;
44 return reader->PopBool(value); 67 return reader->PopBool(value);
45 } 68 }
46 69
47 // Pops a string value when |reader| is not NULL. 70 // Pops a string value when |reader| is not NULL.
48 // Returns true when a value is popped, false otherwise. 71 // Returns true when a value is popped, false otherwise.
49 bool MaybePopString(dbus::MessageReader* reader, std::string* value) { 72 bool MaybePopString(dbus::MessageReader* reader, std::string* value) {
50 if (!reader) 73 if (!reader)
51 return false; 74 return false;
52 return reader->PopString(value); 75 return reader->PopString(value);
53 } 76 }
54 77
78 // Pops a uint32 value when |reader| is not NULL.
79 // Returns true when a value is popped, false otherwise.
80 bool MaybePopUint32(dbus::MessageReader* reader, uint32* value) {
81 if (!reader)
82 return false;
83
84 return reader->PopUint32(value);
85 }
86
55 // Pops a uint64 value when |reader| is not NULL. 87 // Pops a uint64 value when |reader| is not NULL.
56 // Returns true when a value is popped, false otherwise. 88 // Returns true when a value is popped, false otherwise.
57 bool MaybePopUint64(dbus::MessageReader* reader, uint64* value) { 89 bool MaybePopUint64(dbus::MessageReader* reader, uint64* value) {
58 if (!reader) 90 if (!reader)
59 return false; 91 return false;
60 return reader->PopUint64(value); 92 return reader->PopUint64(value);
61 } 93 }
62 94
63 // Pops an array of strings when |reader| is not NULL. 95 // Pops an array of strings when |reader| is not NULL.
64 // Returns true when an array is popped, false otherwise. 96 // Returns true when an array is popped, false otherwise.
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } // namespace 400 } // namespace
369 401
370 //////////////////////////////////////////////////////////////////////////////// 402 ////////////////////////////////////////////////////////////////////////////////
371 // DiskInfo 403 // DiskInfo
372 404
373 DiskInfo::DiskInfo(const std::string& device_path, dbus::Response* response) 405 DiskInfo::DiskInfo(const std::string& device_path, dbus::Response* response)
374 : device_path_(device_path), 406 : device_path_(device_path),
375 is_drive_(false), 407 is_drive_(false),
376 has_media_(false), 408 has_media_(false),
377 on_boot_device_(false), 409 on_boot_device_(false),
378 device_type_(UNDEFINED), 410 device_type_(DEVICE_TYPE_UNKNOWN),
379 total_size_in_bytes_(0), 411 total_size_in_bytes_(0),
380 is_read_only_(false), 412 is_read_only_(false),
381 is_hidden_(true) { 413 is_hidden_(true) {
382 InitializeFromResponse(response); 414 InitializeFromResponse(response);
383 } 415 }
384 416
385 DiskInfo::~DiskInfo() { 417 DiskInfo::~DiskInfo() {
386 } 418 }
387 419
388 // Initialize |this| from |response| given by the cros-disks service. 420 // Initialize |this| from |response| given by the cros-disks service.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 MaybePopBool(properties[cros_disks::kDevicePresentationHide], &is_hidden_); 527 MaybePopBool(properties[cros_disks::kDevicePresentationHide], &is_hidden_);
496 MaybePopBool(properties[cros_disks::kDeviceIsMediaAvailable], &has_media_); 528 MaybePopBool(properties[cros_disks::kDeviceIsMediaAvailable], &has_media_);
497 MaybePopBool(properties[cros_disks::kDeviceIsOnBootDevice], 529 MaybePopBool(properties[cros_disks::kDeviceIsOnBootDevice],
498 &on_boot_device_); 530 &on_boot_device_);
499 MaybePopString(properties[cros_disks::kNativePath], &system_path_); 531 MaybePopString(properties[cros_disks::kNativePath], &system_path_);
500 MaybePopString(properties[cros_disks::kDeviceFile], &file_path_); 532 MaybePopString(properties[cros_disks::kDeviceFile], &file_path_);
501 MaybePopString(properties[cros_disks::kDriveModel], &drive_model_); 533 MaybePopString(properties[cros_disks::kDriveModel], &drive_model_);
502 MaybePopString(properties[cros_disks::kIdLabel], &label_); 534 MaybePopString(properties[cros_disks::kIdLabel], &label_);
503 MaybePopUint64(properties[cros_disks::kDeviceSize], &total_size_in_bytes_); 535 MaybePopUint64(properties[cros_disks::kDeviceSize], &total_size_in_bytes_);
504 536
537 uint32 media_type_uint32 = 0;
538 if (MaybePopUint32(properties[cros_disks::kDeviceMediaType],
539 &media_type_uint32)) {
540 device_type_ = DeviceMediaTypeToDeviceType(media_type_uint32);
541 }
542
505 std::vector<std::string> mount_paths; 543 std::vector<std::string> mount_paths;
506 if (MaybePopArrayOfStrings(properties[cros_disks::kDeviceMountPaths], 544 if (MaybePopArrayOfStrings(properties[cros_disks::kDeviceMountPaths],
507 &mount_paths) && !mount_paths.empty()) 545 &mount_paths) && !mount_paths.empty())
508 mount_path_ = mount_paths[0]; 546 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 } 547 }
518 548
519 //////////////////////////////////////////////////////////////////////////////// 549 ////////////////////////////////////////////////////////////////////////////////
520 // CrosDisksClient 550 // CrosDisksClient
521 551
522 CrosDisksClient::CrosDisksClient() {} 552 CrosDisksClient::CrosDisksClient() {}
523 553
524 CrosDisksClient::~CrosDisksClient() {} 554 CrosDisksClient::~CrosDisksClient() {}
525 555
526 // static 556 // static
527 CrosDisksClient* CrosDisksClient::Create(dbus::Bus* bus) { 557 CrosDisksClient* CrosDisksClient::Create(dbus::Bus* bus) {
528 if (system::runtime_environment::IsRunningOnChromeOS()) 558 if (system::runtime_environment::IsRunningOnChromeOS())
529 return new CrosDisksClientImpl(bus); 559 return new CrosDisksClientImpl(bus);
530 else 560 else
531 return new CrosDisksClientStubImpl(); 561 return new CrosDisksClientStubImpl();
532 } 562 }
533 563
534 } // namespace chromeos 564 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/cros_disks_client.h ('k') | chrome/browser/chromeos/disks/disk_mount_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698