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

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

Issue 173853007: Media Galleries: Prune uninteresting folders when scanning. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 6 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 | Annotate | Revision Log
OLDNEW
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_FOLDER_FINDER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
16 #include "chrome/browser/media_galleries/media_scan_types.h" 16 #include "chrome/browser/media_galleries/media_scan_types.h"
17 17
18 // MediaFolderFinder scans local hard drives and look for folders that contain 18 // MediaFolderFinder scans local hard drives and look for folders that contain
19 // media files. 19 // media files.
20 class MediaFolderFinder { 20 class MediaFolderFinder {
21 public: 21 public:
22 // Key: path to a folder
23 // Value: scan results for that folder, non-recursive.
22 typedef std::map<base::FilePath, MediaGalleryScanResult> 24 typedef std::map<base::FilePath, MediaGalleryScanResult>
23 MediaFolderFinderResults; 25 MediaFolderFinderResults;
26
27 // |results| never contains entries for |graylisted_folders_| or parent
28 // directories of |graylisted_folders_|.
24 typedef base::Callback<void(bool /*success*/, 29 typedef base::Callback<void(bool /*success*/,
25 const MediaFolderFinderResults& /*results*/)> 30 const MediaFolderFinderResults& /*results*/)>
26 MediaFolderFinderResultsCallback; 31 MediaFolderFinderResultsCallback;
27 32
28 // |callback| will get called when the scan finishes. If the object is deleted 33 // |callback| will get called when the scan finishes. If the object is deleted
29 // before it finishes, the scan will stop and |callback| will get called with 34 // before it finishes, the scan will stop and |callback| will get called with
30 // success = false. 35 // success = false.
31 // MediaFolderFinder has a default set of per-platform paths to scan. 36 // MediaFolderFinder has a default set of per-platform paths to scan.
32 // Override in tests with SetRootsForTesting(). 37 // Override in tests with SetRootsForTesting().
33 explicit MediaFolderFinder(const MediaFolderFinderResultsCallback& callback); 38 explicit MediaFolderFinder(const MediaFolderFinderResultsCallback& callback);
34 virtual ~MediaFolderFinder(); 39 virtual ~MediaFolderFinder();
35 40
36 // Start the scan. 41 // Start the scan.
37 virtual void StartScan(); 42 virtual void StartScan();
38 43
44 const std::vector<base::FilePath>& graylisted_folders() const;
45
39 private: 46 private:
40 friend class MediaFolderFinderTest; 47 friend class MediaFolderFinderTest;
41 friend class MediaGalleriesPlatformAppBrowserTest; 48 friend class MediaGalleriesPlatformAppBrowserTest;
42 49
43 class Worker; 50 class Worker;
44 struct WorkerReply { 51 struct WorkerReply {
45 WorkerReply(); 52 WorkerReply();
46 ~WorkerReply(); 53 ~WorkerReply();
47 54
48 MediaGalleryScanResult scan_result; 55 MediaGalleryScanResult scan_result;
(...skipping 12 matching lines...) Expand all
61 68
62 // Scan a folder from |folders_to_scan_|. 69 // Scan a folder from |folders_to_scan_|.
63 void ScanFolder(); 70 void ScanFolder();
64 71
65 // Callback that handles the |reply| from |worker_| for a scanned |path|. 72 // Callback that handles the |reply| from |worker_| for a scanned |path|.
66 void GotScanResults(const base::FilePath& path, const WorkerReply& reply); 73 void GotScanResults(const base::FilePath& path, const WorkerReply& reply);
67 74
68 const MediaFolderFinderResultsCallback results_callback_; 75 const MediaFolderFinderResultsCallback results_callback_;
69 MediaFolderFinderResults results_; 76 MediaFolderFinderResults results_;
70 77
78 std::vector<base::FilePath> graylisted_folders_;
71 std::vector<base::FilePath> folders_to_scan_; 79 std::vector<base::FilePath> folders_to_scan_;
72 ScanState scan_state_; 80 ScanState scan_state_;
73 81
74 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_; 82 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
75 83
76 // Owned by MediaFolderFinder, but lives on |worker_task_runner_|. 84 // Owned by MediaFolderFinder, but lives on |worker_task_runner_|.
77 Worker* worker_; 85 Worker* worker_;
78 86
79 // Set of roots to scan for testing. 87 // Set of roots to scan for testing.
80 bool has_roots_for_testing_; 88 bool has_roots_for_testing_;
81 std::vector<base::FilePath> roots_for_testing_; 89 std::vector<base::FilePath> roots_for_testing_;
82 90
83 base::WeakPtrFactory<MediaFolderFinder> weak_factory_; 91 base::WeakPtrFactory<MediaFolderFinder> weak_factory_;
84 92
85 DISALLOW_COPY_AND_ASSIGN(MediaFolderFinder); 93 DISALLOW_COPY_AND_ASSIGN(MediaFolderFinder);
86 }; 94 };
87 95
88 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_ 96 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/file_system/file_system_api.cc ('k') | chrome/browser/media_galleries/media_folder_finder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698