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

Side by Side Diff: chrome/browser/intents/device_attached_intent_source.cc

Issue 10829384: SystemMonitor: Pull device type into the device id (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: typo Created 8 years, 4 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 #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"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 91
91 DeviceAttachedIntentSource::~DeviceAttachedIntentSource() { 92 DeviceAttachedIntentSource::~DeviceAttachedIntentSource() {
92 SystemMonitor* sys_monitor = SystemMonitor::Get(); 93 SystemMonitor* sys_monitor = SystemMonitor::Get();
93 if (sys_monitor) 94 if (sys_monitor)
94 sys_monitor->RemoveDevicesChangedObserver(this); 95 sys_monitor->RemoveDevicesChangedObserver(this);
95 } 96 }
96 97
97 void DeviceAttachedIntentSource::OnMediaDeviceAttached( 98 void DeviceAttachedIntentSource::OnMediaDeviceAttached(
98 const std::string& id, 99 const std::string& id,
99 const string16& name, 100 const string16& name,
100 base::SystemMonitor::MediaDeviceType device_type,
101 const FilePath::StringType& location) { 101 const FilePath::StringType& location) {
102 if (!browser_->window()->IsActive()) 102 if (!browser_->window()->IsActive())
103 return; 103 return;
104 104
105 // TODO(kmadhusu): Dispatch intents on incognito window. 105 // TODO(kmadhusu): Dispatch intents on incognito window.
106 if (browser_->profile()->IsOffTheRecord()) 106 if (browser_->profile()->IsOffTheRecord())
107 return; 107 return;
108 108
109 // Only handle FilePaths for now. 109 // Only handle mass storage for now.
110 // TODO(kmadhusu): Handle all device types. http://crbug.com/140353. 110 // TODO(kmadhusu): Handle all device types. http://crbug.com/140353.
111 if (device_type != SystemMonitor::TYPE_PATH) 111 chrome::MediaStorageUtil::Type type;
112 chrome::MediaStorageUtil::CrackDeviceId(id, &type, NULL);
113 if (type == chrome::MediaStorageUtil::USB_MTP)
112 return; 114 return;
115 DCHECK(chrome::MediaStorageUtil::IsRemovableDevice(id));
113 116
114 // Sanity checks for |device_path|. 117 // Sanity checks for |device_path|.
115 const FilePath device_path(location); 118 const FilePath device_path(location);
116 if (!device_path.IsAbsolute() || device_path.ReferencesParent()) 119 if (!device_path.IsAbsolute() || device_path.ReferencesParent())
117 return; 120 return;
118 121
119 SystemMonitor::MediaDeviceInfo device_info(id, name, device_type, location); 122 SystemMonitor::MediaDeviceInfo device_info(id, name, location);
120 scoped_refptr<DispatchIntentTaskHelper> task = new DispatchIntentTaskHelper( 123 scoped_refptr<DispatchIntentTaskHelper> task = new DispatchIntentTaskHelper(
121 AsWeakPtr(), device_info); 124 AsWeakPtr(), device_info);
122 WebIntentsRegistryFactory::GetForProfile(browser_->profile())-> 125 WebIntentsRegistryFactory::GetForProfile(browser_->profile())->
123 GetIntentServices( 126 GetIntentServices(
124 UTF8ToUTF16(kAction), UTF8ToUTF16(kIntentType), 127 UTF8ToUTF16(kAction), UTF8ToUTF16(kIntentType),
125 base::Bind(&DispatchIntentTaskHelper::MayDispatchIntentForService, 128 base::Bind(&DispatchIntentTaskHelper::MayDispatchIntentForService,
126 task.get())); 129 task.get()));
127 } 130 }
128 131
129 void DeviceAttachedIntentSource::DispatchIntentsForService( 132 void DeviceAttachedIntentSource::DispatchIntentsForService(
(...skipping 15 matching lines...) Expand all
145 148
146 delegate_->WebIntentDispatch(NULL /* no WebContents */, 149 delegate_->WebIntentDispatch(NULL /* no WebContents */,
147 content::WebIntentsDispatcher::Create(intent)); 150 content::WebIntentsDispatcher::Create(intent));
148 } 151 }
149 152
150 void DeviceAttachedIntentSource::OnMediaDeviceDetached(const std::string& id) { 153 void DeviceAttachedIntentSource::OnMediaDeviceDetached(const std::string& id) {
151 DeviceIdToInfoMap::iterator it = device_id_map_.find(id); 154 DeviceIdToInfoMap::iterator it = device_id_map_.find(id);
152 if (it == device_id_map_.end()) 155 if (it == device_id_map_.end())
153 return; 156 return;
154 157
155 // TODO(kmadhusu, vandebo): Clean up this code. http://crbug.com/140340. 158 // TODO(kmadhusu) This should be something like
156 159 // RevokeFileSystemByDevice(std::string)
157 FilePath path(it->second.location); 160 FilePath path(it->second.location);
158 fileapi::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path); 161 fileapi::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path);
159 switch (it->second.type) { 162
160 case SystemMonitor::TYPE_MTP:
161 #if defined(SUPPORT_MEDIA_FILESYSTEM) 163 #if defined(SUPPORT_MEDIA_FILESYSTEM)
162 MediaDeviceMapService::GetInstance()->RemoveMediaDevice( 164 // TODO(kmadhusu, vandebo): Clean up this code. http://crbug.com/140340.
163 it->second.location); 165 chrome::MediaStorageUtil::Type type;
166 chrome::MediaStorageUtil::CrackDeviceId(it->second.unique_id, &type, NULL);
167 if (type == chrome::MediaStorageUtil::USB_MTP) {
168 MediaDeviceMapService::GetInstance()->RemoveMediaDevice(
169 it->second.location);
170 }
164 #endif 171 #endif
165 break;
166 case SystemMonitor::TYPE_PATH:
167 break;
168 }
169 device_id_map_.erase(it); 172 device_id_map_.erase(it);
170 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698