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

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: 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;
kmadhusu 2012/08/17 18:53:35 nit: using chrome::MediaStorageUtil;
vandebo (ex-Chrome) 2012/08/17 22:55:51 We prefer to not use "using" unless it significant
kmadhusu 2012/08/20 17:13:49 Google C++ style guide (http://google-styleguide.g
vandebo (ex-Chrome) 2012/08/20 18:35:14 Done.
112 chrome::MediaStorageUtil::CrackDeviceId(id, &type, NULL);
kmadhusu 2012/08/17 18:53:35 How about adding a DCHECK(type == MediaStorageUtil
groby-ooo-7-16 2012/08/17 21:01:30 If you DCHECK, you should _not_ handle that via if
vandebo (ex-Chrome) 2012/08/17 22:55:51 Added DCHECK(MediaStorageUtil::IsRemovableDevice(i
vandebo (ex-Chrome) 2012/08/17 22:55:51 We don't currently handle MTP, but will do so shor
113 if (type == chrome::MediaStorageUtil::USB_MTP)
112 return; 114 return;
113 115
114 // Sanity checks for |device_path|. 116 // Sanity checks for |device_path|.
115 const FilePath device_path(location); 117 const FilePath device_path(location);
116 if (!device_path.IsAbsolute() || device_path.ReferencesParent()) 118 if (!device_path.IsAbsolute() || device_path.ReferencesParent())
117 return; 119 return;
118 120
119 SystemMonitor::MediaDeviceInfo device_info(id, name, device_type, location); 121 SystemMonitor::MediaDeviceInfo device_info(id, name, location);
120 scoped_refptr<DispatchIntentTaskHelper> task = new DispatchIntentTaskHelper( 122 scoped_refptr<DispatchIntentTaskHelper> task = new DispatchIntentTaskHelper(
121 AsWeakPtr(), device_info); 123 AsWeakPtr(), device_info);
122 WebIntentsRegistryFactory::GetForProfile(browser_->profile())-> 124 WebIntentsRegistryFactory::GetForProfile(browser_->profile())->
123 GetIntentServices( 125 GetIntentServices(
124 UTF8ToUTF16(kAction), UTF8ToUTF16(kIntentType), 126 UTF8ToUTF16(kAction), UTF8ToUTF16(kIntentType),
125 base::Bind(&DispatchIntentTaskHelper::MayDispatchIntentForService, 127 base::Bind(&DispatchIntentTaskHelper::MayDispatchIntentForService,
126 task.get())); 128 task.get()));
127 } 129 }
128 130
129 void DeviceAttachedIntentSource::DispatchIntentsForService( 131 void DeviceAttachedIntentSource::DispatchIntentsForService(
(...skipping 15 matching lines...) Expand all
145 147
146 delegate_->WebIntentDispatch(NULL /* no WebContents */, 148 delegate_->WebIntentDispatch(NULL /* no WebContents */,
147 content::WebIntentsDispatcher::Create(intent)); 149 content::WebIntentsDispatcher::Create(intent));
148 } 150 }
149 151
150 void DeviceAttachedIntentSource::OnMediaDeviceDetached(const std::string& id) { 152 void DeviceAttachedIntentSource::OnMediaDeviceDetached(const std::string& id) {
151 DeviceIdToInfoMap::iterator it = device_id_map_.find(id); 153 DeviceIdToInfoMap::iterator it = device_id_map_.find(id);
152 if (it == device_id_map_.end()) 154 if (it == device_id_map_.end())
153 return; 155 return;
154 156
155 // TODO(kmadhusu, vandebo): Clean up this code. http://crbug.com/140340. 157 // TODO(kmadhusu) This should be something like
156 158 // RevokeFileSystemByDevice(std::string)
157 FilePath path(it->second.location); 159 FilePath path(it->second.location);
158 fileapi::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path); 160 fileapi::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path);
159 switch (it->second.type) { 161
160 case SystemMonitor::TYPE_MTP:
161 #if defined(SUPPORT_MEDIA_FILESYSTEM) 162 #if defined(SUPPORT_MEDIA_FILESYSTEM)
162 MediaDeviceMapService::GetInstance()->RemoveMediaDevice( 163 // TODO(kmadhusu, vandebo): Clean up this code. http://crbug.com/140340.
163 it->second.location); 164 chrome::MediaStorageUtil::Type type;
165 chrome::MediaStorageUtil::CrackDeviceId(it->second.unique_id, &type, NULL);
166 if (type == chrome::MediaStorageUtil::USB_MTP) {
167 MediaDeviceMapService::GetInstance()->RemoveMediaDevice(
168 it->second.location);
169 }
164 #endif 170 #endif
165 break;
166 case SystemMonitor::TYPE_PATH:
167 break;
168 }
169 device_id_map_.erase(it); 171 device_id_map_.erase(it);
170 } 172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698