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

Side by Side Diff: chrome/browser/media_gallery/media_file_system_registry.cc

Issue 11297002: [Media Gallery] Added code to support mtp device media file system on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comment and disabled MediaFileSystemRegistryTest.GalleryNameMTP Created 7 years, 11 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 // MediaFileSystemRegistry implementation. 5 // MediaFileSystemRegistry implementation.
6 6
7 #include "chrome/browser/media_gallery/media_file_system_registry.h" 7 #include "chrome/browser/media_gallery/media_file_system_registry.h"
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h"
14 #include "base/file_path.h" 15 #include "base/file_path.h"
15 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
16 #include "base/path_service.h" 17 #include "base/path_service.h"
17 #include "base/stl_util.h" 18 #include "base/stl_util.h"
18 #include "base/string_util.h" 19 #include "base/string_util.h"
19 #include "base/system_monitor/system_monitor.h" 20 #include "base/system_monitor/system_monitor.h"
20 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "chrome/browser/extensions/extension_service.h" 23 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/extension_system.h" 24 #include "chrome/browser/extensions/extension_system.h"
24 #include "chrome/browser/media_gallery/media_file_system_context.h" 25 #include "chrome/browser/media_gallery/media_file_system_context.h"
25 #include "chrome/browser/media_gallery/media_galleries_preferences.h" 26 #include "chrome/browser/media_gallery/media_galleries_preferences.h"
26 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h" 27 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h"
27 #include "chrome/browser/media_gallery/scoped_mtp_device_map_entry.h" 28 #include "chrome/browser/media_gallery/scoped_mtp_device_map_entry.h"
28 #include "chrome/browser/prefs/pref_service.h" 29 #include "chrome/browser/prefs/pref_service.h"
29 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/system_monitor/media_storage_util.h" 31 #include "chrome/browser/system_monitor/media_storage_util.h"
31 #include "chrome/common/chrome_notification_types.h" 32 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/chrome_paths.h" 33 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/extensions/extension_constants.h" 35 #include "chrome/common/extensions/extension_constants.h"
34 #include "chrome/common/extensions/extension_set.h" 36 #include "chrome/common/extensions/extension_set.h"
35 #include "chrome/common/extensions/extension.h" 37 #include "chrome/common/extensions/extension.h"
36 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
37 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/notification_details.h" 40 #include "content/public/browser/notification_details.h"
39 #include "content/public/browser/notification_observer.h" 41 #include "content/public/browser/notification_observer.h"
40 #include "content/public/browser/notification_registrar.h" 42 #include "content/public/browser/notification_registrar.h"
41 #include "content/public/browser/notification_source.h" 43 #include "content/public/browser/notification_source.h"
42 #include "content/public/browser/notification_types.h" 44 #include "content/public/browser/notification_types.h"
(...skipping 12 matching lines...) Expand all
55 57
56 namespace chrome { 58 namespace chrome {
57 59
58 namespace { 60 namespace {
59 61
60 struct InvalidatedGalleriesInfo { 62 struct InvalidatedGalleriesInfo {
61 std::set<ExtensionGalleriesHost*> extension_hosts; 63 std::set<ExtensionGalleriesHost*> extension_hosts;
62 std::set<MediaGalleryPrefId> pref_ids; 64 std::set<MediaGalleryPrefId> pref_ids;
63 }; 65 };
64 66
67 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
68 // Returns true if the media transfer protocol (MTP) device operations are
69 // allowed for this platform.
70 // TODO(kmadhusu): Remove this function after fixing crbug.com/154835.
71 bool IsMTPDeviceMediaOperationsEnabled() {
72 #if defined(OS_WIN)
73 return CommandLine::ForCurrentProcess()->HasSwitch(
74 switches::kEnableMediaTransferProtocolDeviceOperations);
75 #endif
76 return true;
77 }
78 #endif
79
65 } // namespace 80 } // namespace
66 81
67 MediaFileSystemInfo::MediaFileSystemInfo(const std::string& fs_name, 82 MediaFileSystemInfo::MediaFileSystemInfo(const std::string& fs_name,
68 const FilePath& fs_path, 83 const FilePath& fs_path,
69 const std::string& filesystem_id) 84 const std::string& filesystem_id)
70 : name(fs_name), 85 : name(fs_name),
71 path(fs_path), 86 path(fs_path),
72 fsid(filesystem_id) { 87 fsid(filesystem_id) {
73 } 88 }
74 89
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // Revoke the file system for |id| if this extension has created one for |id|. 150 // Revoke the file system for |id| if this extension has created one for |id|.
136 void RevokeGalleryByPrefId(MediaGalleryPrefId id) { 151 void RevokeGalleryByPrefId(MediaGalleryPrefId id) {
137 PrefIdFsInfoMap::iterator gallery = pref_id_map_.find(id); 152 PrefIdFsInfoMap::iterator gallery = pref_id_map_.find(id);
138 if (gallery == pref_id_map_.end()) 153 if (gallery == pref_id_map_.end())
139 return; 154 return;
140 155
141 file_system_context_->RevokeFileSystem(gallery->second.fsid); 156 file_system_context_->RevokeFileSystem(gallery->second.fsid);
142 pref_id_map_.erase(gallery); 157 pref_id_map_.erase(gallery);
143 158
144 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 159 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
145 MediaDeviceEntryReferencesMap::iterator mtp_device_host = 160 if (IsMTPDeviceMediaOperationsEnabled()) {
146 media_device_map_references_.find(id); 161 MediaDeviceEntryReferencesMap::iterator mtp_device_host =
147 if (mtp_device_host != media_device_map_references_.end()) 162 media_device_map_references_.find(id);
148 media_device_map_references_.erase(mtp_device_host); 163 if (mtp_device_host != media_device_map_references_.end())
164 media_device_map_references_.erase(mtp_device_host);
165 }
149 #endif 166 #endif
150 167
151 if (pref_id_map_.empty()) { 168 if (pref_id_map_.empty()) {
152 rph_refs_.clear(); 169 rph_refs_.clear();
153 CleanUp(); 170 CleanUp();
154 } 171 }
155 } 172 }
156 173
157 // Indicate that the passed |rvh| will reference the file system ids created 174 // Indicate that the passed |rvh| will reference the file system ids created
158 // by this class. It is safe to call this multiple times with the same RVH. 175 // by this class. It is safe to call this multiple times with the same RVH.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 FilePath path = gallery_info.AbsolutePath(); 275 FilePath path = gallery_info.AbsolutePath();
259 if (!MediaStorageUtil::CanCreateFileSystem(device_id, path)) 276 if (!MediaStorageUtil::CanCreateFileSystem(device_id, path))
260 continue; 277 continue;
261 278
262 std::string fsid; 279 std::string fsid;
263 if (MediaStorageUtil::IsMassStorageDevice(device_id)) { 280 if (MediaStorageUtil::IsMassStorageDevice(device_id)) {
264 fsid = file_system_context_->RegisterFileSystemForMassStorage( 281 fsid = file_system_context_->RegisterFileSystemForMassStorage(
265 device_id, path); 282 device_id, path);
266 } else { 283 } else {
267 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 284 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
285 if (!IsMTPDeviceMediaOperationsEnabled())
286 continue;
287
268 scoped_refptr<ScopedMTPDeviceMapEntry> mtp_device_host; 288 scoped_refptr<ScopedMTPDeviceMapEntry> mtp_device_host;
269 fsid = file_system_context_->RegisterFileSystemForMTPDevice( 289 fsid = file_system_context_->RegisterFileSystemForMTPDevice(
270 device_id, path, &mtp_device_host); 290 device_id, path, &mtp_device_host);
271 DCHECK(mtp_device_host.get()); 291 DCHECK(mtp_device_host.get());
272 media_device_map_references_[pref_id] = mtp_device_host; 292 media_device_map_references_[pref_id] = mtp_device_host;
273 #else 293 #else
274 NOTIMPLEMENTED(); 294 NOTIMPLEMENTED();
275 continue; 295 continue;
276 #endif 296 #endif
277 } 297 }
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 759
740 PrefChangeRegistrarMap::iterator pref_it = 760 PrefChangeRegistrarMap::iterator pref_it =
741 pref_change_registrar_map_.find(profile); 761 pref_change_registrar_map_.find(profile);
742 DCHECK(pref_it != pref_change_registrar_map_.end()); 762 DCHECK(pref_it != pref_change_registrar_map_.end());
743 delete pref_it->second; 763 delete pref_it->second;
744 pref_change_registrar_map_.erase(pref_it); 764 pref_change_registrar_map_.erase(pref_it);
745 } 765 }
746 } 766 }
747 767
748 } // namespace chrome 768 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698