OLD | NEW |
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 #include "chrome/browser/intents/device_attached_intent_source.h" | 5 #include "chrome/browser/intents/device_attached_intent_source.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/intents/web_intents_registry.h" | 14 #include "chrome/browser/intents/web_intents_registry.h" |
15 #include "chrome/browser/intents/web_intents_registry_factory.h" | 15 #include "chrome/browser/intents/web_intents_registry_factory.h" |
| 16 #include "chrome/browser/media_gallery/media_storage_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
19 #include "content/public/browser/web_intents_dispatcher.h" | 20 #include "content/public/browser/web_intents_dispatcher.h" |
20 #include "content/public/browser/web_contents_delegate.h" | 21 #include "content/public/browser/web_contents_delegate.h" |
21 #include "webkit/fileapi/file_system_types.h" | 22 #include "webkit/fileapi/file_system_types.h" |
22 #include "webkit/fileapi/isolated_context.h" | 23 #include "webkit/fileapi/isolated_context.h" |
23 #include "webkit/glue/web_intent_data.h" | 24 #include "webkit/glue/web_intent_data.h" |
24 #include "webkit/glue/web_intent_service_data.h" | 25 #include "webkit/glue/web_intent_service_data.h" |
25 #include "webkit/fileapi/media/media_file_system_config.h" | 26 #include "webkit/fileapi/media/media_file_system_config.h" |
26 | 27 |
27 #if defined(SUPPORT_MEDIA_FILESYSTEM) | 28 #if defined(SUPPORT_MEDIA_FILESYSTEM) |
28 #include "webkit/fileapi/media/media_device_map_service.h" | 29 #include "webkit/fileapi/media/media_device_map_service.h" |
29 | 30 |
30 using fileapi::MediaDeviceMapService; | 31 using fileapi::MediaDeviceMapService; |
31 #endif | 32 #endif |
32 | 33 |
33 using base::SystemMonitor; | 34 using base::SystemMonitor; |
| 35 using chrome::MediaStorageUtil; |
34 using content::WebContentsDelegate; | 36 using content::WebContentsDelegate; |
35 using webkit_glue::WebIntentServiceData; | 37 using webkit_glue::WebIntentServiceData; |
36 | 38 |
37 namespace { | 39 namespace { |
38 | 40 |
39 // Specifies device attached web intent kAction. | 41 // Specifies device attached web intent kAction. |
40 const char kAction[] = "chrome-extension://attach"; | 42 const char kAction[] = "chrome-extension://attach"; |
41 | 43 |
42 // Specifies device attached web intent type. | 44 // Specifies device attached web intent type. |
43 const char kIntentType[] = "chrome-extension://filesystem"; | 45 const char kIntentType[] = "chrome-extension://filesystem"; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 92 |
91 DeviceAttachedIntentSource::~DeviceAttachedIntentSource() { | 93 DeviceAttachedIntentSource::~DeviceAttachedIntentSource() { |
92 SystemMonitor* sys_monitor = SystemMonitor::Get(); | 94 SystemMonitor* sys_monitor = SystemMonitor::Get(); |
93 if (sys_monitor) | 95 if (sys_monitor) |
94 sys_monitor->RemoveDevicesChangedObserver(this); | 96 sys_monitor->RemoveDevicesChangedObserver(this); |
95 } | 97 } |
96 | 98 |
97 void DeviceAttachedIntentSource::OnMediaDeviceAttached( | 99 void DeviceAttachedIntentSource::OnMediaDeviceAttached( |
98 const std::string& id, | 100 const std::string& id, |
99 const string16& name, | 101 const string16& name, |
100 base::SystemMonitor::MediaDeviceType device_type, | |
101 const FilePath::StringType& location) { | 102 const FilePath::StringType& location) { |
102 if (!browser_->window()->IsActive()) | 103 if (!browser_->window()->IsActive()) |
103 return; | 104 return; |
104 | 105 |
105 // TODO(kmadhusu): Dispatch intents on incognito window. | 106 // TODO(kmadhusu): Dispatch intents on incognito window. |
106 if (browser_->profile()->IsOffTheRecord()) | 107 if (browser_->profile()->IsOffTheRecord()) |
107 return; | 108 return; |
108 | 109 |
109 // Only handle FilePaths for now. | 110 // Only handle mass storage for now. |
110 // TODO(kmadhusu): Handle all device types. http://crbug.com/140353. | 111 // TODO(kmadhusu): Handle all device types. http://crbug.com/140353. |
111 if (device_type != SystemMonitor::TYPE_PATH) | 112 MediaStorageUtil::Type type; |
| 113 MediaStorageUtil::CrackDeviceId(id, &type, NULL); |
| 114 if (type == MediaStorageUtil::USB_MTP) |
112 return; | 115 return; |
| 116 DCHECK(MediaStorageUtil::IsRemovableDevice(id)); |
113 | 117 |
114 // Sanity checks for |device_path|. | 118 // Sanity checks for |device_path|. |
115 const FilePath device_path(location); | 119 const FilePath device_path(location); |
116 if (!device_path.IsAbsolute() || device_path.ReferencesParent()) | 120 if (!device_path.IsAbsolute() || device_path.ReferencesParent()) |
117 return; | 121 return; |
118 | 122 |
119 SystemMonitor::MediaDeviceInfo device_info(id, name, device_type, location); | 123 SystemMonitor::MediaDeviceInfo device_info(id, name, location); |
120 scoped_refptr<DispatchIntentTaskHelper> task = new DispatchIntentTaskHelper( | 124 scoped_refptr<DispatchIntentTaskHelper> task = new DispatchIntentTaskHelper( |
121 AsWeakPtr(), device_info); | 125 AsWeakPtr(), device_info); |
122 WebIntentsRegistryFactory::GetForProfile(browser_->profile())-> | 126 WebIntentsRegistryFactory::GetForProfile(browser_->profile())-> |
123 GetIntentServices( | 127 GetIntentServices( |
124 UTF8ToUTF16(kAction), UTF8ToUTF16(kIntentType), | 128 UTF8ToUTF16(kAction), UTF8ToUTF16(kIntentType), |
125 base::Bind(&DispatchIntentTaskHelper::MayDispatchIntentForService, | 129 base::Bind(&DispatchIntentTaskHelper::MayDispatchIntentForService, |
126 task.get())); | 130 task.get())); |
127 } | 131 } |
128 | 132 |
129 void DeviceAttachedIntentSource::DispatchIntentsForService( | 133 void DeviceAttachedIntentSource::DispatchIntentsForService( |
(...skipping 15 matching lines...) Expand all Loading... |
145 | 149 |
146 delegate_->WebIntentDispatch(NULL /* no WebContents */, | 150 delegate_->WebIntentDispatch(NULL /* no WebContents */, |
147 content::WebIntentsDispatcher::Create(intent)); | 151 content::WebIntentsDispatcher::Create(intent)); |
148 } | 152 } |
149 | 153 |
150 void DeviceAttachedIntentSource::OnMediaDeviceDetached(const std::string& id) { | 154 void DeviceAttachedIntentSource::OnMediaDeviceDetached(const std::string& id) { |
151 DeviceIdToInfoMap::iterator it = device_id_map_.find(id); | 155 DeviceIdToInfoMap::iterator it = device_id_map_.find(id); |
152 if (it == device_id_map_.end()) | 156 if (it == device_id_map_.end()) |
153 return; | 157 return; |
154 | 158 |
155 // TODO(kmadhusu, vandebo): Clean up this code. http://crbug.com/140340. | 159 // TODO(kmadhusu) This should be something like |
156 | 160 // RevokeFileSystemByDevice(std::string) |
157 FilePath path(it->second.location); | 161 FilePath path(it->second.location); |
158 fileapi::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path); | 162 fileapi::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path); |
159 switch (it->second.type) { | 163 |
160 case SystemMonitor::TYPE_MTP: | |
161 #if defined(SUPPORT_MEDIA_FILESYSTEM) | 164 #if defined(SUPPORT_MEDIA_FILESYSTEM) |
162 MediaDeviceMapService::GetInstance()->RemoveMediaDevice( | 165 // TODO(kmadhusu, vandebo): Clean up this code. http://crbug.com/140340. |
163 it->second.location); | 166 MediaStorageUtil::Type type; |
| 167 MediaStorageUtil::CrackDeviceId(it->second.unique_id, &type, NULL); |
| 168 if (type == MediaStorageUtil::USB_MTP) { |
| 169 MediaDeviceMapService::GetInstance()->RemoveMediaDevice( |
| 170 it->second.location); |
| 171 } |
164 #endif | 172 #endif |
165 break; | |
166 case SystemMonitor::TYPE_PATH: | |
167 break; | |
168 } | |
169 device_id_map_.erase(it); | 173 device_id_map_.erase(it); |
170 } | 174 } |
OLD | NEW |