Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/media_galleries/media_scan_manager.h

Issue 1695563002: Media Galleries Partial Deprecation: Remove scan functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_
7
8 #include <map>
9 #include <set>
10 #include <string>
11
12 #include "base/compiler_specific.h"
13 #include "base/macros.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"
21
22 class MediaScanManagerObserver;
23 class Profile;
24
25 namespace extensions {
26 class Extension;
27 class ExtensionRegistry;
28 }
29
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 ~MediaScanManager() override;
38
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);
43
44 // Must be called when |profile| is shut down.
45 void CancelScansForProfile(Profile* profile);
46
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);
53
54 protected:
55 friend class MediaGalleriesPlatformAppBrowserTest;
56 friend class MediaScanManagerTest;
57
58 typedef base::Callback<MediaFolderFinder*(
59 const MediaFolderFinder::MediaFolderFinderResultsCallback&)>
60 MediaFolderFinderFactory;
61
62 void SetMediaFolderFinderFactory(const MediaFolderFinderFactory& factory);
63
64 // Here so that friend MediaScanManagerTest can access it.
65 static MediaFolderFinder::MediaFolderFinderResults FindContainerScanResults(
66 const MediaFolderFinder::MediaFolderFinderResults& found_folders,
67 const std::vector<base::FilePath>& sensitive_locations);
68
69 private:
70 struct ScanObservers {
71 ScanObservers();
72 ScanObservers(const ScanObservers& other);
73 ~ScanObservers();
74 MediaScanManagerObserver* observer;
75 std::set<std::string /*extension id*/> scanning_extensions;
76 };
77 typedef std::map<Profile*, ScanObservers> ScanObserverMap;
78
79 // extensions::ExtensionRegistryObserver implementation.
80 void OnExtensionUnloaded(
81 content::BrowserContext* browser_context,
82 const extensions::Extension* extension,
83 extensions::UnloadedExtensionInfo::Reason reason) override;
84
85 bool ScanInProgress() const;
86
87 void OnScanCompleted(
88 bool success,
89 const MediaFolderFinder::MediaFolderFinderResults& found_folders);
90
91 void OnFoundContainerDirectories(
92 const MediaFolderFinder::MediaFolderFinderResults& found_folders,
93 const MediaFolderFinder::MediaFolderFinderResults& container_folders);
94
95 scoped_ptr<MediaFolderFinder> folder_finder_;
96
97 base::Time scan_start_time_;
98
99 // If not NULL, used to create |folder_finder_|. Used for testing.
100 MediaFolderFinderFactory testing_folder_finder_factory_;
101
102 // Set of extensions (on all profiles) that have an in-progress scan.
103 ScanObserverMap observers_;
104
105 ScopedObserver<extensions::ExtensionRegistry,
106 extensions::ExtensionRegistryObserver>
107 scoped_extension_registry_observer_;
108
109 base::WeakPtrFactory<MediaScanManager> weak_factory_;
110
111 DISALLOW_COPY_AND_ASSIGN(MediaScanManager);
112 };
113
114 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698