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

Side by Side Diff: webrtc/base/win32filesystem.cc

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. Created 3 years, 11 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
« no previous file with comments | « webrtc/base/win32.cc ('k') | webrtc/base/win32socketserver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), NULL)) { 69 if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), NULL)) {
70 delete fs; 70 delete fs;
71 fs = NULL; 71 fs = NULL;
72 } 72 }
73 return fs; 73 return fs;
74 } 74 }
75 75
76 bool Win32Filesystem::DeleteFile(const Pathname &filename) { 76 bool Win32Filesystem::DeleteFile(const Pathname &filename) {
77 LOG(LS_INFO) << "Deleting file " << filename.pathname(); 77 LOG(LS_INFO) << "Deleting file " << filename.pathname();
78 if (!IsFile(filename)) { 78 if (!IsFile(filename)) {
79 ASSERT(IsFile(filename)); 79 RTC_DCHECK(IsFile(filename));
80 return false; 80 return false;
81 } 81 }
82 return ::DeleteFile(ToUtf16(filename.pathname()).c_str()) != 0; 82 return ::DeleteFile(ToUtf16(filename.pathname()).c_str()) != 0;
83 } 83 }
84 84
85 bool Win32Filesystem::DeleteEmptyFolder(const Pathname &folder) { 85 bool Win32Filesystem::DeleteEmptyFolder(const Pathname &folder) {
86 LOG(LS_INFO) << "Deleting folder " << folder.pathname(); 86 LOG(LS_INFO) << "Deleting folder " << folder.pathname();
87 87
88 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1); 88 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1);
89 return ::RemoveDirectory(ToUtf16(no_slash).c_str()) != 0; 89 return ::RemoveDirectory(ToUtf16(no_slash).c_str()) != 0;
90 } 90 }
91 91
92 bool Win32Filesystem::GetTemporaryFolder(Pathname &pathname, bool create, 92 bool Win32Filesystem::GetTemporaryFolder(Pathname &pathname, bool create,
93 const std::string *append) { 93 const std::string *append) {
94 wchar_t buffer[MAX_PATH + 1]; 94 wchar_t buffer[MAX_PATH + 1];
95 if (!::GetTempPath(arraysize(buffer), buffer)) 95 if (!::GetTempPath(arraysize(buffer), buffer))
96 return false; 96 return false;
97 if (!IsCurrentProcessLowIntegrity() && 97 if (!IsCurrentProcessLowIntegrity() &&
98 !::GetLongPathName(buffer, buffer, arraysize(buffer))) 98 !::GetLongPathName(buffer, buffer, arraysize(buffer)))
99 return false; 99 return false;
100 size_t len = strlen(buffer); 100 size_t len = strlen(buffer);
101 if ((len > 0) && (buffer[len-1] != '\\')) { 101 if ((len > 0) && (buffer[len-1] != '\\')) {
102 len += strcpyn(buffer + len, arraysize(buffer) - len, L"\\"); 102 len += strcpyn(buffer + len, arraysize(buffer) - len, L"\\");
103 } 103 }
104 if (len >= arraysize(buffer) - 1) 104 if (len >= arraysize(buffer) - 1)
105 return false; 105 return false;
106 pathname.clear(); 106 pathname.clear();
107 pathname.SetFolder(ToUtf8(buffer)); 107 pathname.SetFolder(ToUtf8(buffer));
108 if (append != NULL) { 108 if (append != NULL) {
109 ASSERT(!append->empty()); 109 RTC_DCHECK(!append->empty());
110 pathname.AppendFolder(*append); 110 pathname.AppendFolder(*append);
111 } 111 }
112 return !create || CreateFolder(pathname); 112 return !create || CreateFolder(pathname);
113 } 113 }
114 114
115 std::string Win32Filesystem::TempFilename(const Pathname &dir, 115 std::string Win32Filesystem::TempFilename(const Pathname &dir,
116 const std::string &prefix) { 116 const std::string &prefix) {
117 wchar_t filename[MAX_PATH]; 117 wchar_t filename[MAX_PATH];
118 if (::GetTempFileName(ToUtf16(dir.pathname()).c_str(), 118 if (::GetTempFileName(ToUtf16(dir.pathname()).c_str(),
119 ToUtf16(prefix).c_str(), 0, filename) != 0) 119 ToUtf16(prefix).c_str(), 0, filename) != 0)
120 return ToUtf8(filename); 120 return ToUtf8(filename);
121 RTC_NOTREACHED(); 121 RTC_NOTREACHED();
122 return ""; 122 return "";
123 } 123 }
124 124
125 bool Win32Filesystem::MoveFile(const Pathname &old_path, 125 bool Win32Filesystem::MoveFile(const Pathname &old_path,
126 const Pathname &new_path) { 126 const Pathname &new_path) {
127 if (!IsFile(old_path)) { 127 if (!IsFile(old_path)) {
128 ASSERT(IsFile(old_path)); 128 RTC_DCHECK(IsFile(old_path));
129 return false; 129 return false;
130 } 130 }
131 LOG(LS_INFO) << "Moving " << old_path.pathname() 131 LOG(LS_INFO) << "Moving " << old_path.pathname()
132 << " to " << new_path.pathname(); 132 << " to " << new_path.pathname();
133 return ::MoveFile(ToUtf16(old_path.pathname()).c_str(), 133 return ::MoveFile(ToUtf16(old_path.pathname()).c_str(),
134 ToUtf16(new_path.pathname()).c_str()) != 0; 134 ToUtf16(new_path.pathname()).c_str()) != 0;
135 } 135 }
136 136
137 bool Win32Filesystem::IsFolder(const Pathname &path) { 137 bool Win32Filesystem::IsFolder(const Pathname &path) {
138 WIN32_FILE_ATTRIBUTE_DATA data = {0}; 138 WIN32_FILE_ATTRIBUTE_DATA data = {0};
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 bool Win32Filesystem::GetAppPathname(Pathname* path) { 211 bool Win32Filesystem::GetAppPathname(Pathname* path) {
212 TCHAR buffer[MAX_PATH + 1]; 212 TCHAR buffer[MAX_PATH + 1];
213 if (0 == ::GetModuleFileName(NULL, buffer, arraysize(buffer))) 213 if (0 == ::GetModuleFileName(NULL, buffer, arraysize(buffer)))
214 return false; 214 return false;
215 path->SetPathname(ToUtf8(buffer)); 215 path->SetPathname(ToUtf8(buffer));
216 return true; 216 return true;
217 } 217 }
218 218
219 bool Win32Filesystem::GetAppDataFolder(Pathname* path, bool per_user) { 219 bool Win32Filesystem::GetAppDataFolder(Pathname* path, bool per_user) {
220 ASSERT(!organization_name_.empty()); 220 RTC_DCHECK(!organization_name_.empty());
221 ASSERT(!application_name_.empty()); 221 RTC_DCHECK(!application_name_.empty());
222 TCHAR buffer[MAX_PATH + 1]; 222 TCHAR buffer[MAX_PATH + 1];
223 int csidl = per_user ? CSIDL_LOCAL_APPDATA : CSIDL_COMMON_APPDATA; 223 int csidl = per_user ? CSIDL_LOCAL_APPDATA : CSIDL_COMMON_APPDATA;
224 if (!::SHGetSpecialFolderPath(NULL, buffer, csidl, TRUE)) 224 if (!::SHGetSpecialFolderPath(NULL, buffer, csidl, TRUE))
225 return false; 225 return false;
226 if (!IsCurrentProcessLowIntegrity() && 226 if (!IsCurrentProcessLowIntegrity() &&
227 !::GetLongPathName(buffer, buffer, arraysize(buffer))) 227 !::GetLongPathName(buffer, buffer, arraysize(buffer)))
228 return false; 228 return false;
229 size_t len = strcatn(buffer, arraysize(buffer), __T("\\")); 229 size_t len = strcatn(buffer, arraysize(buffer), __T("\\"));
230 len += strcpyn(buffer + len, arraysize(buffer) - len, 230 len += strcpyn(buffer + len, arraysize(buffer) - len,
231 ToUtf16(organization_name_).c_str()); 231 ToUtf16(organization_name_).c_str());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 UINT drive_type = ::GetDriveType(target_drive); 275 UINT drive_type = ::GetDriveType(target_drive);
276 if ((drive_type == DRIVE_REMOTE) || (drive_type == DRIVE_UNKNOWN)) { 276 if ((drive_type == DRIVE_REMOTE) || (drive_type == DRIVE_UNKNOWN)) {
277 LOG(LS_VERBOSE) << "Remote or unknown drive: " << drive; 277 LOG(LS_VERBOSE) << "Remote or unknown drive: " << drive;
278 return false; 278 return false;
279 } 279 }
280 280
281 int64_t total_number_of_bytes; // receives the number of bytes on disk 281 int64_t total_number_of_bytes; // receives the number of bytes on disk
282 int64_t total_number_of_free_bytes; // receives the free bytes on disk 282 int64_t total_number_of_free_bytes; // receives the free bytes on disk
283 // make sure things won't change in 64 bit machine 283 // make sure things won't change in 64 bit machine
284 // TODO replace with compile time assert 284 // TODO replace with compile time assert
285 ASSERT(sizeof(ULARGE_INTEGER) == sizeof(uint64_t)); // NOLINT 285 RTC_DCHECK(sizeof(ULARGE_INTEGER) == sizeof(uint64_t)); // NOLINT
286 if (::GetDiskFreeSpaceEx(target_drive, 286 if (::GetDiskFreeSpaceEx(target_drive,
287 (PULARGE_INTEGER)free_bytes, 287 (PULARGE_INTEGER)free_bytes,
288 (PULARGE_INTEGER)&total_number_of_bytes, 288 (PULARGE_INTEGER)&total_number_of_bytes,
289 (PULARGE_INTEGER)&total_number_of_free_bytes)) { 289 (PULARGE_INTEGER)&total_number_of_free_bytes)) {
290 return true; 290 return true;
291 } else { 291 } else {
292 LOG(LS_VERBOSE) << "GetDiskFreeSpaceEx returns error."; 292 LOG(LS_VERBOSE) << "GetDiskFreeSpaceEx returns error.";
293 return false; 293 return false;
294 } 294 }
295 } 295 }
296 296
297 } // namespace rtc 297 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/win32.cc ('k') | webrtc/base/win32socketserver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698