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

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

Issue 11188015: Fix crash in media galleries on device removal. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 462
463 Profile* profile = 463 Profile* profile =
464 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); 464 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
465 MediaGalleriesPreferences* preferences = 465 MediaGalleriesPreferences* preferences =
466 MediaGalleriesPreferencesFactory::GetForProfile(profile); 466 MediaGalleriesPreferencesFactory::GetForProfile(profile);
467 467
468 if (!ContainsKey(extension_hosts_map_, profile)) 468 if (!ContainsKey(extension_hosts_map_, profile))
469 AddAttachedMediaDeviceGalleries(preferences); 469 AddAttachedMediaDeviceGalleries(preferences);
470 MediaGalleryPrefIdSet galleries = 470 MediaGalleryPrefIdSet galleries =
471 preferences->GalleriesForExtension(*extension); 471 preferences->GalleriesForExtension(*extension);
472 ExtensionGalleriesHost* extension_host =
473 extension_hosts_map_[profile][extension->id()].get();
474 472
475 // If the extension has no galleries and it didn't have any last time, just 473 // If the extension has no galleries and it didn't have any last time, just
476 // return the empty list. The second check is needed because of 474 // return the empty list. The second check is needed because of
477 // http://crbug.com/145855. 475 // http://crbug.com/145855.
478 if (galleries.empty() && !extension_host) { 476 bool has_extension_host = ContainsKey(extension_hosts_map_, profile) &&
477 ContainsKey(extension_hosts_map_[profile], extension->id());
478 if (galleries.empty() && !has_extension_host) {
479 callback.Run(std::vector<MediaFileSystemInfo>()); 479 callback.Run(std::vector<MediaFileSystemInfo>());
480 return; 480 return;
481 } 481 }
482 482
483 ExtensionGalleriesHost* extension_host =
484 extension_hosts_map_[profile][extension->id()].get();
483 if (!extension_host) { 485 if (!extension_host) {
484 extension_host = new ExtensionGalleriesHost( 486 extension_host = new ExtensionGalleriesHost(
485 file_system_context_.get(), 487 file_system_context_.get(),
486 base::Bind(&MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty, 488 base::Bind(&MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty,
487 base::Unretained(this), profile, extension->id())); 489 base::Unretained(this), profile, extension->id()));
488 extension_hosts_map_[profile][extension->id()] = extension_host; 490 extension_hosts_map_[profile][extension->id()] = extension_host;
489 } 491 }
490 extension_host->ReferenceFromRVH(rvh); 492 extension_host->ReferenceFromRVH(rvh);
491 493
492 extension_host->GetMediaFileSystems(galleries, preferences->known_galleries(), 494 extension_host->GetMediaFileSystems(galleries, preferences->known_galleries(),
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 extension_hosts_map_.find(profile); 686 extension_hosts_map_.find(profile);
685 DCHECK(extension_hosts != extension_hosts_map_.end()); 687 DCHECK(extension_hosts != extension_hosts_map_.end());
686 ExtensionHostMap::size_type erase_count = 688 ExtensionHostMap::size_type erase_count =
687 extension_hosts->second.erase(extension_id); 689 extension_hosts->second.erase(extension_id);
688 DCHECK_EQ(1U, erase_count); 690 DCHECK_EQ(1U, erase_count);
689 if (extension_hosts->second.empty()) 691 if (extension_hosts->second.empty())
690 extension_hosts_map_.erase(extension_hosts); 692 extension_hosts_map_.erase(extension_hosts);
691 } 693 }
692 694
693 } // namespace chrome 695 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698