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

Side by Side Diff: base/file_util_win.cc

Issue 1582022: Unpack extensions inside chrome's directory. (Closed)
Patch Set: Final rebase. Created 10 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
« no previous file with comments | « base/file_util_unittest.cc ('k') | base/scoped_temp_dir.h » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 PLOG(WARNING) << "Failed to get long path name for " << temp_name; 493 PLOG(WARNING) << "Failed to get long path name for " << temp_name;
494 return false; 494 return false;
495 } 495 }
496 496
497 std::wstring temp_file_str; 497 std::wstring temp_file_str;
498 temp_file_str.assign(temp_name, path_len); 498 temp_file_str.assign(temp_name, path_len);
499 *temp_file = FilePath(temp_file_str); 499 *temp_file = FilePath(temp_file_str);
500 return true; 500 return true;
501 } 501 }
502 502
503 bool CreateNewTempDirectory(const FilePath::StringType& prefix, 503 bool CreateTemporaryDirInDir(const FilePath& base_dir,
504 FilePath* new_temp_path) { 504 const FilePath::StringType& prefix,
505 FilePath system_temp_dir; 505 FilePath* new_dir) {
506 if (!GetTempDir(&system_temp_dir))
507 return false;
508
509 FilePath path_to_create; 506 FilePath path_to_create;
510 srand(static_cast<uint32>(time(NULL))); 507 srand(static_cast<uint32>(time(NULL)));
511 508
512 int count = 0; 509 int count = 0;
513 while (count < 50) { 510 while (count < 50) {
514 // Try create a new temporary directory with random generated name. If 511 // Try create a new temporary directory with random generated name. If
515 // the one exists, keep trying another path name until we reach some limit. 512 // the one exists, keep trying another path name until we reach some limit.
516 path_to_create = system_temp_dir; 513 path_to_create = base_dir;
514
517 std::wstring new_dir_name; 515 std::wstring new_dir_name;
518 new_dir_name.assign(prefix); 516 new_dir_name.assign(prefix);
519 new_dir_name.append(IntToWString(rand() % kint16max)); 517 new_dir_name.append(IntToWString(rand() % kint16max));
518
520 path_to_create = path_to_create.Append(new_dir_name); 519 path_to_create = path_to_create.Append(new_dir_name);
521
522 if (::CreateDirectory(path_to_create.value().c_str(), NULL)) 520 if (::CreateDirectory(path_to_create.value().c_str(), NULL))
523 break; 521 break;
524 count++; 522 count++;
525 } 523 }
526 524
527 if (count == 50) { 525 if (count == 50) {
528 return false; 526 return false;
529 } 527 }
530 528
531 *new_temp_path = path_to_create; 529 *new_dir = path_to_create;
532 return true; 530 return true;
533 } 531 }
534 532
533 bool CreateNewTempDirectory(const FilePath::StringType& prefix,
534 FilePath* new_temp_path) {
535 FilePath system_temp_dir;
536 if (!GetTempDir(&system_temp_dir))
537 return false;
538
539 return CreateTemporaryDirInDir(system_temp_dir, prefix, new_temp_path);
540 }
541
535 bool CreateDirectory(const FilePath& full_path) { 542 bool CreateDirectory(const FilePath& full_path) {
536 // If the path exists, we've succeeded if it's a directory, failed otherwise. 543 // If the path exists, we've succeeded if it's a directory, failed otherwise.
537 const wchar_t* full_path_str = full_path.value().c_str(); 544 const wchar_t* full_path_str = full_path.value().c_str();
538 DWORD fileattr = ::GetFileAttributes(full_path_str); 545 DWORD fileattr = ::GetFileAttributes(full_path_str);
539 if (fileattr != INVALID_FILE_ATTRIBUTES) { 546 if (fileattr != INVALID_FILE_ATTRIBUTES) {
540 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) { 547 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
541 DLOG(INFO) << "CreateDirectory(" << full_path_str << "), " << 548 DLOG(INFO) << "CreateDirectory(" << full_path_str << "), " <<
542 "directory already exists."; 549 "directory already exists.";
543 return true; 550 return true;
544 } else { 551 } else {
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 } 877 }
871 878
872 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, 879 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info,
873 const base::Time& cutoff_time) { 880 const base::Time& cutoff_time) {
874 long result = CompareFileTime(&find_info.ftLastWriteTime, 881 long result = CompareFileTime(&find_info.ftLastWriteTime,
875 &cutoff_time.ToFileTime()); 882 &cutoff_time.ToFileTime());
876 return result == 1 || result == 0; 883 return result == 1 || result == 0;
877 } 884 }
878 885
879 } // namespace file_util 886 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_unittest.cc ('k') | base/scoped_temp_dir.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698