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_
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
20 class MediaFolderFinder
{
22 typedef std::map
<base::FilePath
, MediaGalleryScanResult
>
23 MediaFolderFinderResults
;
24 typedef base::Callback
<void(bool /*success*/,
25 const MediaFolderFinderResults
& /*results*/)>
26 MediaFolderFinderResultsCallback
;
28 // |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
31 // MediaFolderFinder has a default set of per-platform paths to scan.
32 // Override in tests with SetRootsForTesting().
33 explicit MediaFolderFinder(const MediaFolderFinderResultsCallback
& callback
);
34 virtual ~MediaFolderFinder();
37 virtual void StartScan();
40 friend class MediaFolderFinderTest
;
47 MediaGalleryScanResult scan_result
;
48 std::vector
<base::FilePath
> new_folders
;
52 SCAN_STATE_NOT_STARTED
,
57 void SetRootsForTesting(const std::vector
<base::FilePath
>& roots
);
59 void OnInitialized(const std::vector
<base::FilePath
>& roots
);
61 // Scan a folder from |folders_to_scan_|.
64 // Callback that handles the |reply| from |worker_| for a scanned |path|.
65 void GotScanResults(const base::FilePath
& path
, const WorkerReply
& reply
);
67 const MediaFolderFinderResultsCallback results_callback_
;
68 MediaFolderFinderResults results_
;
70 std::vector
<base::FilePath
> folders_to_scan_
;
71 ScanState scan_state_
;
73 scoped_refptr
<base::SequencedTaskRunner
> worker_task_runner_
;
75 // Owned by MediaFolderFinder, but lives on |worker_task_runner_|.
78 // Set of roots to scan for testing.
79 bool has_roots_for_testing_
;
80 std::vector
<base::FilePath
> roots_for_testing_
;
82 base::WeakPtrFactory
<MediaFolderFinder
> weak_factory_
;
84 DISALLOW_COPY_AND_ASSIGN(MediaFolderFinder
);
87 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FOLDER_FINDER_H_