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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/media_galleries/media_folder_finder.h"
17 #include "chrome/browser/media_galleries/media_scan_types.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
22 class MediaScanManagerObserver
;
24 namespace extensions
{
26 } // namespace extensions
28 // The MediaScanManager is owned by MediaFileSystemRegistry, which is global.
29 // This class manages multiple 'virtual' media scans, up to one per extension
30 // per profile, and also manages the one physical scan backing them.
31 // This class lives and is called on the UI thread.
32 class MediaScanManager
: public content::NotificationObserver
{
35 virtual ~MediaScanManager();
37 // There can only be ever one observer registered per profile. Does not take
38 // ownership of |observer|. An observer must be registered before scanning.
39 void AddObserver(Profile
* profile
, MediaScanManagerObserver
* observer
);
40 void RemoveObserver(Profile
* profile
);
42 // Must be called when |profile| is shut down.
43 void CancelScansForProfile(Profile
* profile
);
45 // The results of the scan are reported to the registered
46 // MediaScanManagerObserver via OnScanFinished. There must be an observer
47 // registered for |profile| before the scan starts.
48 void StartScan(Profile
* profile
, const extensions::Extension
* extension
,
50 void CancelScan(Profile
* profile
, const extensions::Extension
* extension
);
53 friend class MediaGalleriesPlatformAppBrowserTest
;
55 typedef base::Callback
<MediaFolderFinder
*(
56 const MediaFolderFinder::MediaFolderFinderResultsCallback
&)>
57 MediaFolderFinderFactory
;
59 void SetMediaFolderFinderFactory(const MediaFolderFinderFactory
& factory
);
62 struct ScanObservers
{
65 MediaScanManagerObserver
* observer
;
66 std::set
<std::string
/*extension id*/> scanning_extensions
;
68 typedef std::map
<Profile
*, ScanObservers
> ScanObserverMap
;
70 // content::NotificationObserver implementation.
71 virtual void Observe(int type
,
72 const content::NotificationSource
& source
,
73 const content::NotificationDetails
& details
) OVERRIDE
;
75 bool ScanInProgress() const;
79 const MediaFolderFinder::MediaFolderFinderResults
& found_folders
);
81 void OnFoundContainerDirectories(
82 const MediaFolderFinder::MediaFolderFinderResults
& found_folders
,
83 const MediaFolderFinder::MediaFolderFinderResults
& container_folders
);
85 scoped_ptr
<MediaFolderFinder
> folder_finder_
;
87 // If not NULL, used to create |folder_finder_|. Used for testing.
88 MediaFolderFinderFactory testing_folder_finder_factory_
;
90 // Set of extensions (on all profiles) that have an in-progress scan.
91 ScanObserverMap observers_
;
93 // Used to listen for NOTIFICATION_EXTENSION_UNLOADED events.
94 content::NotificationRegistrar registrar_
;
96 base::WeakPtrFactory
<MediaScanManager
> weak_factory_
;
98 DISALLOW_COPY_AND_ASSIGN(MediaScanManager
);
101 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_