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

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

Issue 10781014: Isolated FS for media devices. (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/file_path.h" 9 #include "base/file_path.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
13 #include "content/public/browser/web_intents_dispatcher.h" 13 #include "content/public/browser/web_intents_dispatcher.h"
14 #include "content/public/browser/web_contents_delegate.h" 14 #include "content/public/browser/web_contents_delegate.h"
15 #include "webkit/fileapi/file_system_types.h" 15 #include "webkit/fileapi/file_system_types.h"
16 #include "webkit/fileapi/isolated_context.h" 16 #include "webkit/fileapi/isolated_context.h"
17 #include "webkit/glue/web_intent_data.h" 17 #include "webkit/glue/web_intent_data.h"
18 #include "webkit/fileapi/media/media_file_system_config.h"
19
20 #if defined(SUPPORT_MEDIA_FILESYSTEM)
21 #include "webkit/fileapi/media/media_device_map_service.h"
22
23 using fileapi::MediaDeviceMapService;
24 #endif
18 25
19 using base::SystemMonitor; 26 using base::SystemMonitor;
20 using content::WebContentsDelegate; 27 using content::WebContentsDelegate;
21 28
22 DeviceAttachedIntentSource::DeviceAttachedIntentSource( 29 DeviceAttachedIntentSource::DeviceAttachedIntentSource(
23 Browser* browser, WebContentsDelegate* delegate) 30 Browser* browser, WebContentsDelegate* delegate)
24 : browser_(browser), delegate_(delegate) { 31 : browser_(browser), delegate_(delegate) {
25 SystemMonitor* sys_monitor = SystemMonitor::Get(); 32 SystemMonitor* sys_monitor = SystemMonitor::Get();
26 if (sys_monitor) 33 if (sys_monitor)
27 sys_monitor->AddDevicesChangedObserver(this); 34 sys_monitor->AddDevicesChangedObserver(this);
28 } 35 }
29 36
30 DeviceAttachedIntentSource::~DeviceAttachedIntentSource() { 37 DeviceAttachedIntentSource::~DeviceAttachedIntentSource() {
31 SystemMonitor* sys_monitor = SystemMonitor::Get(); 38 SystemMonitor* sys_monitor = SystemMonitor::Get();
32 if (sys_monitor) 39 if (sys_monitor)
33 sys_monitor->RemoveDevicesChangedObserver(this); 40 sys_monitor->RemoveDevicesChangedObserver(this);
34 } 41 }
35 42
36 void DeviceAttachedIntentSource::OnMediaDeviceAttached( 43 void DeviceAttachedIntentSource::OnMediaDeviceAttached(
37 const std::string& id, 44 const std::string& id,
38 const string16& name, 45 const string16& name,
39 base::SystemMonitor::MediaDeviceType type, 46 base::SystemMonitor::MediaDeviceType type,
40 const FilePath::StringType& location) { 47 const FilePath::StringType& location) {
41 if (!browser_->window()->IsActive()) 48 if (!browser_->window()->IsActive())
42 return; 49 return;
43 50
44 // Only handle FilePaths for now. 51 // Only handle FilePaths for now.
52 // TODO(kmadhusu): Handle all device types. http://crbug.com/140353.
45 if (type != SystemMonitor::TYPE_PATH) 53 if (type != SystemMonitor::TYPE_PATH)
46 return; 54 return;
47 55
48 // Sanity checks for |device_path|. 56 // Sanity checks for |device_path|.
49 const FilePath device_path(location); 57 const FilePath device_path(location);
50 if (!device_path.IsAbsolute() || device_path.ReferencesParent()) 58 if (!device_path.IsAbsolute() || device_path.ReferencesParent())
51 return; 59 return;
52 60
61 // Store the media device info locally.
62 SystemMonitor::MediaDeviceInfo device_info(id, name, type, location);
63 device_id_map_.insert(std::make_pair(id, device_info));
64
53 std::string device_name; 65 std::string device_name;
54 66
55 // Register device path as an isolated file system. 67 // Register device path as an isolated file system.
56 // TODO(kinuko, kmadhusu): Use a different file system type for MTP. 68 // TODO(kinuko, kmadhusu): Use a different file system type for MTP.
57 const std::string filesystem_id = 69 const std::string filesystem_id =
58 fileapi::IsolatedContext::GetInstance()->RegisterFileSystemForPath( 70 fileapi::IsolatedContext::GetInstance()->RegisterFileSystemForPath(
59 fileapi::kFileSystemTypeNativeMedia, device_path, &device_name); 71 fileapi::kFileSystemTypeNativeMedia, device_path, &device_name);
60 72
61 CHECK(!filesystem_id.empty()); 73 CHECK(!filesystem_id.empty());
62 webkit_glue::WebIntentData intent( 74 webkit_glue::WebIntentData intent(
63 ASCIIToUTF16("chrome-extension://attach"), 75 ASCIIToUTF16("chrome-extension://attach"),
64 ASCIIToUTF16("chrome-extension://filesystem"), 76 ASCIIToUTF16("chrome-extension://filesystem"),
65 device_name, 77 device_name,
66 filesystem_id); 78 filesystem_id);
67 79
68 delegate_->WebIntentDispatch(NULL /* no WebContents */, 80 delegate_->WebIntentDispatch(NULL /* no WebContents */,
69 content::WebIntentsDispatcher::Create(intent)); 81 content::WebIntentsDispatcher::Create(intent));
70 } 82 }
83
84 void DeviceAttachedIntentSource::OnMediaDeviceDetached(const std::string& id) {
85 DeviceIdToInfoMap::iterator it = device_id_map_.find(id);
86 if (it == device_id_map_.end())
87 return;
88
89 // TODO(kmadhusu, vandebo): Clean up this code. http://crbug.com/140340.
90
91 FilePath path(it->second.location);
92 fileapi::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path);
93 switch (it->second.type) {
94 case SystemMonitor::TYPE_MTP:
95 #if defined(SUPPORT_MEDIA_FILESYSTEM)
96 MediaDeviceMapService::GetInstance()->RemoveMediaDevice(
97 it->second.location);
98 #endif
99 break;
100 case SystemMonitor::TYPE_PATH:
101 break;
102 }
103 device_id_map_.erase(it);
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698