| 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <psapi.h> | 9 #include <psapi.h> |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| 11 #include <shlobj.h> | 11 #include <shlobj.h> |
| 12 #include <stdint.h> |
| 12 #include <time.h> | 13 #include <time.h> |
| 13 | 14 |
| 14 #include <algorithm> | 15 #include <algorithm> |
| 15 #include <limits> | 16 #include <limits> |
| 16 #include <string> | 17 #include <string> |
| 17 | 18 |
| 18 #include "base/files/file_enumerator.h" | 19 #include "base/files/file_enumerator.h" |
| 19 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
| 20 #include "base/logging.h" | 21 #include "base/logging.h" |
| 21 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 353 |
| 353 FilePath path_to_create; | 354 FilePath path_to_create; |
| 354 | 355 |
| 355 for (int count = 0; count < 50; ++count) { | 356 for (int count = 0; count < 50; ++count) { |
| 356 // Try create a new temporary directory with random generated name. If | 357 // Try create a new temporary directory with random generated name. If |
| 357 // the one exists, keep trying another path name until we reach some limit. | 358 // the one exists, keep trying another path name until we reach some limit. |
| 358 string16 new_dir_name; | 359 string16 new_dir_name; |
| 359 new_dir_name.assign(prefix); | 360 new_dir_name.assign(prefix); |
| 360 new_dir_name.append(IntToString16(GetCurrentProcId())); | 361 new_dir_name.append(IntToString16(GetCurrentProcId())); |
| 361 new_dir_name.push_back('_'); | 362 new_dir_name.push_back('_'); |
| 362 new_dir_name.append(IntToString16(RandInt(0, kint16max))); | 363 new_dir_name.append( |
| 364 IntToString16(RandInt(0, std::numeric_limits<int16_t>::max()))); |
| 363 | 365 |
| 364 path_to_create = base_dir.Append(new_dir_name); | 366 path_to_create = base_dir.Append(new_dir_name); |
| 365 if (::CreateDirectory(path_to_create.value().c_str(), NULL)) { | 367 if (::CreateDirectory(path_to_create.value().c_str(), NULL)) { |
| 366 *new_dir = path_to_create; | 368 *new_dir = path_to_create; |
| 367 return true; | 369 return true; |
| 368 } | 370 } |
| 369 } | 371 } |
| 370 | 372 |
| 371 return false; | 373 return false; |
| 372 } | 374 } |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 // Like Move, this function is not transactional, so we just | 813 // Like Move, this function is not transactional, so we just |
| 812 // leave the copied bits behind if deleting from_path fails. | 814 // leave the copied bits behind if deleting from_path fails. |
| 813 // If to_path exists previously then we have already overwritten | 815 // If to_path exists previously then we have already overwritten |
| 814 // it by now, we don't get better off by deleting the new bits. | 816 // it by now, we don't get better off by deleting the new bits. |
| 815 } | 817 } |
| 816 return false; | 818 return false; |
| 817 } | 819 } |
| 818 | 820 |
| 819 } // namespace internal | 821 } // namespace internal |
| 820 } // namespace base | 822 } // namespace base |
| OLD | NEW |