| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/scoped_observer.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "chrome/browser/media_galleries/media_folder_finder.h" | 18 #include "chrome/browser/media_galleries/media_folder_finder.h" |
| 18 #include "chrome/browser/media_galleries/media_scan_types.h" | 19 #include "chrome/browser/media_galleries/media_scan_types.h" |
| 19 #include "content/public/browser/notification_observer.h" | 20 #include "extensions/browser/extension_registry_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" | |
| 21 | 21 |
| 22 class MediaScanManagerObserver; |
| 22 class Profile; | 23 class Profile; |
| 23 class MediaScanManagerObserver; | |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 class Extension; | 26 class Extension; |
| 27 } // namespace extensions | 27 class ExtensionRegistry; |
| 28 } |
| 28 | 29 |
| 29 // The MediaScanManager is owned by MediaFileSystemRegistry, which is global. | 30 // The MediaScanManager is owned by MediaFileSystemRegistry, which is global. |
| 30 // This class manages multiple 'virtual' media scans, up to one per extension | 31 // This class manages multiple 'virtual' media scans, up to one per extension |
| 31 // per profile, and also manages the one physical scan backing them. | 32 // per profile, and also manages the one physical scan backing them. |
| 32 // This class lives and is called on the UI thread. | 33 // This class lives and is called on the UI thread. |
| 33 class MediaScanManager : public content::NotificationObserver { | 34 class MediaScanManager : public extensions::ExtensionRegistryObserver { |
| 34 public: | 35 public: |
| 35 MediaScanManager(); | 36 MediaScanManager(); |
| 36 virtual ~MediaScanManager(); | 37 virtual ~MediaScanManager(); |
| 37 | 38 |
| 38 // There can only be ever one observer registered per profile. Does not take | 39 // There can only be ever one observer registered per profile. Does not take |
| 39 // ownership of |observer|. An observer must be registered before scanning. | 40 // ownership of |observer|. An observer must be registered before scanning. |
| 40 void AddObserver(Profile* profile, MediaScanManagerObserver* observer); | 41 void AddObserver(Profile* profile, MediaScanManagerObserver* observer); |
| 41 void RemoveObserver(Profile* profile); | 42 void RemoveObserver(Profile* profile); |
| 42 | 43 |
| 43 // Must be called when |profile| is shut down. | 44 // Must be called when |profile| is shut down. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 61 | 62 |
| 62 private: | 63 private: |
| 63 struct ScanObservers { | 64 struct ScanObservers { |
| 64 ScanObservers(); | 65 ScanObservers(); |
| 65 ~ScanObservers(); | 66 ~ScanObservers(); |
| 66 MediaScanManagerObserver* observer; | 67 MediaScanManagerObserver* observer; |
| 67 std::set<std::string /*extension id*/> scanning_extensions; | 68 std::set<std::string /*extension id*/> scanning_extensions; |
| 68 }; | 69 }; |
| 69 typedef std::map<Profile*, ScanObservers> ScanObserverMap; | 70 typedef std::map<Profile*, ScanObservers> ScanObserverMap; |
| 70 | 71 |
| 71 // content::NotificationObserver implementation. | 72 // extensions::ExtensionRegistryObserver implementation. |
| 72 virtual void Observe(int type, | 73 virtual void OnExtensionUnloaded( |
| 73 const content::NotificationSource& source, | 74 content::BrowserContext* browser_context, |
| 74 const content::NotificationDetails& details) OVERRIDE; | 75 const extensions::Extension* extension) OVERRIDE; |
| 75 | 76 |
| 76 bool ScanInProgress() const; | 77 bool ScanInProgress() const; |
| 77 | 78 |
| 78 void OnScanCompleted( | 79 void OnScanCompleted( |
| 79 bool success, | 80 bool success, |
| 80 const MediaFolderFinder::MediaFolderFinderResults& found_folders); | 81 const MediaFolderFinder::MediaFolderFinderResults& found_folders); |
| 81 | 82 |
| 82 void OnFoundContainerDirectories( | 83 void OnFoundContainerDirectories( |
| 83 const MediaFolderFinder::MediaFolderFinderResults& found_folders, | 84 const MediaFolderFinder::MediaFolderFinderResults& found_folders, |
| 84 const MediaFolderFinder::MediaFolderFinderResults& container_folders); | 85 const MediaFolderFinder::MediaFolderFinderResults& container_folders); |
| 85 | 86 |
| 86 scoped_ptr<MediaFolderFinder> folder_finder_; | 87 scoped_ptr<MediaFolderFinder> folder_finder_; |
| 87 | 88 |
| 88 base::Time scan_start_time_; | 89 base::Time scan_start_time_; |
| 89 | 90 |
| 90 // If not NULL, used to create |folder_finder_|. Used for testing. | 91 // If not NULL, used to create |folder_finder_|. Used for testing. |
| 91 MediaFolderFinderFactory testing_folder_finder_factory_; | 92 MediaFolderFinderFactory testing_folder_finder_factory_; |
| 92 | 93 |
| 93 // Set of extensions (on all profiles) that have an in-progress scan. | 94 // Set of extensions (on all profiles) that have an in-progress scan. |
| 94 ScanObserverMap observers_; | 95 ScanObserverMap observers_; |
| 95 | 96 |
| 96 // Used to listen for NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED events. | 97 ScopedObserver<extensions::ExtensionRegistry, |
| 97 content::NotificationRegistrar registrar_; | 98 extensions::ExtensionRegistryObserver> |
| 99 scoped_extension_registry_observer_; |
| 98 | 100 |
| 99 base::WeakPtrFactory<MediaScanManager> weak_factory_; | 101 base::WeakPtrFactory<MediaScanManager> weak_factory_; |
| 100 | 102 |
| 101 DISALLOW_COPY_AND_ASSIGN(MediaScanManager); | 103 DISALLOW_COPY_AND_ASSIGN(MediaScanManager); |
| 102 }; | 104 }; |
| 103 | 105 |
| 104 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_ | 106 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_ |
| OLD | NEW |