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 <propvarutil.h> | 8 #include <propvarutil.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 <time.h> | 12 #include <time.h> |
13 | 13 |
14 #include <limits> | 14 #include <limits> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/file_path.h" | 17 #include "base/file_path.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
20 #include "base/process_util.h" | |
20 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
21 #include "base/string_util.h" | 22 #include "base/string_util.h" |
22 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
23 #include "base/time.h" | 24 #include "base/time.h" |
24 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
25 #include "base/win/pe_image.h" | 26 #include "base/win/pe_image.h" |
26 #include "base/win/scoped_comptr.h" | 27 #include "base/win/scoped_comptr.h" |
27 #include "base/win/scoped_handle.h" | 28 #include "base/win/scoped_handle.h" |
28 #include "base/win/win_util.h" | 29 #include "base/win/win_util.h" |
29 #include "base/win/windows_version.h" | 30 #include "base/win/windows_version.h" |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 base::ThreadRestrictions::AssertIOAllowed(); | 553 base::ThreadRestrictions::AssertIOAllowed(); |
553 | 554 |
554 FilePath path_to_create; | 555 FilePath path_to_create; |
555 srand(static_cast<uint32>(time(NULL))); | 556 srand(static_cast<uint32>(time(NULL))); |
556 | 557 |
557 for (int count = 0; count < 50; ++count) { | 558 for (int count = 0; count < 50; ++count) { |
558 // Try create a new temporary directory with random generated name. If | 559 // Try create a new temporary directory with random generated name. If |
559 // the one exists, keep trying another path name until we reach some limit. | 560 // the one exists, keep trying another path name until we reach some limit. |
560 string16 new_dir_name; | 561 string16 new_dir_name; |
561 new_dir_name.assign(prefix); | 562 new_dir_name.assign(prefix); |
563 new_dir_name.append(base::IntToString16(::base::GetCurrentProcId())); | |
564 new_dir_name.append(FILE_PATH_LITERAL("_")); | |
brettw
2012/05/01 04:51:11
I'd do "new_dir_name.push_back('_');" which will w
Dirk Pranke
2012/05/01 19:01:23
Just goes to show how weak my c++ is :). Done.
| |
562 new_dir_name.append(base::IntToString16(rand() % kint16max)); | 565 new_dir_name.append(base::IntToString16(rand() % kint16max)); |
563 | 566 |
564 path_to_create = base_dir.Append(new_dir_name); | 567 path_to_create = base_dir.Append(new_dir_name); |
565 if (::CreateDirectory(path_to_create.value().c_str(), NULL)) { | 568 if (::CreateDirectory(path_to_create.value().c_str(), NULL)) { |
566 *new_dir = path_to_create; | 569 *new_dir = path_to_create; |
567 return true; | 570 return true; |
568 } | 571 } |
569 } | 572 } |
570 | 573 |
571 return false; | 574 return false; |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1106 HANDLE cp = GetCurrentProcess(); | 1109 HANDLE cp = GetCurrentProcess(); |
1107 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { | 1110 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { |
1108 *nt_path = FilePath(mapped_file_path); | 1111 *nt_path = FilePath(mapped_file_path); |
1109 success = true; | 1112 success = true; |
1110 } | 1113 } |
1111 ::UnmapViewOfFile(file_view); | 1114 ::UnmapViewOfFile(file_view); |
1112 return success; | 1115 return success; |
1113 } | 1116 } |
1114 | 1117 |
1115 } // namespace file_util | 1118 } // namespace file_util |
OLD | NEW |