| 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_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/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/system_monitor/system_monitor.h" | |
| 20 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 21 #include "base/values.h" | 20 #include "base/values.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/extension_system.h" | 22 #include "chrome/browser/extensions/extension_system.h" |
| 24 #include "chrome/browser/media_gallery/media_file_system_context.h" | 23 #include "chrome/browser/media_gallery/media_file_system_context.h" |
| 25 #include "chrome/browser/media_gallery/media_galleries_preferences.h" | 24 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
| 26 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h" | 25 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h" |
| 27 #include "chrome/browser/media_gallery/scoped_mtp_device_map_entry.h" | 26 #include "chrome/browser/media_gallery/scoped_mtp_device_map_entry.h" |
| 28 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/system_monitor/media_storage_util.h" | 29 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 31 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
| 33 #include "chrome/common/extensions/extension_constants.h" | 32 #include "chrome/common/extensions/extension_constants.h" |
| 34 #include "chrome/common/extensions/extension_set.h" | 33 #include "chrome/common/extensions/extension_set.h" |
| 35 #include "chrome/common/extensions/extension.h" | 34 #include "chrome/common/extensions/extension.h" |
| 36 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 37 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_details.h" | 37 #include "content/public/browser/notification_details.h" |
| 39 #include "content/public/browser/notification_observer.h" | 38 #include "content/public/browser/notification_observer.h" |
| 40 #include "content/public/browser/notification_registrar.h" | 39 #include "content/public/browser/notification_registrar.h" |
| 41 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.h" |
| 42 #include "content/public/browser/notification_types.h" | 41 #include "content/public/browser/notification_types.h" |
| 43 #include "content/public/browser/render_process_host.h" | 42 #include "content/public/browser/render_process_host.h" |
| 44 #include "content/public/browser/render_view_host.h" | 43 #include "content/public/browser/render_view_host.h" |
| 45 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
| 46 #include "webkit/fileapi/file_system_types.h" | 45 #include "webkit/fileapi/file_system_types.h" |
| 47 #include "webkit/fileapi/isolated_context.h" | 46 #include "webkit/fileapi/isolated_context.h" |
| 48 | 47 |
| 49 using base::SystemMonitor; | |
| 50 using content::BrowserThread; | 48 using content::BrowserThread; |
| 51 using content::NavigationController; | 49 using content::NavigationController; |
| 52 using content::RenderProcessHost; | 50 using content::RenderProcessHost; |
| 53 using content::WebContents; | 51 using content::WebContents; |
| 54 using fileapi::IsolatedContext; | 52 using fileapi::IsolatedContext; |
| 55 | 53 |
| 56 namespace chrome { | 54 namespace chrome { |
| 57 | 55 |
| 58 namespace { | 56 namespace { |
| 59 | 57 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 callback); | 465 callback); |
| 468 } | 466 } |
| 469 | 467 |
| 470 MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences( | 468 MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences( |
| 471 Profile* profile) { | 469 Profile* profile) { |
| 472 MediaGalleriesPreferences* preferences = | 470 MediaGalleriesPreferences* preferences = |
| 473 MediaGalleriesPreferencesFactory::GetForProfile(profile); | 471 MediaGalleriesPreferencesFactory::GetForProfile(profile); |
| 474 if (ContainsKey(extension_hosts_map_, profile)) | 472 if (ContainsKey(extension_hosts_map_, profile)) |
| 475 return preferences; | 473 return preferences; |
| 476 | 474 |
| 477 // SystemMonitor may be NULL in unit tests. | 475 // RemovableStorageNotifications may be NULL in unit tests. |
| 478 SystemMonitor* system_monitor = SystemMonitor::Get(); | 476 RemovableStorageNotifications* notifications = |
| 479 if (!system_monitor) | 477 RemovableStorageNotifications::GetInstance(); |
| 478 if (!notifications) |
| 480 return preferences; | 479 return preferences; |
| 481 std::vector<SystemMonitor::RemovableStorageInfo> existing_devices = | 480 std::vector<RemovableStorageNotifications::RemovableStorageInfo> |
| 482 system_monitor->GetAttachedRemovableStorage(); | 481 existing_devices = notifications->GetAttachedRemovableStorage(); |
| 483 for (size_t i = 0; i < existing_devices.size(); i++) { | 482 for (size_t i = 0; i < existing_devices.size(); i++) { |
| 484 if (!MediaStorageUtil::IsMediaDevice(existing_devices[i].device_id)) | 483 if (!MediaStorageUtil::IsMediaDevice(existing_devices[i].device_id)) |
| 485 continue; | 484 continue; |
| 486 preferences->AddGallery(existing_devices[i].device_id, | 485 preferences->AddGallery(existing_devices[i].device_id, |
| 487 existing_devices[i].name, FilePath(), | 486 existing_devices[i].name, FilePath(), |
| 488 false /*not user added*/); | 487 false /*not user added*/); |
| 489 } | 488 } |
| 490 return preferences; | 489 return preferences; |
| 491 } | 490 } |
| 492 | 491 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 622 } |
| 624 | 623 |
| 625 private: | 624 private: |
| 626 MediaFileSystemRegistry* registry_; | 625 MediaFileSystemRegistry* registry_; |
| 627 | 626 |
| 628 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemContextImpl); | 627 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemContextImpl); |
| 629 }; | 628 }; |
| 630 | 629 |
| 631 MediaFileSystemRegistry::MediaFileSystemRegistry() | 630 MediaFileSystemRegistry::MediaFileSystemRegistry() |
| 632 : file_system_context_(new MediaFileSystemContextImpl(this)) { | 631 : file_system_context_(new MediaFileSystemContextImpl(this)) { |
| 633 // SystemMonitor may be NULL in unit tests. | 632 // RemovableStorageNotifications may be NULL in unit tests. |
| 634 SystemMonitor* system_monitor = SystemMonitor::Get(); | 633 RemovableStorageNotifications* notifications = |
| 635 if (system_monitor) { | 634 RemovableStorageNotifications::GetInstance(); |
| 636 system_monitor->AddDevicesChangedObserver(this); | 635 if (notifications) { |
| 636 notifications->AddRemovableStorageObserver(this); |
| 637 | 637 |
| 638 // Add the devices that were already present before MediaFileSystemRegistry | 638 // Add the devices that were already present before MediaFileSystemRegistry |
| 639 // creation. | 639 // creation. |
| 640 std::vector<base::SystemMonitor::RemovableStorageInfo> storage_info = | 640 std::vector<RemovableStorageNotifications::RemovableStorageInfo> |
| 641 system_monitor->GetAttachedRemovableStorage(); | 641 storage_info = notifications->GetAttachedRemovableStorage(); |
| 642 for (size_t i = 0; i < storage_info.size(); ++i) | 642 for (size_t i = 0; i < storage_info.size(); ++i) |
| 643 transient_device_ids_.DeviceAttached(storage_info[i].device_id); | 643 transient_device_ids_.DeviceAttached(storage_info[i].device_id); |
| 644 } | 644 } |
| 645 } | 645 } |
| 646 | 646 |
| 647 MediaFileSystemRegistry::~MediaFileSystemRegistry() { | 647 MediaFileSystemRegistry::~MediaFileSystemRegistry() { |
| 648 // SystemMonitor may be NULL in unit tests. | 648 // RemovableStorageNotifications may be NULL in unit tests. |
| 649 SystemMonitor* system_monitor = SystemMonitor::Get(); | 649 RemovableStorageNotifications* notifications = |
| 650 if (system_monitor) | 650 RemovableStorageNotifications::GetInstance(); |
| 651 system_monitor->RemoveDevicesChangedObserver(this); | 651 if (notifications) |
| 652 notifications->RemoveRemovableStorageObserver(this); |
| 652 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 653 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 653 DCHECK(mtp_device_delegate_map_.empty()); | 654 DCHECK(mtp_device_delegate_map_.empty()); |
| 654 #endif | 655 #endif |
| 655 } | 656 } |
| 656 | 657 |
| 657 void MediaFileSystemRegistry::OnMediaGalleriesRememberedGalleriesChanged( | 658 void MediaFileSystemRegistry::OnMediaGalleriesRememberedGalleriesChanged( |
| 658 PrefServiceBase* prefs) { | 659 PrefServiceBase* prefs) { |
| 659 // Find the Profile that contains the source PrefService. | 660 // Find the Profile that contains the source PrefService. |
| 660 PrefChangeRegistrarMap::iterator pref_change_it = | 661 PrefChangeRegistrarMap::iterator pref_change_it = |
| 661 pref_change_registrar_map_.begin(); | 662 pref_change_registrar_map_.begin(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 | 734 |
| 734 PrefChangeRegistrarMap::iterator pref_it = | 735 PrefChangeRegistrarMap::iterator pref_it = |
| 735 pref_change_registrar_map_.find(profile); | 736 pref_change_registrar_map_.find(profile); |
| 736 DCHECK(pref_it != pref_change_registrar_map_.end()); | 737 DCHECK(pref_it != pref_change_registrar_map_.end()); |
| 737 delete pref_it->second; | 738 delete pref_it->second; |
| 738 pref_change_registrar_map_.erase(pref_it); | 739 pref_change_registrar_map_.erase(pref_it); |
| 739 } | 740 } |
| 740 } | 741 } |
| 741 | 742 |
| 742 } // namespace chrome | 743 } // namespace chrome |
| OLD | NEW |