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

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

Issue 11358243: Redesigned and refactored ScopedMTPDeviceMapEntry, MTPDeviceMapService & MTPDeviceDelegate classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 8 years, 1 month 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>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 const FilePath& fs_path, 123 const FilePath& fs_path,
124 const std::string& filesystem_id) 124 const std::string& filesystem_id)
125 : name(fs_name), 125 : name(fs_name),
126 path(fs_path), 126 path(fs_path),
127 fsid(filesystem_id) { 127 fsid(filesystem_id) {
128 } 128 }
129 129
130 MediaFileSystemInfo::MediaFileSystemInfo() {} 130 MediaFileSystemInfo::MediaFileSystemInfo() {}
131 131
132 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 132 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
133
134 ScopedMTPDeviceMapEntry::ScopedMTPDeviceMapEntry( 133 ScopedMTPDeviceMapEntry::ScopedMTPDeviceMapEntry(
135 const FilePath::StringType& device_location, 134 const FilePath::StringType& device_location)
136 const base::Closure& no_references_callback) 135 : device_location_(device_location) {
137 : device_location_(device_location),
138 delegate_(new MTPDeviceDelegateImpl(device_location)),
139 no_references_callback_(no_references_callback) {
140 BrowserThread::PostTask( 136 BrowserThread::PostTask(
141 BrowserThread::IO, FROM_HERE, 137 BrowserThread::IO, FROM_HERE,
142 Bind(&MTPDeviceMapService::AddDelegate, 138 Bind(&MTPDeviceMapService::AddDelegate,
143 base::Unretained(MTPDeviceMapService::GetInstance()), 139 base::Unretained(MTPDeviceMapService::GetInstance()),
144 device_location_, make_scoped_refptr(delegate_))); 140 device_location_,
141 new MTPDeviceDelegateImpl(device_location)));
145 } 142 }
146 143
147 ScopedMTPDeviceMapEntry::~ScopedMTPDeviceMapEntry() { 144 ScopedMTPDeviceMapEntry::~ScopedMTPDeviceMapEntry() {
148 BrowserThread::PostTask( 145 BrowserThread::PostTask(
149 BrowserThread::IO, FROM_HERE, 146 BrowserThread::IO, FROM_HERE,
150 Bind(&MTPDeviceMapService::RemoveDelegate, 147 Bind(&MTPDeviceMapService::RemoveDelegate,
151 base::Unretained(MTPDeviceMapService::GetInstance()), 148 base::Unretained(MTPDeviceMapService::GetInstance()),
152 device_location_)); 149 device_location_));
153 no_references_callback_.Run();
154 } 150 }
155 151 #endif
156 #endif // defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
157 152
158 // The main owner of this class is 153 // The main owner of this class is
159 // |MediaFileSystemRegistry::extension_hosts_map_|, but a callback may 154 // |MediaFileSystemRegistry::extension_hosts_map_|, but a callback may
160 // temporarily hold a reference. 155 // temporarily hold a reference.
161 class ExtensionGalleriesHost 156 class ExtensionGalleriesHost
162 : public base::RefCountedThreadSafe<ExtensionGalleriesHost>, 157 : public base::RefCountedThreadSafe<ExtensionGalleriesHost>,
163 public content::NotificationObserver { 158 public content::NotificationObserver {
164 public: 159 public:
165 // |no_references_callback| is called when the last RenderViewHost reference 160 // |no_references_callback| is called when the last RenderViewHost reference
166 // goes away. RenderViewHost references are added through ReferenceFromRVH(). 161 // goes away. RenderViewHost references are added through ReferenceFromRVH().
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // Revoke the file system for |id| if this extension has created one for |id|. 211 // Revoke the file system for |id| if this extension has created one for |id|.
217 void RevokeGalleryByPrefId(MediaGalleryPrefId id) { 212 void RevokeGalleryByPrefId(MediaGalleryPrefId id) {
218 PrefIdFsInfoMap::iterator gallery = pref_id_map_.find(id); 213 PrefIdFsInfoMap::iterator gallery = pref_id_map_.find(id);
219 if (gallery == pref_id_map_.end()) 214 if (gallery == pref_id_map_.end())
220 return; 215 return;
221 216
222 file_system_context_->RevokeFileSystem(gallery->second.fsid); 217 file_system_context_->RevokeFileSystem(gallery->second.fsid);
223 pref_id_map_.erase(gallery); 218 pref_id_map_.erase(gallery);
224 219
225 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 220 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
226 MediaDeviceEntryReferencesMap::iterator mtp_device_host = 221 for (MTPDeviceGalleryReferencesMap::iterator it =
227 media_device_map_references_.find(id); 222 mtp_device_gallery_references_.begin();
228 if (mtp_device_host != media_device_map_references_.end()) 223 it != mtp_device_gallery_references_.end(); ++it) {
229 media_device_map_references_.erase(mtp_device_host); 224 MediaGalleryPrefIdSet::iterator found = it->second.find(id);
225 if (found == it->second.end())
226 continue;
227 it->second.erase(id);
228 if (it->second.empty()) {
229 file_system_context_->RemoveMTPDeviceReferenceForHost(it->first, this);
230 mtp_device_gallery_references_.erase(it);
231 }
232 break;
233 }
230 #endif 234 #endif
231 235
232 if (pref_id_map_.empty()) { 236 if (pref_id_map_.empty()) {
233 rph_refs_.clear(); 237 rph_refs_.clear();
234 CleanUp(); 238 CleanUp();
235 } 239 }
236 } 240 }
237 241
238 // Indicate that the passed |rvh| will reference the file system ids created 242 // Indicate that the passed |rvh| will reference the file system ids created
239 // by this class. It is safe to call this multiple times with the same RVH. 243 // by this class. It is safe to call this multiple times with the same RVH.
(...skipping 15 matching lines...) Expand all
255 if (rph_refs_[rph].size() == 1) { 259 if (rph_refs_[rph].size() == 1) {
256 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 260 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
257 content::Source<RenderProcessHost>(rph)); 261 content::Source<RenderProcessHost>(rph));
258 } 262 }
259 } 263 }
260 264
261 private: 265 private:
262 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> 266 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo>
263 PrefIdFsInfoMap; 267 PrefIdFsInfoMap;
264 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 268 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
265 typedef std::map<MediaGalleryPrefId, 269 typedef std::map<const FilePath::StringType, MediaGalleryPrefIdSet>
266 scoped_refptr<ScopedMTPDeviceMapEntry> > 270 MTPDeviceGalleryReferencesMap;
267 MediaDeviceEntryReferencesMap;
268 #endif 271 #endif
269 typedef std::map<const RenderProcessHost*, std::set<const WebContents*> > 272 typedef std::map<const RenderProcessHost*, std::set<const WebContents*> >
270 RenderProcessHostRefCount; 273 RenderProcessHostRefCount;
271 274
272 // Private destructor and friend declaration for ref counted implementation. 275 // Private destructor and friend declaration for ref counted implementation.
273 friend class base::RefCountedThreadSafe<ExtensionGalleriesHost>; 276 friend class base::RefCountedThreadSafe<ExtensionGalleriesHost>;
274 277
275 virtual ~ExtensionGalleriesHost() { 278 virtual ~ExtensionGalleriesHost() {
276 DCHECK(rph_refs_.empty()); 279 DCHECK(rph_refs_.empty());
277 DCHECK(pref_id_map_.empty()); 280 DCHECK(pref_id_map_.empty());
278 281
279 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 282 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
280 DCHECK(media_device_map_references_.empty()); 283 DCHECK(mtp_device_gallery_references_.empty());
281 #endif 284 #endif
282 } 285 }
283 286
284 // NotificationObserver implementation. 287 // NotificationObserver implementation.
285 virtual void Observe(int type, 288 virtual void Observe(int type,
286 const content::NotificationSource& source, 289 const content::NotificationSource& source,
287 const content::NotificationDetails& details) OVERRIDE { 290 const content::NotificationDetails& details) OVERRIDE {
288 switch (type) { 291 switch (type) {
289 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { 292 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
290 OnRendererProcessTerminated( 293 OnRendererProcessTerminated(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 FilePath path = gallery_info.AbsolutePath(); 342 FilePath path = gallery_info.AbsolutePath();
340 if (!path.IsAbsolute()) 343 if (!path.IsAbsolute())
341 continue; 344 continue;
342 345
343 std::string fsid; 346 std::string fsid;
344 if (MediaStorageUtil::IsMassStorageDevice(device_id)) { 347 if (MediaStorageUtil::IsMassStorageDevice(device_id)) {
345 fsid = file_system_context_->RegisterFileSystemForMassStorage( 348 fsid = file_system_context_->RegisterFileSystemForMassStorage(
346 device_id, path); 349 device_id, path);
347 } else { 350 } else {
348 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 351 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
349 scoped_refptr<ScopedMTPDeviceMapEntry> mtp_device_host;
350 fsid = file_system_context_->RegisterFileSystemForMTPDevice( 352 fsid = file_system_context_->RegisterFileSystemForMTPDevice(
351 device_id, path, &mtp_device_host); 353 device_id, path, this);
352 DCHECK(mtp_device_host.get()); 354 mtp_device_gallery_references_[path.value()].insert(pref_id);
353 media_device_map_references_[pref_id] = mtp_device_host;
354 #else 355 #else
355 NOTIMPLEMENTED(); 356 NOTIMPLEMENTED();
356 continue; 357 continue;
357 #endif 358 #endif
358 } 359 }
359 DCHECK(!fsid.empty()); 360 DCHECK(!fsid.empty());
360 361
361 MediaFileSystemInfo new_entry( 362 MediaFileSystemInfo new_entry(
362 MakeJSONFileSystemName(gallery_info.display_name, 363 MakeJSONFileSystemName(gallery_info.display_name,
363 pref_id, 364 pref_id,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 void CleanUp() { 420 void CleanUp() {
420 DCHECK(rph_refs_.empty()); 421 DCHECK(rph_refs_.empty());
421 for (PrefIdFsInfoMap::const_iterator it = pref_id_map_.begin(); 422 for (PrefIdFsInfoMap::const_iterator it = pref_id_map_.begin();
422 it != pref_id_map_.end(); 423 it != pref_id_map_.end();
423 ++it) { 424 ++it) {
424 file_system_context_->RevokeFileSystem(it->second.fsid); 425 file_system_context_->RevokeFileSystem(it->second.fsid);
425 } 426 }
426 pref_id_map_.clear(); 427 pref_id_map_.clear();
427 428
428 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 429 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
429 media_device_map_references_.clear(); 430 for (MTPDeviceGalleryReferencesMap::iterator it =
431 mtp_device_gallery_references_.begin();
432 it != mtp_device_gallery_references_.end(); ++it) {
433 file_system_context_->RemoveMTPDeviceReferenceForHost(it->first, this);
434 }
435 mtp_device_gallery_references_.clear();
430 #endif 436 #endif
431
432 registrar_.RemoveAll(); 437 registrar_.RemoveAll();
433
434 no_references_callback_.Run(); 438 no_references_callback_.Run();
435 } 439 }
436 440
437 // MediaFileSystemRegistry owns |this| and |file_system_context_|, so it's 441 // MediaFileSystemRegistry owns |this| and |file_system_context_|, so it's
438 // safe to store a raw pointer. 442 // safe to store a raw pointer.
439 MediaFileSystemContext* file_system_context_; 443 MediaFileSystemContext* file_system_context_;
440 444
441 // A callback to call when the last RVH reference goes away. 445 // A callback to call when the last RVH reference goes away.
442 base::Closure no_references_callback_; 446 base::Closure no_references_callback_;
443 447
444 // A map from the gallery preferences id to the file system information. 448 // A map from the gallery preferences id to the file system information.
445 PrefIdFsInfoMap pref_id_map_; 449 PrefIdFsInfoMap pref_id_map_;
446 450
447 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 451 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
448 // A map from the gallery preferences id to the corresponding media device 452 // A map from the MTP device id to a set of media galleries that references to
449 // host object. 453 // that device.
450 MediaDeviceEntryReferencesMap media_device_map_references_; 454 MTPDeviceGalleryReferencesMap mtp_device_gallery_references_;
451 #endif 455 #endif
452 456
453 // The set of render processes and web contents that may have references to 457 // The set of render processes and web contents that may have references to
454 // the file system ids this instance manages. 458 // the file system ids this instance manages.
455 RenderProcessHostRefCount rph_refs_; 459 RenderProcessHostRefCount rph_refs_;
456 460
457 // A registrar for listening notifications. 461 // A registrar for listening notifications.
458 content::NotificationRegistrar registrar_; 462 content::NotificationRegistrar registrar_;
459 463
460 DISALLOW_COPY_AND_ASSIGN(ExtensionGalleriesHost); 464 DISALLOW_COPY_AND_ASSIGN(ExtensionGalleriesHost);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 existing_devices[i].name, FilePath(), 537 existing_devices[i].name, FilePath(),
534 false /*not user added*/); 538 false /*not user added*/);
535 } 539 }
536 return preferences; 540 return preferences;
537 } 541 }
538 542
539 void MediaFileSystemRegistry::OnRemovableStorageAttached( 543 void MediaFileSystemRegistry::OnRemovableStorageAttached(
540 const std::string& id, const string16& name, 544 const std::string& id, const string16& name,
541 const FilePath::StringType& location) { 545 const FilePath::StringType& location) {
542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
543
544 if (!MediaStorageUtil::IsMediaDevice(id)) 547 if (!MediaStorageUtil::IsMediaDevice(id))
545 return; 548 return;
546 549
547 for (ExtensionGalleriesHostMap::iterator profile_it = 550 for (ExtensionGalleriesHostMap::iterator profile_it =
548 extension_hosts_map_.begin(); 551 extension_hosts_map_.begin();
549 profile_it != extension_hosts_map_.end(); 552 profile_it != extension_hosts_map_.end();
550 ++profile_it) { 553 ++profile_it) {
551 MediaGalleriesPreferences* preferences = GetPreferences(profile_it->first); 554 MediaGalleriesPreferences* preferences = GetPreferences(profile_it->first);
552 preferences->AddGallery(id, name, FilePath(), false /*not user added*/); 555 preferences->AddGallery(id, name, FilePath(), false /*not user added*/);
553 } 556 }
554 } 557 }
555 558
556 size_t MediaFileSystemRegistry::GetExtensionHostCountForTests() const { 559 size_t MediaFileSystemRegistry::GetExtensionHostCountForTests() const {
557 return extension_hosts_map_.size(); 560 return extension_hosts_map_.size();
558 } 561 }
559 562
560 void MediaFileSystemRegistry::OnRemovableStorageDetached( 563 void MediaFileSystemRegistry::OnRemovableStorageDetached(
561 const std::string& id) { 564 const std::string& id) {
562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
563
564 // Since revoking a gallery in the ExtensionGalleriesHost may cause it 566 // Since revoking a gallery in the ExtensionGalleriesHost may cause it
565 // to be removed from the map and therefore invalidate any iterator pointing 567 // to be removed from the map and therefore invalidate any iterator pointing
566 // to it, this code first copies all the invalid gallery ids and the 568 // to it, this code first copies all the invalid gallery ids and the
567 // extension hosts in which they may appear (per profile) and revoked it in 569 // extension hosts in which they may appear (per profile) and revoked it in
568 // a second step. 570 // a second step.
569 std::vector<InvalidatedGalleriesInfo> invalid_galleries_info; 571 std::vector<InvalidatedGalleriesInfo> invalid_galleries_info;
570 572
571 for (ExtensionGalleriesHostMap::iterator profile_it = 573 for (ExtensionGalleriesHostMap::iterator profile_it =
572 extension_hosts_map_.begin(); 574 extension_hosts_map_.begin();
573 profile_it != extension_hosts_map_.end(); 575 profile_it != extension_hosts_map_.end();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 const std::string fsid = 632 const std::string fsid =
631 IsolatedContext::GetInstance()->RegisterFileSystemForPath( 633 IsolatedContext::GetInstance()->RegisterFileSystemForPath(
632 fileapi::kFileSystemTypeNativeMedia, path, &fs_name); 634 fileapi::kFileSystemTypeNativeMedia, path, &fs_name);
633 CHECK(!fsid.empty()); 635 CHECK(!fsid.empty());
634 return fsid; 636 return fsid;
635 } 637 }
636 638
637 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 639 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
638 virtual std::string RegisterFileSystemForMTPDevice( 640 virtual std::string RegisterFileSystemForMTPDevice(
639 const std::string& device_id, const FilePath& path, 641 const std::string& device_id, const FilePath& path,
640 scoped_refptr<ScopedMTPDeviceMapEntry>* entry) { 642 const ExtensionGalleriesHost* galleries_host) {
641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
642 DCHECK(!MediaStorageUtil::IsMassStorageDevice(device_id)); 644 DCHECK(!MediaStorageUtil::IsMassStorageDevice(device_id));
643 645
644 // Sanity checks for |path|. 646 // Sanity checks for |path|.
645 CHECK(path.IsAbsolute()); 647 CHECK(path.IsAbsolute());
646 CHECK(!path.ReferencesParent()); 648 CHECK(!path.ReferencesParent());
647 std::string fs_name(extension_misc::kMediaFileSystemPathPart); 649 std::string fs_name(extension_misc::kMediaFileSystemPathPart);
648 const std::string fsid = 650 const std::string fsid =
649 IsolatedContext::GetInstance()->RegisterFileSystemForPath( 651 IsolatedContext::GetInstance()->RegisterFileSystemForPath(
650 fileapi::kFileSystemTypeDeviceMedia, path, &fs_name); 652 fileapi::kFileSystemTypeDeviceMedia, path, &fs_name);
651 CHECK(!fsid.empty()); 653 CHECK(!fsid.empty());
652 DCHECK(entry); 654 registry_->AddGalleriesHostReferenceForMTPDevice(path.value(),
653 *entry = registry_->GetOrCreateScopedMTPDeviceMapEntry(path.value()); 655 galleries_host);
654 return fsid; 656 return fsid;
655 } 657 }
658
659 virtual void RemoveMTPDeviceReferenceForHost(
660 const FilePath::StringType& device_location,
661 const ExtensionGalleriesHost* galleries_host) {
662 registry_->RemoveGalleriesHostReferenceForMTPDevice(device_location,
663 galleries_host);
664 }
656 #endif 665 #endif
657 666
658 virtual void RevokeFileSystem(const std::string& fsid) { 667 virtual void RevokeFileSystem(const std::string& fsid) {
659 IsolatedContext::GetInstance()->RevokeFileSystem(fsid); 668 IsolatedContext::GetInstance()->RevokeFileSystem(fsid);
660 } 669 }
661 670
662 private: 671 private:
663 MediaFileSystemRegistry* registry_; 672 MediaFileSystemRegistry* registry_;
664 673
665 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemContextImpl); 674 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemContextImpl);
666 }; 675 };
667 676
668 MediaFileSystemRegistry::MediaFileSystemRegistry() 677 MediaFileSystemRegistry::MediaFileSystemRegistry()
669 : file_system_context_(new MediaFileSystemContextImpl(this)) { 678 : file_system_context_(new MediaFileSystemContextImpl(this)) {
670 // SystemMonitor may be NULL in unit tests. 679 // SystemMonitor may be NULL in unit tests.
671 SystemMonitor* system_monitor = SystemMonitor::Get(); 680 SystemMonitor* system_monitor = SystemMonitor::Get();
672 if (system_monitor) 681 if (system_monitor)
673 system_monitor->AddDevicesChangedObserver(this); 682 system_monitor->AddDevicesChangedObserver(this);
674 } 683 }
675 684
676 MediaFileSystemRegistry::~MediaFileSystemRegistry() { 685 MediaFileSystemRegistry::~MediaFileSystemRegistry() {
677 // SystemMonitor may be NULL in unit tests. 686 // SystemMonitor may be NULL in unit tests.
678 SystemMonitor* system_monitor = SystemMonitor::Get(); 687 SystemMonitor* system_monitor = SystemMonitor::Get();
679 if (system_monitor) 688 if (system_monitor)
680 system_monitor->RemoveDevicesChangedObserver(this); 689 system_monitor->RemoveDevicesChangedObserver(this);
690 DCHECK(mtp_device_delegate_map_.empty());
691 DCHECK(mtp_device_references_map_.empty());
681 } 692 }
682 693
683 void MediaFileSystemRegistry::OnMediaGalleriesRememberedGalleriesChanged( 694 void MediaFileSystemRegistry::OnMediaGalleriesRememberedGalleriesChanged(
684 PrefServiceBase* prefs) { 695 PrefServiceBase* prefs) {
685 // Find the Profile that contains the source PrefService. 696 // Find the Profile that contains the source PrefService.
686 PrefChangeRegistrarMap::iterator pref_change_it = 697 PrefChangeRegistrarMap::iterator pref_change_it =
687 pref_change_registrar_map_.begin(); 698 pref_change_registrar_map_.begin();
688 for (; pref_change_it != pref_change_registrar_map_.end(); ++pref_change_it) { 699 for (; pref_change_it != pref_change_registrar_map_.end(); ++pref_change_it) {
689 if (pref_change_it->first->GetPrefs() == prefs) 700 if (pref_change_it->first->GetPrefs() == prefs)
690 break; 701 break;
(...skipping 19 matching lines...) Expand all
710 gallery_host_it != extension_host_map.end(); 721 gallery_host_it != extension_host_map.end();
711 ++gallery_host_it) { 722 ++gallery_host_it) {
712 const extensions::Extension* extension = 723 const extensions::Extension* extension =
713 extensions_set->GetByID(gallery_host_it->first); 724 extensions_set->GetByID(gallery_host_it->first);
714 gallery_host_it->second->RevokeOldGalleries( 725 gallery_host_it->second->RevokeOldGalleries(
715 preferences->GalleriesForExtension(*extension)); 726 preferences->GalleriesForExtension(*extension));
716 } 727 }
717 } 728 }
718 729
719 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 730 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
720 ScopedMTPDeviceMapEntry* 731 void MediaFileSystemRegistry::AddGalleriesHostReferenceForMTPDevice(
721 MediaFileSystemRegistry::GetOrCreateScopedMTPDeviceMapEntry( 732 const FilePath::StringType& device_location,
722 const FilePath::StringType& device_location) { 733 const ExtensionGalleriesHost* galleries_host) {
723 MTPDeviceDelegateMap::iterator delegate_it = 734 MTPDeviceDelegateMap::iterator delegate_it =
724 mtp_delegate_map_.find(device_location); 735 mtp_device_delegate_map_.find(device_location);
725 if (delegate_it != mtp_delegate_map_.end() && delegate_it->second.get()) 736 if (delegate_it == mtp_device_delegate_map_.end()) {
726 return delegate_it->second; 737 mtp_device_delegate_map_[device_location] =
727 ScopedMTPDeviceMapEntry* mtp_device_host = new ScopedMTPDeviceMapEntry( 738 new ScopedMTPDeviceMapEntry(device_location);
728 device_location, base::Bind( 739 }
729 &MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry, 740 mtp_device_references_map_[device_location].insert(galleries_host);
730 base::Unretained(this), device_location));
731 mtp_delegate_map_[device_location] = mtp_device_host->AsWeakPtr();
732 return mtp_device_host;
733 } 741 }
734 742
735 void MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry( 743 void MediaFileSystemRegistry::RemoveGalleriesHostReferenceForMTPDevice(
736 const FilePath::StringType& device_location) { 744 const FilePath::StringType& device_location,
737 MTPDeviceDelegateMap::iterator delegate_it = 745 const ExtensionGalleriesHost* galleries_host) {
738 mtp_delegate_map_.find(device_location); 746 MTPDeviceReferencesMap::iterator hosts_it =
739 DCHECK(delegate_it != mtp_delegate_map_.end()); 747 mtp_device_references_map_.find(device_location);
740 mtp_delegate_map_.erase(delegate_it); 748 DCHECK(hosts_it != mtp_device_references_map_.end());
749 DCHECK(hosts_it->second.find(galleries_host) != hosts_it->second.end());
750 hosts_it->second.erase(galleries_host);
751 if (hosts_it->second.empty()) {
752 delete mtp_device_delegate_map_[device_location];
753 mtp_device_delegate_map_.erase(device_location);
754 mtp_device_references_map_.erase(hosts_it);
755 }
741 } 756 }
742 #endif 757 #endif
743 758
744 void MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty( 759 void MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty(
745 Profile* profile, const std::string& extension_id) { 760 Profile* profile, const std::string& extension_id) {
746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 761 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
747 762
748 ExtensionGalleriesHostMap::iterator extension_hosts = 763 ExtensionGalleriesHostMap::iterator extension_hosts =
749 extension_hosts_map_.find(profile); 764 extension_hosts_map_.find(profile);
750 DCHECK(extension_hosts != extension_hosts_map_.end()); 765 DCHECK(extension_hosts != extension_hosts_map_.end());
751 ExtensionHostMap::size_type erase_count = 766 ExtensionHostMap::size_type erase_count =
752 extension_hosts->second.erase(extension_id); 767 extension_hosts->second.erase(extension_id);
753 DCHECK_EQ(1U, erase_count); 768 DCHECK_EQ(1U, erase_count);
754 if (extension_hosts->second.empty()) { 769 if (extension_hosts->second.empty()) {
755 extension_hosts_map_.erase(extension_hosts); 770 extension_hosts_map_.erase(extension_hosts);
756 771
757 PrefChangeRegistrarMap::iterator pref_it = 772 PrefChangeRegistrarMap::iterator pref_it =
758 pref_change_registrar_map_.find(profile); 773 pref_change_registrar_map_.find(profile);
759 DCHECK(pref_it != pref_change_registrar_map_.end()); 774 DCHECK(pref_it != pref_change_registrar_map_.end());
760 delete pref_it->second; 775 delete pref_it->second;
761 pref_change_registrar_map_.erase(pref_it); 776 pref_change_registrar_map_.erase(pref_it);
762 } 777 }
763 } 778 }
764 779
765 } // namespace chrome 780 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698