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

Side by Side Diff: net/url_request/sdch_dictionary_fetcher.cc

Issue 2075033003: Make SdchDictionaryFetcher free more memory when done. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Oops Created 4 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
« no previous file with comments | « net/url_request/sdch_dictionary_fetcher.h ('k') | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/url_request/sdch_dictionary_fetcher.h" 5 #include "net/url_request/sdch_dictionary_fetcher.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <queue> 8 #include <queue>
9 #include <set> 9 #include <set>
10 10
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // and Schedule() is only called from user code, so this call to DoLoop() 218 // and Schedule() is only called from user code, so this call to DoLoop()
219 // does not require an |if (in_loop_) return;| guard. 219 // does not require an |if (in_loop_) return;| guard.
220 DoLoop(OK); 220 DoLoop(OK);
221 return true; 221 return true;
222 } 222 }
223 223
224 void SdchDictionaryFetcher::ResetRequest() { 224 void SdchDictionaryFetcher::ResetRequest() {
225 current_request_.reset(); 225 current_request_.reset();
226 buffer_ = nullptr; 226 buffer_ = nullptr;
227 current_callback_.Reset(); 227 current_callback_.Reset();
228 dictionary_.clear(); 228 dictionary_.reset();
229 return; 229 return;
230 } 230 }
231 231
232 int SdchDictionaryFetcher::DoLoop(int rv) { 232 int SdchDictionaryFetcher::DoLoop(int rv) {
233 DCHECK(!in_loop_); 233 DCHECK(!in_loop_);
234 base::AutoReset<bool> auto_reset_in_loop(&in_loop_, true); 234 base::AutoReset<bool> auto_reset_in_loop(&in_loop_, true);
235 235
236 do { 236 do {
237 State state = next_state_; 237 State state = next_state_;
238 next_state_ = STATE_NONE; 238 next_state_ = STATE_NONE;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 FetchInfo info; 279 FetchInfo info;
280 bool success = fetch_queue_->Pop(&info); 280 bool success = fetch_queue_->Pop(&info);
281 DCHECK(success); 281 DCHECK(success);
282 current_request_ = context_->CreateRequest(info.url, IDLE, this); 282 current_request_ = context_->CreateRequest(info.url, IDLE, this);
283 int load_flags = LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; 283 int load_flags = LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES;
284 if (info.cache_only) 284 if (info.cache_only)
285 load_flags |= LOAD_ONLY_FROM_CACHE; 285 load_flags |= LOAD_ONLY_FROM_CACHE;
286 current_request_->SetLoadFlags(load_flags); 286 current_request_->SetLoadFlags(load_flags);
287 287
288 buffer_ = new IOBuffer(kBufferSize); 288 buffer_ = new IOBuffer(kBufferSize);
289 dictionary_.reset(new std::string());
289 current_callback_ = info.callback; 290 current_callback_ = info.callback;
290 291
291 current_request_->Start(); 292 current_request_->Start();
292 current_request_->net_log().AddEvent(NetLog::TYPE_SDCH_DICTIONARY_FETCH); 293 current_request_->net_log().AddEvent(NetLog::TYPE_SDCH_DICTIONARY_FETCH);
293 294
294 return ERR_IO_PENDING; 295 return ERR_IO_PENDING;
295 } 296 }
296 297
297 int SdchDictionaryFetcher::DoReceivedRedirect(int rv) { 298 int SdchDictionaryFetcher::DoReceivedRedirect(int rv) {
298 // Fetching SDCH through a redirect is forbidden; it raises possible 299 // Fetching SDCH through a redirect is forbidden; it raises possible
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 if (rv < 0) { 344 if (rv < 0) {
344 ResetRequest(); 345 ResetRequest();
345 next_state_ = STATE_SEND_REQUEST; 346 next_state_ = STATE_SEND_REQUEST;
346 return OK; 347 return OK;
347 } 348 }
348 349
349 DCHECK(current_request_->status().is_success()); 350 DCHECK(current_request_->status().is_success());
350 351
351 // Data; append to the dictionary and look for more data. 352 // Data; append to the dictionary and look for more data.
352 if (rv > 0) { 353 if (rv > 0) {
353 dictionary_.append(buffer_->data(), rv); 354 dictionary_->append(buffer_->data(), rv);
354 next_state_ = STATE_READ_BODY; 355 next_state_ = STATE_READ_BODY;
355 return OK; 356 return OK;
356 } 357 }
357 358
358 // End of file; complete the request. 359 // End of file; complete the request.
359 next_state_ = STATE_REQUEST_COMPLETE; 360 next_state_ = STATE_REQUEST_COMPLETE;
360 return OK; 361 return OK;
361 } 362 }
362 363
363 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { 364 int SdchDictionaryFetcher::DoCompleteRequest(int rv) {
364 DCHECK(CalledOnValidThread()); 365 DCHECK(CalledOnValidThread());
365 366
366 // If the dictionary was successfully fetched, add it to the manager. 367 // If the dictionary was successfully fetched, add it to the manager.
367 if (rv == OK) { 368 if (rv == OK) {
368 current_callback_.Run(dictionary_, current_request_->url(), 369 current_callback_.Run(*dictionary_, current_request_->url(),
369 current_request_->net_log(), 370 current_request_->net_log(),
370 current_request_->was_cached()); 371 current_request_->was_cached());
371 } 372 }
372 373
373 ResetRequest(); 374 ResetRequest();
374 next_state_ = STATE_SEND_REQUEST; 375 next_state_ = STATE_SEND_REQUEST;
375 return OK; 376 return OK;
376 } 377 }
377 378
378 } // namespace net 379 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/sdch_dictionary_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698