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

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

Issue 149363004: Media Galleries: Initial media scanner implementation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: with test Created 6 years, 10 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
Property Changes:
Added: svn:eol-style
+ LF
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_FOLDER_FINDER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_
7
8 #include <map>
9 #include <stack>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/sequenced_worker_pool.h"
16 #include "chrome/browser/media_galleries/media_scan_types.h"
17
18 // MediaFolderFinder scans local hard drives and look for folders that contain
19 // media files.
20 class MediaFolderFinder {
21 public:
22 typedef std::map<base::FilePath, MediaGalleryScanResult>
23 MediaFolderFinderResults;
24 typedef base::Callback<void(bool /*success*/,
25 const MediaFolderFinderResults& /*results*/)>
26 MediaFolderFinderResultsCallback;
27 typedef base::Callback<MediaGalleryScanFileType(const base::FilePath&)>
28 FilterCallback;
29
30 // Set up a scan with a given set of |roots| as starting points.
31 // The elements of |roots| should not overlap and should be absolute.
32 // |callback| will get called when the scan finishes. If the object is deleted
33 // before it finishes, the scan will stop and |callback| will get called with
34 // success = false.
35 MediaFolderFinder(const std::vector<base::FilePath>& roots,
36 const MediaFolderFinderResultsCallback& callback);
37 ~MediaFolderFinder();
38
39 // Start the scan.
40 void StartScan();
41
42 private:
43 enum ScanState {
44 SCAN_STATE_NOT_STARTED,
45 SCAN_STATE_STARTED,
46 SCAN_STATE_FINISHED,
47 };
48
49 // Scan a folder from |folders_to_scan_|.
50 void ScanFolder();
51
52 // Callback that returns the |scan_result| for |path| and the |new_folders|
53 // to scan in future calls to ScanFolder().
54 void GotScanResults(const base::FilePath& path,
55 const MediaGalleryScanResult* scan_result,
56 const std::vector<base::FilePath>* new_folders);
57
58 const MediaFolderFinderResultsCallback results_callback_;
59 MediaFolderFinderResults results_;
60
61 std::stack<base::FilePath> folders_to_scan_;
62 ScanState scan_state_;
63
64 // Token to make sure all calls with |filter_callback_| are on the same
65 // sequence.
66 base::SequencedWorkerPool::SequenceToken token_;
67
68 // Callback used to filter through files and make sure they are media files.
69 FilterCallback filter_callback_;
70
71 base::WeakPtrFactory<MediaFolderFinder> weak_factory_;
72
73 DISALLOW_COPY_AND_ASSIGN(MediaFolderFinder);
74 };
75
76 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_
OLDNEW
« no previous file with comments | « chrome/browser/media_galleries/fileapi/media_path_filter.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