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

Side by Side Diff: chrome/browser/system_monitor/removable_device_notifications_chromeos.cc

Issue 11573048: [Media Galleries] Move RemovableStorageInfo notifications to chrome namespace (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing up tests Created 7 years, 11 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 // chromeos::RemovableDeviceNotificationsCros implementation. 5 // chromeos::RemovableDeviceNotificationsCros implementation.
6 6
7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos. h" 7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos. h"
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" 15 #include "chrome/browser/system_monitor/media_device_notifications_utils.h"
16 #include "chrome/browser/system_monitor/media_storage_util.h" 16 #include "chrome/browser/system_monitor/media_storage_util.h"
17 #include "chrome/browser/system_monitor/removable_device_constants.h" 17 #include "chrome/browser/system_monitor/removable_device_constants.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 19
20 namespace chromeos { 20 namespace chromeos {
21 21
22 using base::SystemMonitor;
23
24 namespace { 22 namespace {
25 23
26 // Constructs a device name using label or manufacturer (vendor and product) 24 // Constructs a device name using label or manufacturer (vendor and product)
27 // name details. 25 // name details.
28 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { 26 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) {
29 if (disk.device_type() == DEVICE_TYPE_SD) { 27 if (disk.device_type() == DEVICE_TYPE_SD) {
30 // Mount path of an SD card will be one of the following: 28 // Mount path of an SD card will be one of the following:
31 // (1) /media/removable/<volume_label> 29 // (1) /media/removable/<volume_label>
32 // (2) /media/removable/SD Card 30 // (2) /media/removable/SD Card
33 // If the volume label is available, mount path will be (1) else (2). 31 // If the volume label is available, mount path will be (1) else (2).
(...skipping 21 matching lines...) Expand all
55 // Format: VendorModelSerial:VendorInfo:ModelInfo:SerialInfo 53 // Format: VendorModelSerial:VendorInfo:ModelInfo:SerialInfo
56 // TODO(kmadhusu) Extract serial information for the disks and append it to 54 // TODO(kmadhusu) Extract serial information for the disks and append it to
57 // the device unique id. 55 // the device unique id.
58 const std::string& vendor = disk.vendor_id(); 56 const std::string& vendor = disk.vendor_id();
59 const std::string& product = disk.product_id(); 57 const std::string& product = disk.product_id();
60 if (vendor.empty() && product.empty()) 58 if (vendor.empty() && product.empty())
61 return std::string(); 59 return std::string();
62 return chrome::kVendorModelSerialPrefix + vendor + ":" + product + ":"; 60 return chrome::kVendorModelSerialPrefix + vendor + ":" + product + ":";
63 } 61 }
64 62
65 static RemovableDeviceNotificationsCros*
66 g_removable_device_notifications_chromeos = NULL;
67
68 // Returns true if the requested device is valid, else false. On success, fills 63 // Returns true if the requested device is valid, else false. On success, fills
69 // in |unique_id|, |device_label| and |storage_size_in_bytes|. 64 // in |unique_id|, |device_label| and |storage_size_in_bytes|.
70 bool GetDeviceInfo(const std::string& source_path, 65 bool GetDeviceInfo(const std::string& source_path,
71 std::string* unique_id, 66 std::string* unique_id,
72 string16* device_label, 67 string16* device_label,
73 uint64* storage_size_in_bytes) { 68 uint64* storage_size_in_bytes) {
74 const disks::DiskMountManager::Disk* disk = 69 const disks::DiskMountManager::Disk* disk =
75 disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path); 70 disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path);
76 if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN) 71 if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN)
77 return false; 72 return false;
78 73
79 if (unique_id) 74 if (unique_id)
80 *unique_id = MakeDeviceUniqueId(*disk); 75 *unique_id = MakeDeviceUniqueId(*disk);
81 76
82 if (device_label) 77 if (device_label)
83 *device_label = GetDeviceName(*disk); 78 *device_label = GetDeviceName(*disk);
84 79
85 if (storage_size_in_bytes) 80 if (storage_size_in_bytes)
86 *storage_size_in_bytes = disk->total_size_in_bytes(); 81 *storage_size_in_bytes = disk->total_size_in_bytes();
87 return true; 82 return true;
88 } 83 }
89 84
90 } // namespace 85 } // namespace
91 86
92 using content::BrowserThread; 87 using content::BrowserThread;
93 88
94 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { 89 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() {
95 DCHECK(disks::DiskMountManager::GetInstance()); 90 DCHECK(disks::DiskMountManager::GetInstance());
96 DCHECK(!g_removable_device_notifications_chromeos);
97 g_removable_device_notifications_chromeos = this;
98 disks::DiskMountManager::GetInstance()->AddObserver(this); 91 disks::DiskMountManager::GetInstance()->AddObserver(this);
99 CheckExistingMountPointsOnUIThread(); 92 CheckExistingMountPointsOnUIThread();
100 } 93 }
101 94
102 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() { 95 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() {
103 DCHECK_EQ(this, g_removable_device_notifications_chromeos);
104 g_removable_device_notifications_chromeos = NULL;
105 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); 96 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
106 if (manager) { 97 if (manager) {
107 manager->RemoveObserver(this); 98 manager->RemoveObserver(this);
108 } 99 }
109 } 100 }
110 101
111 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() { 102 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
113 const disks::DiskMountManager::MountPointMap& mount_point_map = 104 const disks::DiskMountManager::MountPointMap& mount_point_map =
114 disks::DiskMountManager::GetInstance()->mount_points(); 105 disks::DiskMountManager::GetInstance()->mount_points();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 BrowserThread::FILE, FROM_HERE, 149 BrowserThread::FILE, FROM_HERE,
159 base::Bind( 150 base::Bind(
160 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, 151 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread,
161 this, mount_info)); 152 this, mount_info));
162 break; 153 break;
163 } 154 }
164 case disks::DiskMountManager::UNMOUNTING: { 155 case disks::DiskMountManager::UNMOUNTING: {
165 MountMap::iterator it = mount_map_.find(mount_info.mount_path); 156 MountMap::iterator it = mount_map_.find(mount_info.mount_path);
166 if (it == mount_map_.end()) 157 if (it == mount_map_.end())
167 return; 158 return;
168 SystemMonitor::Get()->ProcessRemovableStorageDetached( 159 ProcessDetach(it->second.storage_info.device_id);
169 it->second.storage_info.device_id);
170 mount_map_.erase(it); 160 mount_map_.erase(it);
171 break; 161 break;
172 } 162 }
173 } 163 }
174 } 164 }
175 165
176 void RemovableDeviceNotificationsCros::OnFormatEvent( 166 void RemovableDeviceNotificationsCros::OnFormatEvent(
177 disks::DiskMountManager::FormatEvent event, 167 disks::DiskMountManager::FormatEvent event,
178 FormatError error_code, 168 FormatError error_code,
179 const std::string& device_path) { 169 const std::string& device_path) {
180 } 170 }
181 171
182 bool RemovableDeviceNotificationsCros::GetDeviceInfoForPath( 172 bool RemovableDeviceNotificationsCros::GetDeviceInfoForPath(
183 const FilePath& path, 173 const FilePath& path,
184 SystemMonitor::RemovableStorageInfo* device_info) const { 174 StorageInfo* device_info) const {
185 if (!path.IsAbsolute()) 175 if (!path.IsAbsolute())
186 return false; 176 return false;
187 177
188 FilePath current = path; 178 FilePath current = path;
189 while (!ContainsKey(mount_map_, current.value()) && 179 while (!ContainsKey(mount_map_, current.value()) &&
190 current != current.DirName()) { 180 current != current.DirName()) {
191 current = current.DirName(); 181 current = current.DirName();
192 } 182 }
193 183
194 MountMap::const_iterator info_it = mount_map_.find(current.value()); 184 MountMap::const_iterator info_it = mount_map_.find(current.value());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 if (unique_id.empty() || device_label.empty()) 235 if (unique_id.empty() || device_label.empty())
246 return; 236 return;
247 237
248 chrome::MediaStorageUtil::Type type = has_dcim ? 238 chrome::MediaStorageUtil::Type type = has_dcim ?
249 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : 239 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM :
250 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; 240 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
251 241
252 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, 242 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type,
253 unique_id); 243 unique_id);
254 StorageObjectInfo object_info = { 244 StorageObjectInfo object_info = {
255 base::SystemMonitor::RemovableStorageInfo(device_id, device_label, 245 StorageInfo(device_id, device_label, mount_info.mount_path),
256 mount_info.mount_path),
257 storage_size_in_bytes 246 storage_size_in_bytes
258 }; 247 };
259 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); 248 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info));
260 SystemMonitor::Get()->ProcessRemovableStorageAttached( 249 ProcessAttach(
261 device_id, 250 device_id,
262 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), 251 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label),
263 mount_info.mount_path); 252 mount_info.mount_path);
264 } 253 }
265 254
266 } // namespace chromeos 255 } // namespace chromeos
267
268 namespace chrome {
269
270 RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() {
271 return chromeos::g_removable_device_notifications_chromeos;
272 }
273
274 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698