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

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

Issue 15203004: Disk cache: Reference CL for the implementation of file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: IndexTable review Created 7 years 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/disk_cache/file_lock.h ('k') | net/disk_cache/in_flight_backend_io.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) 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 "net/disk_cache/file.h" 5 #include "net/disk_cache/file.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 26 matching lines...) Expand all
37 static base::LazyInstance<CompletionHandler> g_completion_handler = 37 static base::LazyInstance<CompletionHandler> g_completion_handler =
38 LAZY_INSTANCE_INITIALIZER; 38 LAZY_INSTANCE_INITIALIZER;
39 39
40 void CompletionHandler::OnIOCompleted(MessageLoopForIO::IOContext* context, 40 void CompletionHandler::OnIOCompleted(MessageLoopForIO::IOContext* context,
41 DWORD actual_bytes, DWORD error) { 41 DWORD actual_bytes, DWORD error) {
42 MyOverlapped* data = reinterpret_cast<MyOverlapped*>(context); 42 MyOverlapped* data = reinterpret_cast<MyOverlapped*>(context);
43 43
44 if (error) { 44 if (error) {
45 DCHECK(!actual_bytes); 45 DCHECK(!actual_bytes);
46 actual_bytes = static_cast<DWORD>(net::ERR_CACHE_READ_FAILURE); 46 actual_bytes = static_cast<DWORD>(net::ERR_CACHE_READ_FAILURE);
47 NOTREACHED();
48 } 47 }
49 48
50 if (data->callback_) 49 if (data->callback_)
51 data->callback_->OnFileIOComplete(static_cast<int>(actual_bytes)); 50 data->callback_->OnFileIOComplete(static_cast<int>(actual_bytes));
52 51
53 delete data; 52 delete data;
54 } 53 }
55 54
56 MyOverlapped::MyOverlapped(disk_cache::File* file, size_t offset, 55 MyOverlapped::MyOverlapped(disk_cache::File* file, size_t offset,
57 disk_cache::FileIOCallback* callback) { 56 disk_cache::FileIOCallback* callback) {
58 memset(this, 0, sizeof(*this)); 57 memset(this, 0, sizeof(*this));
59 context_.handler = g_completion_handler.Pointer(); 58 context_.handler = g_completion_handler.Pointer();
60 context_.overlapped.Offset = static_cast<DWORD>(offset); 59 context_.overlapped.Offset = static_cast<DWORD>(offset);
61 file_ = file; 60 file_ = file;
62 callback_ = callback; 61 callback_ = callback;
63 } 62 }
64 63
65 } // namespace 64 } // namespace
66 65
67 namespace disk_cache { 66 namespace disk_cache {
68 67
69 File::File(base::PlatformFile file) 68 File::File(base::PlatformFile file)
70 : init_(true), mixed_(true), platform_file_(INVALID_HANDLE_VALUE), 69 : init_(true),
70 mixed_(true),
71 force_creation_(false),
72 platform_file_(INVALID_HANDLE_VALUE),
71 sync_platform_file_(file) { 73 sync_platform_file_(file) {
72 } 74 }
73 75
74 bool File::Init(const base::FilePath& name) { 76 bool File::Init(const base::FilePath& name) {
75 DCHECK(!init_); 77 DCHECK(!init_);
76 if (init_) 78 if (init_)
77 return false; 79 return false;
78 80
79 DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; 81 DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
80 DWORD access = GENERIC_READ | GENERIC_WRITE | DELETE; 82 DWORD access = GENERIC_READ | GENERIC_WRITE | DELETE;
83 DWORD mode = force_creation_ ? OPEN_ALWAYS : OPEN_EXISTING;
81 platform_file_ = CreateFile(name.value().c_str(), access, sharing, NULL, 84 platform_file_ = CreateFile(name.value().c_str(), access, sharing, NULL,
82 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); 85 mode, FILE_FLAG_OVERLAPPED, NULL);
83 86
84 if (INVALID_HANDLE_VALUE == platform_file_) 87 if (INVALID_HANDLE_VALUE == platform_file_)
85 return false; 88 return false;
86 89
87 MessageLoopForIO::current()->RegisterIOHandler( 90 MessageLoopForIO::current()->RegisterIOHandler(
88 platform_file_, g_completion_handler.Pointer()); 91 platform_file_, g_completion_handler.Pointer());
89 92
90 init_ = true; 93 init_ = true;
91 sync_platform_file_ = CreateFile(name.value().c_str(), access, sharing, NULL, 94 sync_platform_file_ = CreateFile(name.value().c_str(), access, sharing, NULL,
92 OPEN_EXISTING, 0, NULL); 95 OPEN_EXISTING, 0, NULL);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 MessageLoopForIO::current()->WaitForIOCompletion(100, handler); 266 MessageLoopForIO::current()->WaitForIOCompletion(100, handler);
264 } 267 }
265 } 268 }
266 269
267 // Static. 270 // Static.
268 void File::DropPendingIO() { 271 void File::DropPendingIO() {
269 // Nothing to do here. 272 // Nothing to do here.
270 } 273 }
271 274
272 } // namespace disk_cache 275 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/file_lock.h ('k') | net/disk_cache/in_flight_backend_io.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698