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

Side by Side Diff: net/http/partial_data.cc

Issue 8990001: base::Bind: Convert most of net/http. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang. Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/http/partial_data.h" 5 #include "net/http/partial_data.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 108 }
109 109
110 // ----------------------------------------------------------------------------- 110 // -----------------------------------------------------------------------------
111 111
112 PartialData::PartialData() 112 PartialData::PartialData()
113 : range_present_(false), 113 : range_present_(false),
114 final_range_(false), 114 final_range_(false),
115 sparse_entry_(true), 115 sparse_entry_(true),
116 truncated_(false), 116 truncated_(false),
117 initial_validation_(false), 117 initial_validation_(false),
118 core_(NULL), 118 core_(NULL) {
119 callback_(NULL) {
120 } 119 }
121 120
122 PartialData::~PartialData() { 121 PartialData::~PartialData() {
123 if (core_) 122 if (core_)
124 core_->Cancel(); 123 core_->Cancel();
125 } 124 }
126 125
127 bool PartialData::Init(const HttpRequestHeaders& headers) { 126 bool PartialData::Init(const HttpRequestHeaders& headers) {
128 std::string range_header; 127 std::string range_header;
129 if (!headers.GetHeader(HttpRequestHeaders::kRange, &range_header)) 128 if (!headers.GetHeader(HttpRequestHeaders::kRange, &range_header))
(...skipping 25 matching lines...) Expand all
155 DCHECK(current_range_start_ >= 0 || byte_range_.IsSuffixByteRange()); 154 DCHECK(current_range_start_ >= 0 || byte_range_.IsSuffixByteRange());
156 int64 end = byte_range_.IsSuffixByteRange() ? 155 int64 end = byte_range_.IsSuffixByteRange() ?
157 byte_range_.suffix_length() : byte_range_.last_byte_position(); 156 byte_range_.suffix_length() : byte_range_.last_byte_position();
158 157
159 headers->CopyFrom(extra_headers_); 158 headers->CopyFrom(extra_headers_);
160 if (!truncated_ && byte_range_.IsValid()) 159 if (!truncated_ && byte_range_.IsValid())
161 AddRangeHeader(current_range_start_, end, headers); 160 AddRangeHeader(current_range_start_, end, headers);
162 } 161 }
163 162
164 int PartialData::ShouldValidateCache(disk_cache::Entry* entry, 163 int PartialData::ShouldValidateCache(disk_cache::Entry* entry,
165 OldCompletionCallback* callback) { 164 const CompletionCallback& callback) {
166 DCHECK_GE(current_range_start_, 0); 165 DCHECK_GE(current_range_start_, 0);
167 166
168 // Scan the disk cache for the first cached portion within this range. 167 // Scan the disk cache for the first cached portion within this range.
169 int len = GetNextRangeLen(); 168 int len = GetNextRangeLen();
170 if (!len) 169 if (!len)
171 return 0; 170 return 0;
172 171
173 DVLOG(3) << "ShouldValidateCache len: " << len; 172 DVLOG(3) << "ShouldValidateCache len: " << len;
174 173
175 if (sparse_entry_) { 174 if (sparse_entry_) {
176 DCHECK(!callback_); 175 DCHECK(callback_.is_null());
177 Core* core = Core::CreateCore(this); 176 Core* core = Core::CreateCore(this);
178 cached_min_len_ = core->GetAvailableRange(entry, current_range_start_, len, 177 cached_min_len_ = core->GetAvailableRange(entry, current_range_start_, len,
179 &cached_start_); 178 &cached_start_);
180 179
181 if (cached_min_len_ == ERR_IO_PENDING) { 180 if (cached_min_len_ == ERR_IO_PENDING) {
182 callback_ = callback; 181 callback_ = callback;
183 return ERR_IO_PENDING; 182 return ERR_IO_PENDING;
184 } 183 }
185 } else if (!truncated_) { 184 } else if (!truncated_) {
186 if (byte_range_.HasFirstBytePosition() && 185 if (byte_range_.HasFirstBytePosition() &&
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 int64 range_len = 473 int64 range_len =
475 byte_range_.HasLastBytePosition() ? 474 byte_range_.HasLastBytePosition() ?
476 byte_range_.last_byte_position() - current_range_start_ + 1 : 475 byte_range_.last_byte_position() - current_range_start_ + 1 :
477 kint32max; 476 kint32max;
478 if (range_len > kint32max) 477 if (range_len > kint32max)
479 range_len = kint32max; 478 range_len = kint32max;
480 return static_cast<int32>(range_len); 479 return static_cast<int32>(range_len);
481 } 480 }
482 481
483 void PartialData::GetAvailableRangeCompleted(int result, int64 start) { 482 void PartialData::GetAvailableRangeCompleted(int result, int64 start) {
484 DCHECK(callback_); 483 DCHECK(!callback_.is_null());
485 DCHECK_NE(ERR_IO_PENDING, result); 484 DCHECK_NE(ERR_IO_PENDING, result);
486 485
487 cached_start_ = start; 486 cached_start_ = start;
488 cached_min_len_ = result; 487 cached_min_len_ = result;
489 if (result >= 0) 488 if (result >= 0)
490 result = 1; // Return success, go ahead and validate the entry. 489 result = 1; // Return success, go ahead and validate the entry.
491 490
492 OldCompletionCallback* cb = callback_; 491 CompletionCallback cb = callback_;
493 callback_ = NULL; 492 callback_.Reset();
494 cb->Run(result); 493 cb.Run(result);
495 } 494 }
496 495
497 } // namespace net 496 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698