Chromium Code Reviews| 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 <vector> | 7 #include <vector> |
| 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/media_gallery/media_storage_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "content/public/browser/web_intents_dispatcher.h" | 20 #include "content/public/browser/web_intents_dispatcher.h" |
| 21 #include "content/public/browser/web_contents_delegate.h" | 21 #include "content/public/browser/web_contents_delegate.h" |
| 22 #include "webkit/fileapi/file_system_types.h" | 22 #include "webkit/fileapi/file_system_types.h" |
| 23 #include "webkit/fileapi/isolated_context.h" | 23 #include "webkit/fileapi/isolated_context.h" |
| 24 #include "webkit/glue/web_intent_data.h" | 24 #include "webkit/glue/web_intent_data.h" |
| 25 #include "webkit/glue/web_intent_service_data.h" | 25 #include "webkit/glue/web_intent_service_data.h" |
| 26 #include "webkit/fileapi/media/media_file_system_config.h" | |
| 27 | |
| 28 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
| 29 #include "webkit/fileapi/media/media_device_map_service.h" | |
| 30 | |
| 31 using fileapi::MediaDeviceMapService; | |
| 32 #endif | |
| 33 | 26 |
| 34 using base::SystemMonitor; | 27 using base::SystemMonitor; |
| 35 using chrome::MediaStorageUtil; | 28 using chrome::MediaStorageUtil; |
| 36 using content::WebContentsDelegate; | 29 using content::WebContentsDelegate; |
| 37 using webkit_glue::WebIntentServiceData; | 30 using webkit_glue::WebIntentServiceData; |
| 38 | 31 |
| 39 namespace { | 32 namespace { |
| 40 | 33 |
| 41 // Specifies device attached web intent kAction. | 34 // Specifies device attached web intent kAction. |
| 42 const char kAction[] = "chrome-extension://attach"; | 35 const char kAction[] = "chrome-extension://attach"; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 } | 124 } |
| 132 | 125 |
| 133 void DeviceAttachedIntentSource::DispatchIntentsForService( | 126 void DeviceAttachedIntentSource::DispatchIntentsForService( |
| 134 const base::SystemMonitor::RemovableStorageInfo& device_info) { | 127 const base::SystemMonitor::RemovableStorageInfo& device_info) { |
| 135 // Store the media device info locally. | 128 // Store the media device info locally. |
| 136 device_id_map_.insert(std::make_pair(device_info.device_id, device_info)); | 129 device_id_map_.insert(std::make_pair(device_info.device_id, device_info)); |
| 137 | 130 |
| 138 std::string device_name(UTF16ToUTF8(device_info.name)); | 131 std::string device_name(UTF16ToUTF8(device_info.name)); |
| 139 const FilePath device_path(device_info.location); | 132 const FilePath device_path(device_info.location); |
| 140 | 133 |
| 141 // TODO(kinuko, kmadhusu): Use a different file system type for MTP. | 134 // TODO(kinuko, kmadhusu): Use a different file system type for MTP. |
|
vandebo (ex-Chrome)
2012/08/27 20:30:52
Add a TODO here to get the file system through the
kmadhusu
2012/08/27 20:44:57
Done.
| |
| 142 const std::string fs_id = fileapi::IsolatedContext::GetInstance()-> | 135 const std::string fs_id = fileapi::IsolatedContext::GetInstance()-> |
| 143 RegisterFileSystemForPath(fileapi::kFileSystemTypeNativeMedia, | 136 RegisterFileSystemForPath(fileapi::kFileSystemTypeNativeMedia, |
| 144 device_path, &device_name); | 137 device_path, &device_name); |
| 145 | 138 |
| 146 DCHECK(!fs_id.empty()); | 139 DCHECK(!fs_id.empty()); |
| 147 webkit_glue::WebIntentData intent( | 140 webkit_glue::WebIntentData intent( |
| 148 UTF8ToUTF16(kAction), UTF8ToUTF16(kIntentType), device_name, fs_id); | 141 UTF8ToUTF16(kAction), UTF8ToUTF16(kIntentType), device_name, fs_id); |
| 149 | 142 |
| 150 delegate_->WebIntentDispatch(NULL /* no WebContents */, | 143 delegate_->WebIntentDispatch(NULL /* no WebContents */, |
| 151 content::WebIntentsDispatcher::Create(intent)); | 144 content::WebIntentsDispatcher::Create(intent)); |
| 152 } | 145 } |
| 153 | 146 |
| 154 void DeviceAttachedIntentSource::OnRemovableStorageDetached( | 147 void DeviceAttachedIntentSource::OnRemovableStorageDetached( |
| 155 const std::string& id) { | 148 const std::string& id) { |
| 156 DeviceIdToInfoMap::iterator it = device_id_map_.find(id); | 149 DeviceIdToInfoMap::iterator it = device_id_map_.find(id); |
| 157 if (it == device_id_map_.end()) | 150 if (it == device_id_map_.end()) |
| 158 return; | 151 return; |
| 159 | 152 |
| 160 // TODO(kmadhusu) This should be something like | |
| 161 // RevokeFileSystemByDevice(std::string) | |
| 162 FilePath path(it->second.location); | 153 FilePath path(it->second.location); |
| 163 fileapi::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path); | 154 fileapi::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path); |
| 164 | |
| 165 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
| 166 // TODO(kmadhusu, vandebo): Clean up this code. http://crbug.com/140340. | |
| 167 MediaStorageUtil::Type type; | |
| 168 MediaStorageUtil::CrackDeviceId(it->second.device_id, &type, NULL); | |
| 169 if (type == MediaStorageUtil::USB_MTP) { | |
| 170 MediaDeviceMapService::GetInstance()->RemoveMediaDevice( | |
| 171 it->second.location); | |
| 172 } | |
| 173 #endif | |
| 174 device_id_map_.erase(it); | 155 device_id_map_.erase(it); |
| 175 } | 156 } |
| OLD | NEW |