EME test page application.
[chromium-blink-merge.git] / chrome / browser / media_galleries / media_folder_finder.h
blob8a503e05206d7f1e03611b183e3398b87da25ecf
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_FOLDER_FINDER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_
8 #include <map>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/sequenced_task_runner.h"
16 #include "chrome/browser/media_galleries/media_scan_types.h"
18 // MediaFolderFinder scans local hard drives and look for folders that contain
19 // media files.
20 class MediaFolderFinder {
21 public:
22 // Key: path to a folder
23 // Value: scan results for that folder, non-recursive.
24 typedef std::map<base::FilePath, MediaGalleryScanResult>
25 MediaFolderFinderResults;
27 // |results| never contains entries for |graylisted_folders_| or parent
28 // directories of |graylisted_folders_|.
29 typedef base::Callback<void(bool /*success*/,
30 const MediaFolderFinderResults& /*results*/)>
31 MediaFolderFinderResultsCallback;
33 // |callback| will get called when the scan finishes. If the object is deleted
34 // before it finishes, the scan will stop and |callback| will get called with
35 // success = false.
36 // MediaFolderFinder has a default set of per-platform paths to scan.
37 // Override in tests with SetRootsForTesting().
38 explicit MediaFolderFinder(const MediaFolderFinderResultsCallback& callback);
39 virtual ~MediaFolderFinder();
41 // Start the scan.
42 virtual void StartScan();
44 const std::vector<base::FilePath>& graylisted_folders() const;
46 private:
47 friend class MediaFolderFinderTest;
48 friend class MediaGalleriesPlatformAppBrowserTest;
50 class Worker;
51 struct WorkerReply {
52 WorkerReply();
53 ~WorkerReply();
55 MediaGalleryScanResult scan_result;
56 std::vector<base::FilePath> new_folders;
59 enum ScanState {
60 SCAN_STATE_NOT_STARTED,
61 SCAN_STATE_STARTED,
62 SCAN_STATE_FINISHED,
65 void SetRootsForTesting(const std::vector<base::FilePath>& roots);
67 void OnInitialized(const std::vector<base::FilePath>& roots);
69 // Scan a folder from |folders_to_scan_|.
70 void ScanFolder();
72 // Callback that handles the |reply| from |worker_| for a scanned |path|.
73 void GotScanResults(const base::FilePath& path, const WorkerReply& reply);
75 const MediaFolderFinderResultsCallback results_callback_;
76 MediaFolderFinderResults results_;
78 std::vector<base::FilePath> graylisted_folders_;
79 std::vector<base::FilePath> folders_to_scan_;
80 ScanState scan_state_;
82 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
84 // Owned by MediaFolderFinder, but lives on |worker_task_runner_|.
85 Worker* worker_;
87 // Set of roots to scan for testing.
88 bool has_roots_for_testing_;
89 std::vector<base::FilePath> roots_for_testing_;
91 base::WeakPtrFactory<MediaFolderFinder> weak_factory_;
93 DISALLOW_COPY_AND_ASSIGN(MediaFolderFinder);
96 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_