OLD | NEW |
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path); | 247 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path); |
248 if (path_len >= MAX_PATH || path_len <= 0) | 248 if (path_len >= MAX_PATH || path_len <= 0) |
249 return false; | 249 return false; |
250 // TODO(evanm): the old behavior of this function was to always strip the | 250 // TODO(evanm): the old behavior of this function was to always strip the |
251 // trailing slash. We duplicate this here, but it shouldn't be necessary | 251 // trailing slash. We duplicate this here, but it shouldn't be necessary |
252 // when everyone is using the appropriate FilePath APIs. | 252 // when everyone is using the appropriate FilePath APIs. |
253 *path = FilePath(temp_path).StripTrailingSeparators(); | 253 *path = FilePath(temp_path).StripTrailingSeparators(); |
254 return true; | 254 return true; |
255 } | 255 } |
256 | 256 |
257 bool GetShmemTempDir(bool executable, FilePath* path) { | |
258 return GetTempDir(path); | |
259 } | |
260 | |
261 FilePath GetHomeDir() { | 257 FilePath GetHomeDir() { |
262 char16 result[MAX_PATH]; | 258 char16 result[MAX_PATH]; |
263 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, | 259 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, |
264 result)) && | 260 result)) && |
265 result[0]) { | 261 result[0]) { |
266 return FilePath(result); | 262 return FilePath(result); |
267 } | 263 } |
268 | 264 |
269 // Fall back to the temporary directory on failure. | 265 // Fall back to the temporary directory on failure. |
270 FilePath temp; | 266 FilePath temp; |
(...skipping 13 matching lines...) Expand all Loading... |
284 return false; | 280 return false; |
285 | 281 |
286 if (CreateTemporaryFileInDir(*path, &temp_file)) { | 282 if (CreateTemporaryFileInDir(*path, &temp_file)) { |
287 *path = temp_file; | 283 *path = temp_file; |
288 return true; | 284 return true; |
289 } | 285 } |
290 | 286 |
291 return false; | 287 return false; |
292 } | 288 } |
293 | 289 |
294 FILE* CreateAndOpenTemporaryShmemFile(FilePath* path, bool executable) { | |
295 ThreadRestrictions::AssertIOAllowed(); | |
296 return CreateAndOpenTemporaryFile(path); | |
297 } | |
298 | |
299 // On POSIX we have semantics to create and open a temporary file | 290 // On POSIX we have semantics to create and open a temporary file |
300 // atomically. | 291 // atomically. |
301 // TODO(jrg): is there equivalent call to use on Windows instead of | 292 // TODO(jrg): is there equivalent call to use on Windows instead of |
302 // going 2-step? | 293 // going 2-step? |
303 FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) { | 294 FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) { |
304 ThreadRestrictions::AssertIOAllowed(); | 295 ThreadRestrictions::AssertIOAllowed(); |
305 if (!CreateTemporaryFileInDir(dir, path)) { | 296 if (!CreateTemporaryFileInDir(dir, path)) { |
306 return NULL; | 297 return NULL; |
307 } | 298 } |
308 // Open file in binary mode, to avoid problems with fwrite. On Windows | 299 // Open file in binary mode, to avoid problems with fwrite. On Windows |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 // Like Move, this function is not transactional, so we just | 780 // Like Move, this function is not transactional, so we just |
790 // leave the copied bits behind if deleting from_path fails. | 781 // leave the copied bits behind if deleting from_path fails. |
791 // If to_path exists previously then we have already overwritten | 782 // If to_path exists previously then we have already overwritten |
792 // it by now, we don't get better off by deleting the new bits. | 783 // it by now, we don't get better off by deleting the new bits. |
793 } | 784 } |
794 return false; | 785 return false; |
795 } | 786 } |
796 | 787 |
797 } // namespace internal | 788 } // namespace internal |
798 } // namespace base | 789 } // namespace base |
OLD | NEW |