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

Side by Side Diff: base/file_util_posix.cc

Issue 115773: Prototype implementation of zygotes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | « base/file_descriptor_shuffle.cc ('k') | base/logging.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <fnmatch.h> 10 #include <fnmatch.h>
11 #include <fts.h> 11 #include <fts.h>
12 #include <libgen.h> 12 #include <libgen.h>
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <string.h> 14 #include <string.h>
15 #include <sys/errno.h> 15 #include <sys/errno.h>
16 #include <sys/mman.h> 16 #include <sys/mman.h>
17 #include <sys/stat.h> 17 #include <sys/stat.h>
18 #include <sys/types.h> 18 #include <sys/types.h>
19 #include <time.h> 19 #include <time.h>
20 #include <unistd.h> 20 #include <unistd.h>
21 21
22 #include <fstream> 22 #include <fstream>
23 23
24 #include "base/basictypes.h" 24 #include "base/basictypes.h"
25 #include "base/eintr_wrapper.h" 25 #include "base/eintr_wrapper.h"
26 #include "base/file_path.h" 26 #include "base/file_path.h"
27 #include "base/logging.h" 27 #include "base/logging.h"
28 #include "base/string_util.h" 28 #include "base/string_util.h"
29 #include "base/time.h" 29 #include "base/time.h"
30 #include "base/zygote_manager.h"
30 31
31 namespace file_util { 32 namespace file_util {
32 33
33 #if defined(GOOGLE_CHROME_BUILD) 34 #if defined(GOOGLE_CHROME_BUILD)
34 static const char* kTempFileName = "com.google.chrome.XXXXXX"; 35 static const char* kTempFileName = "com.google.chrome.XXXXXX";
35 #else 36 #else
36 static const char* kTempFileName = "org.chromium.XXXXXX"; 37 static const char* kTempFileName = "org.chromium.XXXXXX";
37 #endif 38 #endif
38 39
39 std::wstring GetDirectoryFromPath(const std::wstring& path) { 40 std::wstring GetDirectoryFromPath(const std::wstring& path) {
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 /////////////////////////////////////////////// 619 ///////////////////////////////////////////////
619 // MemoryMappedFile 620 // MemoryMappedFile
620 621
621 MemoryMappedFile::MemoryMappedFile() 622 MemoryMappedFile::MemoryMappedFile()
622 : file_(-1), 623 : file_(-1),
623 data_(NULL), 624 data_(NULL),
624 length_(0) { 625 length_(0) {
625 } 626 }
626 627
627 bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) { 628 bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
628 file_ = open(file_name.value().c_str(), O_RDONLY); 629 file_ = -1;
630 #if defined(OS_LINUX)
631 base::ZygoteManager* zm = base::ZygoteManager::Get();
632 if (zm) {
633 file_ = zm->OpenFile(file_name.value().c_str());
634 if (file_ == -1) {
635 LOG(INFO) << "Zygote manager can't open " << file_name.value()
636 << ", retrying locally";
637 }
638 }
639 #endif // defined(OS_LINUX)
629 if (file_ == -1) 640 if (file_ == -1)
641 file_ = open(file_name.value().c_str(), O_RDONLY);
642 if (file_ == -1) {
643 LOG(ERROR) << "Couldn't open " << file_name.value();
630 return false; 644 return false;
645 }
631 646
632 struct stat file_stat; 647 struct stat file_stat;
633 if (fstat(file_, &file_stat) == -1) 648 if (fstat(file_, &file_stat) == -1) {
649 LOG(ERROR) << "Couldn't fstat " << file_name.value() << ", errno " << errno;
634 return false; 650 return false;
651 }
635 length_ = file_stat.st_size; 652 length_ = file_stat.st_size;
636 653
637 data_ = static_cast<uint8*>( 654 data_ = static_cast<uint8*>(
638 mmap(NULL, length_, PROT_READ, MAP_SHARED, file_, 0)); 655 mmap(NULL, length_, PROT_READ, MAP_SHARED, file_, 0));
639 if (data_ == MAP_FAILED) 656 if (data_ == MAP_FAILED)
640 data_ = NULL; 657 LOG(ERROR) << "Couldn't mmap " << file_name.value() << ", errno " << errno;
641 return data_ != NULL; 658
659 return data_ != MAP_FAILED;
642 } 660 }
643 661
644 void MemoryMappedFile::CloseHandles() { 662 void MemoryMappedFile::CloseHandles() {
645 if (data_ != NULL) 663 if (data_ != NULL)
646 munmap(data_, length_); 664 munmap(data_, length_);
647 if (file_ != -1) 665 if (file_ != -1)
648 close(file_); 666 close(file_);
649 667
650 data_ = NULL; 668 data_ = NULL;
651 length_ = 0; 669 length_ = 0;
652 file_ = -1; 670 file_ = -1;
653 } 671 }
654 672
655 } // namespace file_util 673 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_descriptor_shuffle.cc ('k') | base/logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698