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

Side by Side Diff: base/file_util.cc

Issue 16950027: Move ComputeDirectorySize to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git try 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <io.h> 8 #include <io.h>
9 #endif 9 #endif
10 #include <stdio.h> 10 #include <stdio.h>
11 11
12 #include <fstream> 12 #include <fstream>
13 13
14 #include "base/files/file_enumerator.h" 14 #include "base/files/file_enumerator.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 21
22 using base::FileEnumerator; 22 namespace base {
23 using base::FilePath;
24 23
25 namespace { 24 namespace {
26 25
27 const FilePath::CharType kExtensionSeparator = FILE_PATH_LITERAL('.'); 26 const FilePath::CharType kExtensionSeparator = FILE_PATH_LITERAL('.');
28 27
29 // The maximum number of 'uniquified' files we will try to create. 28 // The maximum number of 'uniquified' files we will try to create.
30 // This is used when the filename we're trying to download is already in use, 29 // This is used when the filename we're trying to download is already in use,
31 // so we create a new unique filename by appending " (nnn)" before the 30 // so we create a new unique filename by appending " (nnn)" before the
32 // extension, where 1 <= nnn <= kMaxUniqueFiles. 31 // extension, where 1 <= nnn <= kMaxUniqueFiles.
33 // Also used by code that cleans up said files. 32 // Also used by code that cleans up said files.
34 static const int kMaxUniqueFiles = 100; 33 static const int kMaxUniqueFiles = 100;
35 34
36 } // namespace 35 } // namespace
37 36
37 bool g_bug108724_debug = false;
38
39 int64 ComputeDirectorySize(const FilePath& root_path) {
40 int64 running_size = 0;
41 FileEnumerator file_iter(root_path, true, FileEnumerator::FILES);
42 while (!file_iter.Next().empty())
43 running_size += file_iter.GetInfo().GetSize();
44 return running_size;
45 }
46
47 } // namespace base
48
49 // -----------------------------------------------------------------------------
50
38 namespace file_util { 51 namespace file_util {
39 52
40 bool g_bug108724_debug = false; 53 using base::FileEnumerator;
54 using base::FilePath;
55 using base::kExtensionSeparator;
56 using base::kMaxUniqueFiles;
41 57
42 void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) { 58 void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) {
43 FilePath::StringType& value = 59 FilePath::StringType& value =
44 const_cast<FilePath::StringType&>(path->value()); 60 const_cast<FilePath::StringType&>(path->value());
45 61
46 const FilePath::StringType::size_type last_dot = 62 const FilePath::StringType::size_type last_dot =
47 value.rfind(kExtensionSeparator); 63 value.rfind(kExtensionSeparator);
48 const FilePath::StringType::size_type last_separator = 64 const FilePath::StringType::size_type last_separator =
49 value.find_last_of(FilePath::StringType(FilePath::kSeparators)); 65 value.find_last_of(FilePath::StringType(FilePath::kSeparators));
50 66
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 path.InsertBeforeExtensionASCII(base::StringPrintf(" (%d)", count)); 279 path.InsertBeforeExtensionASCII(base::StringPrintf(" (%d)", count));
264 if (!PathExists(new_path) && 280 if (!PathExists(new_path) &&
265 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { 281 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) {
266 return count; 282 return count;
267 } 283 }
268 } 284 }
269 285
270 return -1; 286 return -1;
271 } 287 }
272 288
273 int64 ComputeDirectorySize(const FilePath& root_path) { 289 } // namespace file_util
274 int64 running_size = 0;
275 FileEnumerator file_iter(root_path, true, FileEnumerator::FILES);
276 while (!file_iter.Next().empty())
277 running_size += file_iter.GetInfo().GetSize();
278 return running_size;
279 }
280
281 } // namespace
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | base/file_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698