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

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

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 // 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/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.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 "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 18
19 namespace chromeos { 19 namespace chromeos {
20 20
21 namespace { 21 namespace {
22 22
23 static RemovableDeviceNotificationsCros*
24 g_removable_device_notifications_chromeos = NULL;
25
23 // Returns true if the requested device is valid, else false. On success, fills 26 // Returns true if the requested device is valid, else false. On success, fills
24 // in |unique_id| and |device_label| 27 // in |unique_id| and |device_label|
25 bool GetDeviceInfo(const std::string& source_path, std::string* unique_id, 28 bool GetDeviceInfo(const std::string& source_path, std::string* unique_id,
26 string16* device_label) { 29 string16* device_label) {
27 // Get the media device uuid and label if exists. 30 // Get the media device uuid and label if exists.
28 const disks::DiskMountManager::Disk* disk = 31 const disks::DiskMountManager::Disk* disk =
29 disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path); 32 disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path);
30 if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN) 33 if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN)
31 return false; 34 return false;
32 35
33 *unique_id = disk->fs_uuid(); 36 *unique_id = disk->fs_uuid();
34 37
35 // TODO(kmadhusu): If device label is empty, extract vendor and model details 38 // TODO(kmadhusu): If device label is empty, extract vendor and model details
36 // and use them as device_label. 39 // and use them as device_label.
37 *device_label = UTF8ToUTF16(disk->device_label().empty() ? 40 *device_label = UTF8ToUTF16(disk->device_label().empty() ?
38 FilePath(source_path).BaseName().value() : 41 FilePath(source_path).BaseName().value() :
39 disk->device_label()); 42 disk->device_label());
40 return true; 43 return true;
41 } 44 }
42 45
43 } // namespace 46 } // namespace
44 47
45 using content::BrowserThread; 48 using content::BrowserThread;
46 49
47 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { 50 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() {
48 DCHECK(disks::DiskMountManager::GetInstance()); 51 DCHECK(disks::DiskMountManager::GetInstance());
52 DCHECK(!g_removable_device_notifications_chromeos);
53 g_removable_device_notifications_chromeos = this;
49 disks::DiskMountManager::GetInstance()->AddObserver(this); 54 disks::DiskMountManager::GetInstance()->AddObserver(this);
50 CheckExistingMountPointsOnUIThread(); 55 CheckExistingMountPointsOnUIThread();
51 } 56 }
52 57
53 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() { 58 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() {
59 DCHECK_EQ(this, g_removable_device_notifications_chromeos);
60 g_removable_device_notifications_chromeos = NULL;
54 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); 61 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
55 if (manager) { 62 if (manager) {
56 manager->RemoveObserver(this); 63 manager->RemoveObserver(this);
57 } 64 }
58 } 65 }
59 66
67 // static
68 RemovableDeviceNotificationsCros*
69 RemovableDeviceNotificationsCros::GetInstance() {
70 return g_removable_device_notifications_chromeos;
71 }
72
73 RemovableDeviceNotificationsCros::DeviceInfo::DeviceInfo() {
74 }
75
60 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() { 76 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
62 const disks::DiskMountManager::MountPointMap& mount_point_map = 78 const disks::DiskMountManager::MountPointMap& mount_point_map =
63 disks::DiskMountManager::GetInstance()->mount_points(); 79 disks::DiskMountManager::GetInstance()->mount_points();
64 for (disks::DiskMountManager::MountPointMap::const_iterator it = 80 for (disks::DiskMountManager::MountPointMap::const_iterator it =
65 mount_point_map.begin(); it != mount_point_map.end(); ++it) { 81 mount_point_map.begin(); it != mount_point_map.end(); ++it) {
66 BrowserThread::PostTask( 82 BrowserThread::PostTask(
67 BrowserThread::FILE, FROM_HERE, 83 BrowserThread::FILE, FROM_HERE,
68 base::Bind( 84 base::Bind(
69 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, 85 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 BrowserThread::FILE, FROM_HERE, 123 BrowserThread::FILE, FROM_HERE,
108 base::Bind( 124 base::Bind(
109 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, 125 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread,
110 this, mount_info)); 126 this, mount_info));
111 break; 127 break;
112 } 128 }
113 case disks::DiskMountManager::UNMOUNTING: { 129 case disks::DiskMountManager::UNMOUNTING: {
114 MountMap::iterator it = mount_map_.find(mount_info.mount_path); 130 MountMap::iterator it = mount_map_.find(mount_info.mount_path);
115 if (it == mount_map_.end()) 131 if (it == mount_map_.end())
116 return; 132 return;
117 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(it->second); 133 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(
134 it->second.id);
118 mount_map_.erase(it); 135 mount_map_.erase(it);
119 break; 136 break;
120 } 137 }
121 } 138 }
122 } 139 }
123 140
141 bool RemovableDeviceNotificationsCros::GetDeviceInfoForPath(
142 const FilePath& path,
143 base::SystemMonitor::RemovableStorageInfo* device_info) const {
144 if (!path.IsAbsolute())
145 return false;
146
147 FilePath current = path;
148 while (!ContainsKey(mount_map_, current.value()) &&
149 current != current.DirName()) {
150 current = current.DirName();
151 }
152
153 MountMap::const_iterator info_it = mount_map_.find(current.value());
154 if (info_it == mount_map_.end())
155 return false;
156
157 if (device_info) {
158 device_info->device_id = info_it->second.id;
159 device_info->location = info_it->second.location;
160 device_info->name = info_it->second.name;
161 }
162 return true;
163 }
164
124 void RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread( 165 void RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread(
125 const disks::DiskMountManager::MountPointInfo& mount_info) { 166 const disks::DiskMountManager::MountPointInfo& mount_info) {
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
127 168
128 bool has_dcim = chrome::IsMediaDevice(mount_info.mount_path); 169 bool has_dcim = chrome::IsMediaDevice(mount_info.mount_path);
129 170
130 BrowserThread::PostTask( 171 BrowserThread::PostTask(
131 BrowserThread::UI, FROM_HERE, 172 BrowserThread::UI, FROM_HERE,
132 base::Bind(&RemovableDeviceNotificationsCros::AddMountedPathOnUIThread, 173 base::Bind(&RemovableDeviceNotificationsCros::AddMountedPathOnUIThread,
133 this, mount_info, has_dcim)); 174 this, mount_info, has_dcim));
(...skipping 19 matching lines...) Expand all
153 !unique_id.empty()); 194 !unique_id.empty());
154 if (unique_id.empty()) 195 if (unique_id.empty())
155 return; 196 return;
156 197
157 chrome::MediaStorageUtil::Type type = has_dcim ? 198 chrome::MediaStorageUtil::Type type = has_dcim ?
158 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : 199 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM :
159 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; 200 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
160 201
161 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, 202 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type,
162 unique_id); 203 unique_id);
163 mount_map_.insert(std::make_pair(mount_info.mount_path, device_id)); 204 DeviceInfo info;
205 info.location = mount_info.mount_path;
206 info.id = device_id;
207 info.name = device_label;
208
209 mount_map_.insert(std::make_pair(mount_info.mount_path, info));
164 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( 210 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(
165 device_id, 211 device_id,
166 device_label, 212 device_label,
167 mount_info.mount_path); 213 mount_info.mount_path);
168 } 214 }
169 215
170 } // namespace chrome 216 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698