diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-29 21:54:36 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-29 21:54:36 +0000 |
commit | ae0ea4d284c3a6a521d2eb0fa7b64a76b08385a2 (patch) | |
tree | 57b8640e7f8a56e9ca70f343321d4bb30da18431 | |
parent | 4c1471bed6afee261b14486d96d2685f1c74b163 (diff) | |
download | chromium_src-ae0ea4d284c3a6a521d2eb0fa7b64a76b08385a2.zip chromium_src-ae0ea4d284c3a6a521d2eb0fa7b64a76b08385a2.tar.gz chromium_src-ae0ea4d284c3a6a521d2eb0fa7b64a76b08385a2.tar.bz2 |
Cleanup: In StorageMonitorLinux, use a scoper to call RecordGetDeviceInfoResult() instead of manually calling it on every return path.
Review URL: https://chromiumcodereview.appspot.com/13247004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191452 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/storage_monitor/storage_monitor.h | 7 | ||||
-rw-r--r-- | chrome/browser/storage_monitor/storage_monitor_linux.cc | 48 |
2 files changed, 34 insertions, 21 deletions
diff --git a/chrome/browser/storage_monitor/storage_monitor.h b/chrome/browser/storage_monitor/storage_monitor.h index 4dbd75f..325b97c2 100644 --- a/chrome/browser/storage_monitor/storage_monitor.h +++ b/chrome/browser/storage_monitor/storage_monitor.h @@ -5,6 +5,10 @@ #ifndef CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_H_ #define CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_H_ +#include <map> +#include <string> +#include <vector> + #include "base/callback.h" #include "base/files/file_path.h" #include "base/observer_list_threadsafe.h" @@ -117,6 +121,7 @@ class StorageMonitor { class ReceiverImpl; friend class ReceiverImpl; + // Key: device id. typedef std::map<std::string, StorageInfo> RemovableStorageMap; void ProcessAttach(const StorageInfo& storage); @@ -136,6 +141,6 @@ class StorageMonitor { scoped_ptr<TransientDeviceIds> transient_device_ids_; }; -} // namespace chrome +} // namespace chrome #endif // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_H_ diff --git a/chrome/browser/storage_monitor/storage_monitor_linux.cc b/chrome/browser/storage_monitor/storage_monitor_linux.cc index fe832e4..0bb5c51 100644 --- a/chrome/browser/storage_monitor/storage_monitor_linux.cc +++ b/chrome/browser/storage_monitor/storage_monitor_linux.cc @@ -110,11 +110,25 @@ std::string MakeDeviceUniqueId(struct udev_device* device) { return kVendorModelSerialPrefix + vendor + ":" + model + ":" + serial_short; } -// Records GetDeviceInfo result, to see how often we fail to get device details. -// TODO(thestig) Make this a scoper. -void RecordGetDeviceInfoResult(bool result) { - UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.UdevRequestSuccess", result); -} +// Records GetDeviceInfo result on destruction, to see how often we fail to get +// device details. +class ScopedGetDeviceInfoResultRecorder { + public: + ScopedGetDeviceInfoResultRecorder() : result_(false) {} + ~ScopedGetDeviceInfoResultRecorder() { + UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.UdevRequestSuccess", + result_); + } + + void set_result(bool result) { + result_ = result; + } + + private: + bool result_; + + DISALLOW_COPY_AND_ASSIGN(ScopedGetDeviceInfoResultRecorder); +}; // Returns the storage partition size of the device specified by |device_path|. // If the requested information is unavailable, returns 0. @@ -181,34 +195,28 @@ void GetDeviceInfo(const base::FilePath& device_path, DCHECK(!device_path.empty()); DCHECK(storage_info); + ScopedGetDeviceInfoResultRecorder results_recorder; + ScopedUdevObject udev_obj(udev_new()); - if (!udev_obj.get()) { - RecordGetDeviceInfoResult(false); + if (!udev_obj.get()) return; - } struct stat device_stat; - if (stat(device_path.value().c_str(), &device_stat) < 0) { - RecordGetDeviceInfoResult(false); + if (stat(device_path.value().c_str(), &device_stat) < 0) return; - } char device_type; - if (S_ISCHR(device_stat.st_mode)) { + if (S_ISCHR(device_stat.st_mode)) device_type = 'c'; - } else if (S_ISBLK(device_stat.st_mode)) { + else if (S_ISBLK(device_stat.st_mode)) device_type = 'b'; - } else { - RecordGetDeviceInfoResult(false); + else return; // Not a supported type. - } ScopedUdevDeviceObject device( udev_device_new_from_devnum(udev_obj, device_type, device_stat.st_rdev)); - if (!device.get()) { - RecordGetDeviceInfoResult(false); + if (!device.get()) return; - } string16 volume_label; string16 vendor_name; @@ -248,7 +256,7 @@ void GetDeviceInfo(const base::FilePath& device_path, vendor_name, model_name, GetDeviceStorageSize(device_path, device)); - RecordGetDeviceInfoResult(true); + results_recorder.set_result(true); } } // namespace |