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

Side by Side Diff: chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.h

Issue 10918259: [Chrome OS]Implement MediaStorageUtil::GetDeviceInfoForPath function to support media gallery permi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 3 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 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_CH ROMEOS_H_ 5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_CH ROMEOS_H_
6 #define CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_CH ROMEOS_H_ 6 #define CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_CH ROMEOS_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "base/system_monitor/system_monitor.h"
12 #include "chrome/browser/chromeos/mtp/media_transfer_protocol_manager.h" 13 #include "chrome/browser/chromeos/mtp/media_transfer_protocol_manager.h"
13 14
15 class FilePath;
16
14 namespace chromeos { 17 namespace chromeos {
15 namespace mtp { 18 namespace mtp {
16 19
17 // Gets the mtp device information given a |storage_name|. On success, 20 // Gets the mtp device information given a |storage_name|. On success,
18 // fills in |id|, |name| and |location|. 21 // fills in |id|, |name| and |location|.
19 typedef void (*GetStorageInfoFunc)(const std::string& storage_name, 22 typedef void (*GetStorageInfoFunc)(const std::string& storage_name,
20 std::string* id, 23 std::string* id,
21 string16* name, 24 string16* name,
22 std::string* location); 25 std::string* location);
23 26
24 // Helper class to send MTP storage attachment and detachment events to 27 // Helper class to send MTP storage attachment and detachment events to
25 // SystemMonitor. 28 // SystemMonitor.
26 class MediaTransferProtocolDeviceObserverCros 29 class MediaTransferProtocolDeviceObserverCros
27 : public MediaTransferProtocolManager::Observer { 30 : public MediaTransferProtocolManager::Observer {
28 public: 31 public:
32 // Should only be called by browser start up code. Use GetInstance() instead.
29 MediaTransferProtocolDeviceObserverCros(); 33 MediaTransferProtocolDeviceObserverCros();
34 static MediaTransferProtocolDeviceObserverCros* GetInstance();
Lei Zhang 2012/09/16 00:17:05 nit: don't put this between the ctor and dtor.
kmadhusu 2012/09/16 22:35:42 Done.
35
30 virtual ~MediaTransferProtocolDeviceObserverCros(); 36 virtual ~MediaTransferProtocolDeviceObserverCros();
31 37
38 // Finds the storage that contains |path| and populates |storage_info|.
39 // Returns false if unable to find the storage.
40 bool GetStorageInfoForPath(
41 const FilePath& path,
42 base::SystemMonitor::RemovableStorageInfo* storage_info) const;
43
32 protected: 44 protected:
33 // Only used in unit tests. 45 // Only used in unit tests.
34 explicit MediaTransferProtocolDeviceObserverCros( 46 explicit MediaTransferProtocolDeviceObserverCros(
35 GetStorageInfoFunc get_storage_info_func); 47 GetStorageInfoFunc get_storage_info_func);
36 48
37 // MediaTransferProtocolManager::Observer implementation. 49 // MediaTransferProtocolManager::Observer implementation.
38 // Exposed for unit tests. 50 // Exposed for unit tests.
39 virtual void StorageChanged(bool is_attached, 51 virtual void StorageChanged(bool is_attached,
40 const std::string& storage_name) OVERRIDE; 52 const std::string& storage_name) OVERRIDE;
41 53
42 private: 54 private:
43 // Mapping of storage name and device id. 55 // Structure to save attached storage information such as id, name and root
44 typedef std::map<std::string, std::string> StorageNameToIdMap; 56 // path.
57 struct StorageInfo {
Lei Zhang 2012/09/16 00:17:05 hey, this looks familiar.
kmadhusu 2012/09/16 22:35:42 :)
58 StorageInfo();
vandebo (ex-Chrome) 2012/09/16 00:31:44 You can omit the default constructor when you have
kmadhusu 2012/09/16 22:35:42 Done.
59
60 // Unique storage Id (e.g. "VendorModelVolumeStorage:FFFF:0FFF:D:65537")
61 std::string id;
62
63 // Storage Name (e.g. "usb:2,2:65537")
64 string16 name;
65
66 // Storage root path (e.g. "/usb:2,2:65537")
67 std::string location;
68 };
69
70 // Mapping of storage location and StorageInfo object
71 typedef std::map<std::string, StorageInfo> StorageLocationToInfoMap;
45 72
46 // Enumerate existing mtp storage devices. 73 // Enumerate existing mtp storage devices.
47 void EnumerateStorages(); 74 void EnumerateStorages();
48 75
49 // Map of all attached mtp devices. 76 // Map of all attached mtp devices.
50 StorageNameToIdMap storage_map_; 77 StorageLocationToInfoMap storage_map_;
51 78
52 // Function handler to get storage information. This is useful to set a mock 79 // Function handler to get storage information. This is useful to set a mock
53 // handler for unit testing. 80 // handler for unit testing.
54 GetStorageInfoFunc get_storage_info_func_; 81 GetStorageInfoFunc get_storage_info_func_;
55 82
56 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverCros); 83 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverCros);
57 }; 84 };
58 85
59 } // namespace mtp 86 } // namespace mtp
60 } // namespace chromeos 87 } // namespace chromeos
61 88
62 #endif // CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER _CHROMEOS_H_ 89 #endif // CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER _CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698