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

Side by Side Diff: net/disk_cache/blockfile/file_posix.cc

Issue 2657003003: Avoid unneeded refcount bump on disk_cache::File (Closed)
Patch Set: Created 3 years, 10 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 | « 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 "net/disk_cache/blockfile/file.h" 5 #include "net/disk_cache/blockfile/file.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return Read(buffer, buffer_len, offset); 90 return Read(buffer, buffer_len, offset);
91 } 91 }
92 92
93 if (buffer_len > static_cast<size_t>(std::numeric_limits<int32_t>::max()) || 93 if (buffer_len > static_cast<size_t>(std::numeric_limits<int32_t>::max()) ||
94 offset > static_cast<size_t>(std::numeric_limits<int32_t>::max())) { 94 offset > static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
95 return false; 95 return false;
96 } 96 }
97 97
98 base::PostTaskAndReplyWithResult( 98 base::PostTaskAndReplyWithResult(
99 s_worker_pool.Pointer(), FROM_HERE, 99 s_worker_pool.Pointer(), FROM_HERE,
100 base::Bind(&File::DoRead, this, buffer, buffer_len, offset), 100 base::Bind(&File::DoRead, base::Unretained(this), buffer, buffer_len,
101 offset),
101 base::Bind(&File::OnOperationComplete, this, callback)); 102 base::Bind(&File::OnOperationComplete, this, callback));
102 103
103 *completed = false; 104 *completed = false;
104 return true; 105 return true;
105 } 106 }
106 107
107 bool File::Write(const void* buffer, size_t buffer_len, size_t offset, 108 bool File::Write(const void* buffer, size_t buffer_len, size_t offset,
108 FileIOCallback* callback, bool* completed) { 109 FileIOCallback* callback, bool* completed) {
109 DCHECK(base_file_.IsValid()); 110 DCHECK(base_file_.IsValid());
110 if (!callback) { 111 if (!callback) {
111 if (completed) 112 if (completed)
112 *completed = true; 113 *completed = true;
113 return Write(buffer, buffer_len, offset); 114 return Write(buffer, buffer_len, offset);
114 } 115 }
115 116
116 if (buffer_len > static_cast<size_t>(std::numeric_limits<int32_t>::max()) || 117 if (buffer_len > static_cast<size_t>(std::numeric_limits<int32_t>::max()) ||
117 offset > static_cast<size_t>(std::numeric_limits<int32_t>::max())) { 118 offset > static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
118 return false; 119 return false;
119 } 120 }
120 121
121 base::PostTaskAndReplyWithResult( 122 base::PostTaskAndReplyWithResult(
122 s_worker_pool.Pointer(), FROM_HERE, 123 s_worker_pool.Pointer(), FROM_HERE,
123 base::Bind(&File::DoWrite, this, buffer, buffer_len, offset), 124 base::Bind(&File::DoWrite, base::Unretained(this), buffer, buffer_len,
125 offset),
124 base::Bind(&File::OnOperationComplete, this, callback)); 126 base::Bind(&File::OnOperationComplete, this, callback));
125 127
126 *completed = false; 128 *completed = false;
127 return true; 129 return true;
128 } 130 }
129 131
130 bool File::SetLength(size_t length) { 132 bool File::SetLength(size_t length) {
131 DCHECK(base_file_.IsValid()); 133 DCHECK(base_file_.IsValid());
132 if (length > std::numeric_limits<uint32_t>::max()) 134 if (length > std::numeric_limits<uint32_t>::max())
133 return false; 135 return false;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return net::ERR_CACHE_WRITE_FAILURE; 186 return net::ERR_CACHE_WRITE_FAILURE;
185 } 187 }
186 188
187 // This method actually makes sure that the last reference to the file doesn't 189 // This method actually makes sure that the last reference to the file doesn't
188 // go away on the worker pool. 190 // go away on the worker pool.
189 void File::OnOperationComplete(FileIOCallback* callback, int result) { 191 void File::OnOperationComplete(FileIOCallback* callback, int result) {
190 callback->OnFileIOComplete(result); 192 callback->OnFileIOComplete(result);
191 } 193 }
192 194
193 } // namespace disk_cache 195 } // namespace disk_cache
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