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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 }; | 424 }; |
425 | 425 |
426 /****************** | 426 /****************** |
427 * Public methods | 427 * Public methods |
428 ******************/ | 428 ******************/ |
429 | 429 |
430 void MediaFileSystemRegistry::GetMediaFileSystemsForExtension( | 430 void MediaFileSystemRegistry::GetMediaFileSystemsForExtension( |
431 const content::RenderViewHost* rvh, | 431 const content::RenderViewHost* rvh, |
432 const extensions::Extension* extension, | 432 const extensions::Extension* extension, |
433 const MediaFileSystemsCallback& callback) { | 433 const MediaFileSystemsCallback& callback) { |
434 LOG(INFO) << "GetFSForExt"; | |
434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
435 | 436 |
436 Profile* profile = | 437 Profile* profile = |
437 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); | 438 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); |
438 MediaGalleriesPreferences* preferences = GetPreferences(profile); | 439 GetPreferencesAsync( |
440 profile, base::Bind( | |
441 &MediaFileSystemRegistry::GetMediaFileSystemsPostStorageMonitorInit, | |
442 base::Unretained(this), | |
443 rvh, extension, callback)); | |
444 } | |
445 | |
446 void MediaFileSystemRegistry::GetMediaFileSystemsPostStorageMonitorInit( | |
447 const content::RenderViewHost* rvh, | |
448 const extensions::Extension* extension, | |
449 const MediaFileSystemsCallback& callback, | |
450 MediaGalleriesPreferences* preferences) { | |
451 LOG(INFO) << "GetFSForExtPostInit"; | |
439 MediaGalleryPrefIdSet galleries = | 452 MediaGalleryPrefIdSet galleries = |
440 preferences->GalleriesForExtension(*extension); | 453 preferences->GalleriesForExtension(*extension); |
441 | 454 |
442 if (galleries.empty()) { | 455 if (galleries.empty()) { |
443 callback.Run(std::vector<MediaFileSystemInfo>()); | 456 callback.Run(std::vector<MediaFileSystemInfo>()); |
444 return; | 457 return; |
445 } | 458 } |
446 | 459 |
460 Profile* profile = | |
461 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); | |
447 if (!ContainsKey(pref_change_registrar_map_, profile)) { | 462 if (!ContainsKey(pref_change_registrar_map_, profile)) { |
448 PrefChangeRegistrar* pref_registrar = new PrefChangeRegistrar; | 463 PrefChangeRegistrar* pref_registrar = new PrefChangeRegistrar; |
449 pref_registrar->Init(profile->GetPrefs()); | 464 pref_registrar->Init(profile->GetPrefs()); |
450 pref_registrar->Add( | 465 pref_registrar->Add( |
451 prefs::kMediaGalleriesRememberedGalleries, | 466 prefs::kMediaGalleriesRememberedGalleries, |
452 base::Bind(&MediaFileSystemRegistry::OnRememberedGalleriesChanged, | 467 base::Bind(&MediaFileSystemRegistry::OnRememberedGalleriesChanged, |
453 base::Unretained(this), | 468 base::Unretained(this), |
454 pref_registrar->prefs())); | 469 pref_registrar->prefs())); |
455 pref_change_registrar_map_[profile] = pref_registrar; | 470 pref_change_registrar_map_[profile] = pref_registrar; |
456 } | 471 } |
457 | 472 |
458 ExtensionGalleriesHost* extension_host = | 473 ExtensionGalleriesHost* extension_host = |
459 extension_hosts_map_[profile][extension->id()].get(); | 474 extension_hosts_map_[profile][extension->id()].get(); |
460 if (!extension_host) { | 475 if (!extension_host) { |
461 extension_host = new ExtensionGalleriesHost( | 476 extension_host = new ExtensionGalleriesHost( |
462 file_system_context_.get(), | 477 file_system_context_.get(), |
463 base::Bind(&MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty, | 478 base::Bind(&MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty, |
464 base::Unretained(this), profile, extension->id())); | 479 base::Unretained(this), profile, extension->id())); |
465 extension_hosts_map_[profile][extension->id()] = extension_host; | 480 extension_hosts_map_[profile][extension->id()] = extension_host; |
466 } | 481 } |
467 extension_host->ReferenceFromRVH(rvh); | 482 extension_host->ReferenceFromRVH(rvh); |
468 | 483 |
469 extension_host->GetMediaFileSystems(galleries, preferences->known_galleries(), | 484 extension_host->GetMediaFileSystems(galleries, preferences->known_galleries(), |
470 callback); | 485 callback); |
471 } | 486 } |
472 | 487 |
488 void MediaFileSystemRegistry::GetPreferencesAsync( | |
489 Profile* profile, | |
490 base::Callback<void(MediaGalleriesPreferences*)> callback) { | |
491 LOG(INFO) << "GetPreferencesAsync"; | |
492 StorageMonitor* monitor = StorageMonitor::GetInstance(); | |
493 if (!monitor) { | |
Lei Zhang
2013/05/10 05:24:43
Do we want to just make tests that use MediaFSRegi
Greg Billock
2013/05/10 16:20:27
Yes, I think that'd be better. I kind of suspect t
Lei Zhang
2013/05/11 02:12:22
Can you add a TODO so we don't forget?
Greg Billock
2013/05/13 21:20:38
Done.
| |
494 callback.Run(MediaGalleriesPreferencesFactory::GetForProfile(profile)); | |
495 return; | |
496 } | |
497 | |
498 if (monitor->IsInitialized()) { | |
499 callback.Run(GetPreferences(profile)); | |
500 return; | |
501 } | |
502 | |
503 monitor->Initialize( | |
504 base::Bind(&MediaFileSystemRegistry::OnStorageMonitorInitialized, | |
505 base::Unretained(this), | |
506 profile, callback)); | |
507 | |
508 // TODO(gbillock): set a timeout here to bail out of init? | |
509 } | |
510 | |
511 void MediaFileSystemRegistry::OnStorageMonitorInitialized( | |
512 Profile* profile, | |
513 base::Callback<void(MediaGalleriesPreferences*)> callback) { | |
514 LOG(INFO) << "StorageMonitor inialized..."; | |
515 callback.Run(GetPreferences(profile)); | |
516 } | |
517 | |
473 MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences( | 518 MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences( |
474 Profile* profile) { | 519 Profile* profile) { |
520 LOG(INFO) << "MFSR::GetPreferences"; | |
475 MediaGalleriesPreferences* preferences = | 521 MediaGalleriesPreferences* preferences = |
476 MediaGalleriesPreferencesFactory::GetForProfile(profile); | 522 MediaGalleriesPreferencesFactory::GetForProfile(profile); |
477 if (ContainsKey(extension_hosts_map_, profile)) | 523 if (ContainsKey(extension_hosts_map_, profile)) |
478 return preferences; | 524 return preferences; |
479 | 525 |
480 // Create an empty entry so the initialization code below only gets called | 526 // Create an empty entry so the initialization code below only gets called |
481 // once per profile. | 527 // once per profile. |
482 extension_hosts_map_[profile] = ExtensionHostMap(); | 528 extension_hosts_map_[profile] = ExtensionHostMap(); |
483 | 529 |
484 // StorageMonitor may be NULL in unit tests. | 530 // StorageMonitor may be NULL in unit tests. |
485 StorageMonitor* monitor = StorageMonitor::GetInstance(); | 531 StorageMonitor* monitor = StorageMonitor::GetInstance(); |
486 if (!monitor) | 532 if (!monitor) |
487 return preferences; | 533 return preferences; |
534 DCHECK(monitor->IsInitialized()); | |
488 std::vector<StorageInfo> existing_devices = monitor->GetAttachedStorage(); | 535 std::vector<StorageInfo> existing_devices = monitor->GetAttachedStorage(); |
489 for (size_t i = 0; i < existing_devices.size(); i++) { | 536 for (size_t i = 0; i < existing_devices.size(); i++) { |
490 if (!MediaStorageUtil::IsMediaDevice(existing_devices[i].device_id)) | 537 if (!MediaStorageUtil::IsMediaDevice(existing_devices[i].device_id)) |
491 continue; | 538 continue; |
492 preferences->AddGalleryWithName(existing_devices[i].device_id, | 539 preferences->AddGalleryWithName(existing_devices[i].device_id, |
493 existing_devices[i].name, | 540 existing_devices[i].name, |
494 base::FilePath(), | 541 base::FilePath(), |
495 false /*not user added*/); | 542 false /*not user added*/); |
496 } | 543 } |
497 return preferences; | 544 return preferences; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 // previously used. | 775 // previously used. |
729 PrefChangeRegistrarMap::iterator pref_it = | 776 PrefChangeRegistrarMap::iterator pref_it = |
730 pref_change_registrar_map_.find(profile); | 777 pref_change_registrar_map_.find(profile); |
731 DCHECK(pref_it != pref_change_registrar_map_.end()); | 778 DCHECK(pref_it != pref_change_registrar_map_.end()); |
732 delete pref_it->second; | 779 delete pref_it->second; |
733 pref_change_registrar_map_.erase(pref_it); | 780 pref_change_registrar_map_.erase(pref_it); |
734 } | 781 } |
735 } | 782 } |
736 | 783 |
737 } // namespace chrome | 784 } // namespace chrome |
OLD | NEW |