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

Unified Diff: chrome/browser/media_galleries/media_scan_manager.cc

Issue 173853007: Media Galleries: Prune uninteresting folders when scanning. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media_galleries/media_scan_manager.cc
===================================================================
--- chrome/browser/media_galleries/media_scan_manager.cc (revision 253526)
+++ chrome/browser/media_galleries/media_scan_manager.cc (working copy)
@@ -212,14 +212,38 @@
// may be to contain media directories. This function tries to find those
// immediate container directories.
MediaFolderFinder::MediaFolderFinderResults FindContainerScanResults(
- const MediaFolderFinder::MediaFolderFinderResults& found_folders) {
+ const MediaFolderFinder::MediaFolderFinderResults& found_folders,
+ const std::vector<base::FilePath>& sensitive_locations) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
+ std::vector<base::FilePath> abs_sensitive_locations;
+ for (size_t i = 0; i < sensitive_locations.size(); ++i) {
+ base::FilePath path = base::MakeAbsoluteFilePath(sensitive_locations[i]);
+ if (!path.empty())
+ abs_sensitive_locations.push_back(path);
+ }
// Count the number of scan results with the same parent directory.
typedef std::map<base::FilePath, int /*count*/> ContainerCandidates;
ContainerCandidates candidates;
for (MediaFolderFinder::MediaFolderFinderResults::const_iterator it =
found_folders.begin(); it != found_folders.end(); ++it) {
base::FilePath parent_directory = it->first.DirName();
+
+ // Skip sensitive folders and their ancestors.
+ bool is_sensitive = false;
+ base::FilePath abs_parent_directory =
+ base::MakeAbsoluteFilePath(parent_directory);
+ if (abs_parent_directory.empty())
+ continue;
+ for (size_t i = 0; i < abs_sensitive_locations.size(); ++i) {
+ if (abs_parent_directory == abs_sensitive_locations[i] ||
+ abs_parent_directory.IsParent(abs_sensitive_locations[i])) {
+ is_sensitive = true;
+ continue;
+ }
+ }
+ if (is_sensitive)
+ continue;
+
ContainerCandidates::iterator existing = candidates.find(parent_directory);
if (existing == candidates.end()) {
candidates[parent_directory] = 1;
@@ -252,11 +276,6 @@
return result;
}
-void RemoveSensitiveLocations(
- MediaFolderFinder::MediaFolderFinderResults* found_folders) {
- // TODO(vandebo) Use the greylist from filesystem api.
-}
-
int CountScanResultsForExtension(MediaGalleriesPreferences* preferences,
const extensions::Extension* extension,
MediaGalleryScanResult* file_counts) {
@@ -444,9 +463,12 @@
content::BrowserThread::PostTaskAndReplyWithResult(
content::BrowserThread::FILE, FROM_HERE,
- base::Bind(FindContainerScanResults, found_folders),
+ base::Bind(FindContainerScanResults,
+ found_folders,
+ folder_finder_->graylisted_folders()),
base::Bind(&MediaScanManager::OnFoundContainerDirectories,
- weak_factory_.GetWeakPtr(), found_folders));
+ weak_factory_.GetWeakPtr(),
+ found_folders));
}
void MediaScanManager::OnFoundContainerDirectories(
@@ -456,8 +478,6 @@
folders.insert(found_folders.begin(), found_folders.end());
folders.insert(container_folders.begin(), container_folders.end());
- RemoveSensitiveLocations(&folders);
-
for (ScanObserverMap::iterator scans_for_profile = observers_.begin();
scans_for_profile != observers_.end();
++scans_for_profile) {

Powered by Google App Engine
This is Rietveld 408576698