OLD | NEW |
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_galleries/media_file_system_registry.h" | 7 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 141 } |
142 default: { | 142 default: { |
143 NOTREACHED(); | 143 NOTREACHED(); |
144 break; | 144 break; |
145 } | 145 } |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 void OnRendererProcessTerminated(const RenderProcessHost* rph) { | 149 void OnRendererProcessTerminated(const RenderProcessHost* rph) { |
150 RPHRefCount::iterator rph_info = refs_.find(rph); | 150 RPHRefCount::iterator rph_info = refs_.find(rph); |
151 DCHECK(rph_info != refs_.end()); | 151 // This could be a potential problem if the RPH is navigated to |
| 152 // a page on the same renderer (triggering OWCDON()) and then |
| 153 // the renderer crashes. |
| 154 if (rph_info == refs_.end()) { |
| 155 NOTREACHED(); |
| 156 return; |
| 157 } |
| 158 |
152 delete rph_info->second; | 159 delete rph_info->second; |
153 refs_.erase(rph_info); | 160 refs_.erase(rph_info); |
154 if (refs_.empty()) | 161 if (refs_.empty()) |
155 no_references_callback_.Run(); | 162 no_references_callback_.Run(); |
156 } | 163 } |
157 | 164 |
158 void OnWebContentsDestroyedOrNavigated(const WebContents* contents) { | 165 void OnWebContentsDestroyedOrNavigated(const WebContents* contents) { |
159 RenderProcessHost* rph = contents->GetRenderProcessHost(); | 166 RenderProcessHost* rph = contents->GetRenderProcessHost(); |
160 RPHRefCount::iterator rph_info = refs_.find(rph); | 167 RPHRefCount::iterator rph_info = refs_.find(rph); |
161 DCHECK(rph_info != refs_.end()); | 168 DCHECK(rph_info != refs_.end()); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 287 |
281 private: | 288 private: |
282 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> PrefIdFsInfoMap; | 289 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> PrefIdFsInfoMap; |
283 | 290 |
284 // Private destructor and friend declaration for ref counted implementation. | 291 // Private destructor and friend declaration for ref counted implementation. |
285 friend class base::RefCountedThreadSafe<ExtensionGalleriesHost>; | 292 friend class base::RefCountedThreadSafe<ExtensionGalleriesHost>; |
286 | 293 |
287 virtual ~ExtensionGalleriesHost() { | 294 virtual ~ExtensionGalleriesHost() { |
288 DCHECK(rph_refs_.empty()); | 295 DCHECK(rph_refs_.empty()); |
289 DCHECK(pref_id_map_.empty()); | 296 DCHECK(pref_id_map_.empty()); |
290 | |
291 } | 297 } |
292 | 298 |
293 void GetMediaFileSystemsForAttachedDevices( | 299 void GetMediaFileSystemsForAttachedDevices( |
294 const MediaStorageUtil::DeviceIdSet* attached_devices, | 300 const MediaStorageUtil::DeviceIdSet* attached_devices, |
295 const MediaGalleryPrefIdSet& galleries, | 301 const MediaGalleryPrefIdSet& galleries, |
296 const MediaGalleriesPrefInfoMap& galleries_info, | 302 const MediaGalleriesPrefInfoMap& galleries_info, |
297 const MediaFileSystemsCallback& callback) { | 303 const MediaFileSystemsCallback& callback) { |
298 std::vector<MediaFileSystemInfo> result; | 304 std::vector<MediaFileSystemInfo> result; |
| 305 |
| 306 if (rph_refs_.empty()) { |
| 307 // We're actually in the middle of shutdown, and Filter...() lagging |
| 308 // which can invoke this method interleaved in the destruction callback |
| 309 // sequence and re-populate pref_id_map_. |
| 310 callback.Run(result); |
| 311 return; |
| 312 } |
| 313 |
299 MediaGalleryPrefIdSet new_galleries; | 314 MediaGalleryPrefIdSet new_galleries; |
300 for (std::set<MediaGalleryPrefId>::const_iterator pref_id_it = | 315 for (std::set<MediaGalleryPrefId>::const_iterator pref_id_it = |
301 galleries.begin(); | 316 galleries.begin(); |
302 pref_id_it != galleries.end(); | 317 pref_id_it != galleries.end(); |
303 ++pref_id_it) { | 318 ++pref_id_it) { |
304 const MediaGalleryPrefId& pref_id = *pref_id_it; | 319 const MediaGalleryPrefId& pref_id = *pref_id_it; |
305 const MediaGalleryPrefInfo& gallery_info = | 320 const MediaGalleryPrefInfo& gallery_info = |
306 galleries_info.find(pref_id)->second; | 321 galleries_info.find(pref_id)->second; |
307 const std::string& device_id = gallery_info.device_id; | 322 const std::string& device_id = gallery_info.device_id; |
308 if (!ContainsKey(*attached_devices, device_id)) | 323 if (!ContainsKey(*attached_devices, device_id)) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 extension_hosts->second[extension->id()].get(); | 429 extension_hosts->second[extension->id()].get(); |
415 if (!extension_host) { | 430 if (!extension_host) { |
416 extension_host = new ExtensionGalleriesHost( | 431 extension_host = new ExtensionGalleriesHost( |
417 file_system_context_.get(), | 432 file_system_context_.get(), |
418 base::Bind(&MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty, | 433 base::Bind(&MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty, |
419 base::Unretained(this), | 434 base::Unretained(this), |
420 profile, | 435 profile, |
421 extension->id())); | 436 extension->id())); |
422 extension_hosts_map_[profile][extension->id()] = extension_host; | 437 extension_hosts_map_[profile][extension->id()] = extension_host; |
423 } | 438 } |
| 439 // This must come before the GetMediaFileSystems call to make sure the |
| 440 // RVH of the context is referenced before the filesystems are retrieved. |
424 extension_host->ReferenceFromRVH(rvh); | 441 extension_host->ReferenceFromRVH(rvh); |
425 | 442 |
426 extension_host->GetMediaFileSystems(galleries, preferences->known_galleries(), | 443 extension_host->GetMediaFileSystems(galleries, preferences->known_galleries(), |
427 callback); | 444 callback); |
428 } | 445 } |
429 | 446 |
430 MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences( | 447 MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences( |
431 Profile* profile) { | 448 Profile* profile) { |
432 // Create an empty ExtensionHostMap for this profile on first initialization. | 449 // Create an empty ExtensionHostMap for this profile on first initialization. |
433 if (!ContainsKey(extension_hosts_map_, profile)) | 450 if (!ContainsKey(extension_hosts_map_, profile)) |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 DCHECK_EQ(1U, erase_count); | 683 DCHECK_EQ(1U, erase_count); |
667 if (extension_hosts->second.empty()) { | 684 if (extension_hosts->second.empty()) { |
668 // When a profile has no ExtensionGalleriesHosts left, remove the | 685 // When a profile has no ExtensionGalleriesHosts left, remove the |
669 // matching gallery-change-watcher since it is no longer needed. Leave the | 686 // matching gallery-change-watcher since it is no longer needed. Leave the |
670 // |extension_hosts| entry alone, since it indicates the profile has been | 687 // |extension_hosts| entry alone, since it indicates the profile has been |
671 // previously used. | 688 // previously used. |
672 MediaGalleriesPreferences* preferences = GetPreferences(profile); | 689 MediaGalleriesPreferences* preferences = GetPreferences(profile); |
673 preferences->RemoveGalleryChangeObserver(this); | 690 preferences->RemoveGalleryChangeObserver(this); |
674 } | 691 } |
675 } | 692 } |
OLD | NEW |