Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / media_galleries / media_scan_manager.h
blob707bd0ed69e022f4b5343033a89ca412ef0df27e
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_
8 #include <map>
9 #include <set>
10 #include <string>
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 "base/scoped_observer.h"
17 #include "base/time/time.h"
18 #include "chrome/browser/media_galleries/media_folder_finder.h"
19 #include "chrome/browser/media_galleries/media_scan_types.h"
20 #include "extensions/browser/extension_registry_observer.h"
22 class MediaScanManagerObserver;
23 class Profile;
25 namespace extensions {
26 class Extension;
27 class ExtensionRegistry;
30 // The MediaScanManager is owned by MediaFileSystemRegistry, which is global.
31 // This class manages multiple 'virtual' media scans, up to one per extension
32 // per profile, and also manages the one physical scan backing them.
33 // This class lives and is called on the UI thread.
34 class MediaScanManager : public extensions::ExtensionRegistryObserver {
35 public:
36 MediaScanManager();
37 virtual ~MediaScanManager();
39 // There can only be ever one observer registered per profile. Does not take
40 // ownership of |observer|. An observer must be registered before scanning.
41 void AddObserver(Profile* profile, MediaScanManagerObserver* observer);
42 void RemoveObserver(Profile* profile);
44 // Must be called when |profile| is shut down.
45 void CancelScansForProfile(Profile* profile);
47 // The results of the scan are reported to the registered
48 // MediaScanManagerObserver via OnScanFinished. There must be an observer
49 // registered for |profile| before the scan starts.
50 void StartScan(Profile* profile, const extensions::Extension* extension,
51 bool user_gesture);
52 void CancelScan(Profile* profile, const extensions::Extension* extension);
54 protected:
55 friend class MediaGalleriesPlatformAppBrowserTest;
57 typedef base::Callback<MediaFolderFinder*(
58 const MediaFolderFinder::MediaFolderFinderResultsCallback&)>
59 MediaFolderFinderFactory;
61 void SetMediaFolderFinderFactory(const MediaFolderFinderFactory& factory);
63 private:
64 struct ScanObservers {
65 ScanObservers();
66 ~ScanObservers();
67 MediaScanManagerObserver* observer;
68 std::set<std::string /*extension id*/> scanning_extensions;
70 typedef std::map<Profile*, ScanObservers> ScanObserverMap;
72 // extensions::ExtensionRegistryObserver implementation.
73 virtual void OnExtensionUnloaded(
74 content::BrowserContext* browser_context,
75 const extensions::Extension* extension,
76 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
78 bool ScanInProgress() const;
80 void OnScanCompleted(
81 bool success,
82 const MediaFolderFinder::MediaFolderFinderResults& found_folders);
84 void OnFoundContainerDirectories(
85 const MediaFolderFinder::MediaFolderFinderResults& found_folders,
86 const MediaFolderFinder::MediaFolderFinderResults& container_folders);
88 scoped_ptr<MediaFolderFinder> folder_finder_;
90 base::Time scan_start_time_;
92 // If not NULL, used to create |folder_finder_|. Used for testing.
93 MediaFolderFinderFactory testing_folder_finder_factory_;
95 // Set of extensions (on all profiles) that have an in-progress scan.
96 ScanObserverMap observers_;
98 ScopedObserver<extensions::ExtensionRegistry,
99 extensions::ExtensionRegistryObserver>
100 scoped_extension_registry_observer_;
102 base::WeakPtrFactory<MediaScanManager> weak_factory_;
104 DISALLOW_COPY_AND_ASSIGN(MediaScanManager);
107 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_