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

Side by Side Diff: chrome/browser/media_galleries/fileapi/filtering_file_enumerator.cc

Issue 15653004: Picasa import: Make NativeMediaFileUtil an AsyncFileUtil (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address vandebo comments. Created 7 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "chrome/browser/media_galleries/fileapi/filtering_file_enumerator.h"
6
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "build/build_config.h"
10
11 #if defined(OS_WIN)
12 #include <windows.h>
13 #else
14 #include <cstring>
15
16 #include "base/string_util.h"
17 #endif
18
19 namespace chrome {
20
21 namespace {
22
23 // Used to skip the hidden folders and files. Returns true if the file specified
24 // by |path| should be skipped.
25 bool ShouldSkip(const base::FilePath& path) {
26 const base::FilePath& base_name = path.BaseName();
27 if (base_name.empty())
28 return false;
29
30 // Dot files (aka hidden files)
31 if (base_name.value()[0] == '.')
32 return true;
33
34 // Mac OS X file.
35 if (base_name.value() == FILE_PATH_LITERAL("__MACOSX"))
36 return true;
37
38 #if defined(OS_WIN)
39 DWORD file_attributes = ::GetFileAttributes(path.value().c_str());
40 if ((file_attributes != INVALID_FILE_ATTRIBUTES) &&
41 ((file_attributes & FILE_ATTRIBUTE_HIDDEN) != 0))
42 return true;
43 #else
44 // Windows always creates a recycle bin folder in the attached device to store
45 // all the deleted contents. On non-windows operating systems, there is no way
46 // to get the hidden attribute of windows recycle bin folders that are present
47 // on the attached device. Therefore, compare the file path name to the
48 // recycle bin name and exclude those folders. For more details, please refer
49 // to http://support.microsoft.com/kb/171694.
50 const char win_98_recycle_bin_name[] = "RECYCLED";
51 const char win_xp_recycle_bin_name[] = "RECYCLER";
52 const char win_vista_recycle_bin_name[] = "$Recycle.bin";
53 if ((base::strncasecmp(base_name.value().c_str(),
54 win_98_recycle_bin_name,
55 strlen(win_98_recycle_bin_name)) == 0) ||
56 (base::strncasecmp(base_name.value().c_str(),
57 win_xp_recycle_bin_name,
58 strlen(win_xp_recycle_bin_name)) == 0) ||
59 (base::strncasecmp(base_name.value().c_str(),
60 win_vista_recycle_bin_name,
61 strlen(win_vista_recycle_bin_name)) == 0))
62 return true;
63 #endif
64 return false;
65 }
66
67 } // namespace
68
69 FilteringFileEnumerator::FilteringFileEnumerator(
70 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator>
71 base_enumerator,
72 MediaPathFilter* filter)
73 : base_enumerator_(base_enumerator.Pass()),
74 filter_(filter) {
75 DCHECK(base_enumerator_.get());
76 DCHECK(filter);
77 }
78
79 FilteringFileEnumerator::~FilteringFileEnumerator() {
80 }
81
82 base::FilePath FilteringFileEnumerator::Next() {
83 while (true) {
84 base::FilePath next = base_enumerator_->Next();
85 if (ShouldSkip(next))
86 continue;
87
88 if (next.empty() ||
89 base_enumerator_->IsDirectory() ||
90 filter_->Match(next))
91 return next;
92 }
93 }
94
95 int64 FilteringFileEnumerator::Size() {
96 return base_enumerator_->Size();
97 }
98
99 base::Time FilteringFileEnumerator::LastModifiedTime() {
100 return base_enumerator_->LastModifiedTime();
101 }
102
103 bool FilteringFileEnumerator::IsDirectory() {
104 return base_enumerator_->IsDirectory();
105 }
106
107 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698