| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { | 257 bool GetShmemTempDir(bool executable, FilePath* path) { |
| 258 return GetTempDir(path); | 258 return GetTempDir(path); |
| 259 } | 259 } |
| 260 | 260 |
| 261 FilePath GetHomeDir() { |
| 262 char16 result[MAX_PATH]; |
| 263 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, |
| 264 result)) && |
| 265 result[0]) { |
| 266 return FilePath(result); |
| 267 } |
| 268 |
| 269 // Fall back to the temporary directory on failure. |
| 270 FilePath temp; |
| 271 if (GetTempDir(&temp)) |
| 272 return temp; |
| 273 |
| 274 // Last resort. |
| 275 return FilePath(L"C:\\"); |
| 276 } |
| 277 |
| 261 bool CreateTemporaryFile(FilePath* path) { | 278 bool CreateTemporaryFile(FilePath* path) { |
| 262 ThreadRestrictions::AssertIOAllowed(); | 279 ThreadRestrictions::AssertIOAllowed(); |
| 263 | 280 |
| 264 FilePath temp_file; | 281 FilePath temp_file; |
| 265 | 282 |
| 266 if (!GetTempDir(path)) | 283 if (!GetTempDir(path)) |
| 267 return false; | 284 return false; |
| 268 | 285 |
| 269 if (CreateTemporaryFileInDir(*path, &temp_file)) { | 286 if (CreateTemporaryFileInDir(*path, &temp_file)) { |
| 270 *path = temp_file; | 287 *path = temp_file; |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // Like Move, this function is not transactional, so we just | 804 // Like Move, this function is not transactional, so we just |
| 788 // leave the copied bits behind if deleting from_path fails. | 805 // leave the copied bits behind if deleting from_path fails. |
| 789 // If to_path exists previously then we have already overwritten | 806 // If to_path exists previously then we have already overwritten |
| 790 // it by now, we don't get better off by deleting the new bits. | 807 // it by now, we don't get better off by deleting the new bits. |
| 791 } | 808 } |
| 792 return false; | 809 return false; |
| 793 } | 810 } |
| 794 | 811 |
| 795 } // namespace internal | 812 } // namespace internal |
| 796 } // namespace base | 813 } // namespace base |
| OLD | NEW |