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

Side by Side Diff: base/file_util_win.cc

Issue 10264026: Change CreateTemporaryDirInDir to be "more unique" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use push_back() instead of append() Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.push_back('_');
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698