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

Side by Side Diff: net/disk_cache/backend_impl.cc

Issue 8843: Add write and read/write support to FileStream (renamed from FileInputStream)... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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 | « net/build/net_unittests.vcproj ('k') | net/disk_cache/block_files.cc » ('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 "net/disk_cache/backend_impl.h" 5 #include "net/disk_cache/backend_impl.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/histogram.h" 8 #include "base/histogram.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 bool BackendImpl::CreateExternalFile(Addr* address) { 543 bool BackendImpl::CreateExternalFile(Addr* address) {
544 int file_number = data_->header.last_file + 1; 544 int file_number = data_->header.last_file + 1;
545 Addr file_address(0); 545 Addr file_address(0);
546 bool success = false; 546 bool success = false;
547 for (int i = 0; (i < 0x0fffffff) && !success; i++, file_number++) { 547 for (int i = 0; (i < 0x0fffffff) && !success; i++, file_number++) {
548 if (!file_address.SetFileNumber(file_number)) { 548 if (!file_address.SetFileNumber(file_number)) {
549 file_number = 1; 549 file_number = 1;
550 continue; 550 continue;
551 } 551 }
552 std::wstring name = GetFileName(file_address); 552 std::wstring name = GetFileName(file_address);
553 scoped_refptr<disk_cache::File> file( 553 int flags = base::PLATFORM_FILE_READ |
554 new disk_cache::File(CreateOSFile(name.c_str(), OS_FILE_READ | 554 base::PLATFORM_FILE_WRITE |
555 OS_FILE_WRITE |OS_FILE_SHARE_READ | OS_FILE_CREATE, NULL))); 555 base::PLATFORM_FILE_CREATE |
556 base::PLATFORM_FILE_EXCLUSIVE_WRITE;
557 scoped_refptr<disk_cache::File> file(new disk_cache::File(
558 base::CreatePlatformFile(name.c_str(), flags, NULL)));
556 if (!file->IsValid()) 559 if (!file->IsValid())
557 continue; 560 continue;
558 561
559 success = true; 562 success = true;
560 } 563 }
561 564
562 DCHECK(success); 565 DCHECK(success);
563 if (!success) 566 if (!success)
564 return false; 567 return false;
565 568
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 744
742 return file->SetLength(GetIndexSize(header.table_len)); 745 return file->SetLength(GetIndexSize(header.table_len));
743 } 746 }
744 747
745 bool BackendImpl::InitBackingStore(bool* file_created) { 748 bool BackendImpl::InitBackingStore(bool* file_created) {
746 file_util::CreateDirectory(path_); 749 file_util::CreateDirectory(path_);
747 750
748 std::wstring index_name(path_); 751 std::wstring index_name(path_);
749 file_util::AppendToPath(&index_name, kIndexName); 752 file_util::AppendToPath(&index_name, kIndexName);
750 753
754 int flags = base::PLATFORM_FILE_READ |
755 base::PLATFORM_FILE_WRITE |
756 base::PLATFORM_FILE_OPEN_ALWAYS |
757 base::PLATFORM_FILE_EXCLUSIVE_WRITE;
751 scoped_refptr<disk_cache::File> file(new disk_cache::File( 758 scoped_refptr<disk_cache::File> file(new disk_cache::File(
752 CreateOSFile(index_name.c_str(), OS_FILE_READ | OS_FILE_WRITE | 759 base::CreatePlatformFile(index_name.c_str(), flags, file_created)));
753 OS_FILE_SHARE_READ | OS_FILE_OPEN_ALWAYS, file_created)));
754 760
755 if (!file->IsValid()) 761 if (!file->IsValid())
756 return false; 762 return false;
757 763
758 bool ret = true; 764 bool ret = true;
759 if (*file_created) 765 if (*file_created)
760 ret = CreateBackingStore(file); 766 ret = CreateBackingStore(file);
761 767
762 file = NULL; 768 file = NULL;
763 if (!ret) 769 if (!ret)
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 1123
1118 return num_dirty; 1124 return num_dirty;
1119 } 1125 }
1120 1126
1121 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { 1127 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) {
1122 RankingsNode* rankings = cache_entry->rankings()->Data(); 1128 RankingsNode* rankings = cache_entry->rankings()->Data();
1123 return !rankings->pointer; 1129 return !rankings->pointer;
1124 } 1130 }
1125 1131
1126 } // namespace disk_cache 1132 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/build/net_unittests.vcproj ('k') | net/disk_cache/block_files.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698