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

Side by Side Diff: base/file_util_win.cc

Issue 13196006: Move path functions from file_util to FilePath object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git try Created 7 years, 8 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 #include <windows.h> 7 #include <windows.h>
8 #include <psapi.h> 8 #include <psapi.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 10 matching lines...) Expand all
21 #include "base/string_util.h" 21 #include "base/string_util.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/threading/thread_restrictions.h" 23 #include "base/threading/thread_restrictions.h"
24 #include "base/time.h" 24 #include "base/time.h"
25 #include "base/utf_string_conversions.h" 25 #include "base/utf_string_conversions.h"
26 #include "base/win/scoped_handle.h" 26 #include "base/win/scoped_handle.h"
27 #include "base/win/windows_version.h" 27 #include "base/win/windows_version.h"
28 28
29 using base::FilePath; 29 using base::FilePath;
30 30
31 namespace base {
32
33 FilePath MakeAbsoluteFilePath(const FilePath& input) {
34 base::ThreadRestrictions::AssertIOAllowed();
35 wchar_t file_path[MAX_PATH];
36 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH))
37 return FilePath();
38 return FilePath(file_path);
39 }
40
41 } // namespace base
42
31 namespace file_util { 43 namespace file_util {
32 44
33 namespace { 45 namespace {
34 46
35 const DWORD kFileShareAll = 47 const DWORD kFileShareAll =
36 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; 48 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
37 49
38 } // namespace 50 } // namespace
39 51
40 bool AbsolutePath(FilePath* path) {
41 base::ThreadRestrictions::AssertIOAllowed();
42 wchar_t file_path_buf[MAX_PATH];
43 if (!_wfullpath(file_path_buf, path->value().c_str(), MAX_PATH))
44 return false;
45 *path = FilePath(file_path_buf);
46 return true;
47 }
48
49 bool Delete(const FilePath& path, bool recursive) { 52 bool Delete(const FilePath& path, bool recursive) {
50 base::ThreadRestrictions::AssertIOAllowed(); 53 base::ThreadRestrictions::AssertIOAllowed();
51 54
52 if (path.value().length() >= MAX_PATH) 55 if (path.value().length() >= MAX_PATH)
53 return false; 56 return false;
54 57
55 if (!recursive) { 58 if (!recursive) {
56 // If not recursing, then first check to see if |path| is a directory. 59 // If not recursing, then first check to see if |path| is a directory.
57 // If it is, then remove it with RemoveDirectory. 60 // If it is, then remove it with RemoveDirectory.
58 base::PlatformFileInfo file_info; 61 base::PlatformFileInfo file_info;
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 857
855 // Length of |path| with path separator appended. 858 // Length of |path| with path separator appended.
856 size_t prefix = path.StripTrailingSeparators().value().size() + 1; 859 size_t prefix = path.StripTrailingSeparators().value().size() + 1;
857 // The whole path string must be shorter than MAX_PATH. That is, it must be 860 // The whole path string must be shorter than MAX_PATH. That is, it must be
858 // prefix + component_length < MAX_PATH (or equivalently, <= MAX_PATH - 1). 861 // prefix + component_length < MAX_PATH (or equivalently, <= MAX_PATH - 1).
859 int whole_path_limit = std::max(0, MAX_PATH - 1 - static_cast<int>(prefix)); 862 int whole_path_limit = std::max(0, MAX_PATH - 1 - static_cast<int>(prefix));
860 return std::min(whole_path_limit, static_cast<int>(max_length)); 863 return std::min(whole_path_limit, static_cast<int>(max_length));
861 } 864 }
862 865
863 } // namespace file_util 866 } // namespace file_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698