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

Side by Side Diff: webkit/appcache/appcache_service.cc

Issue 8991001: base::Bind: Convert most of webkit/appcache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix 2. 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 "webkit/appcache/appcache_service.h" 5 #include "webkit/appcache/appcache_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/message_loop.h" 10 #include "base/message_loop.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 #include "net/base/completion_callback.h" 12 #include "net/base/completion_callback.h"
12 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
13 #include "webkit/appcache/appcache.h" 14 #include "webkit/appcache/appcache.h"
14 #include "webkit/appcache/appcache_backend_impl.h" 15 #include "webkit/appcache/appcache_backend_impl.h"
15 #include "webkit/appcache/appcache_entry.h" 16 #include "webkit/appcache/appcache_entry.h"
16 #include "webkit/appcache/appcache_histograms.h" 17 #include "webkit/appcache/appcache_histograms.h"
17 #include "webkit/appcache/appcache_policy.h" 18 #include "webkit/appcache/appcache_policy.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 CheckResponseHelper( 339 CheckResponseHelper(
339 AppCacheService* service, const GURL& manifest_url, int64 cache_id, 340 AppCacheService* service, const GURL& manifest_url, int64 cache_id,
340 int64 response_id) 341 int64 response_id)
341 : AsyncHelper(service, NULL), 342 : AsyncHelper(service, NULL),
342 manifest_url_(manifest_url), 343 manifest_url_(manifest_url),
343 cache_id_(cache_id), 344 cache_id_(cache_id),
344 response_id_(response_id), 345 response_id_(response_id),
345 kIOBufferSize(32 * 1024), 346 kIOBufferSize(32 * 1024),
346 expected_total_size_(0), 347 expected_total_size_(0),
347 amount_headers_read_(0), 348 amount_headers_read_(0),
348 amount_data_read_(0), 349 amount_data_read_(0) {
349 ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_(
350 this, &CheckResponseHelper::OnReadInfoComplete)),
351 ALLOW_THIS_IN_INITIALIZER_LIST(read_data_callback_(
352 this, &CheckResponseHelper::OnReadDataComplete)) {
353 } 350 }
354 351
355 virtual void Start() { 352 virtual void Start() {
356 service_->storage()->LoadOrCreateGroup(manifest_url_, this); 353 service_->storage()->LoadOrCreateGroup(manifest_url_, this);
357 } 354 }
358 355
359 virtual void Cancel() { 356 virtual void Cancel() {
360 AppCacheHistograms::CountCheckResponseResult( 357 AppCacheHistograms::CountCheckResponseResult(
361 AppCacheHistograms::CHECK_CANCELED); 358 AppCacheHistograms::CHECK_CANCELED);
362 response_reader_.reset(); 359 response_reader_.reset();
(...skipping 12 matching lines...) Expand all
375 372
376 // Internals used to perform the checks. 373 // Internals used to perform the checks.
377 const int kIOBufferSize; 374 const int kIOBufferSize;
378 scoped_refptr<AppCache> cache_; 375 scoped_refptr<AppCache> cache_;
379 scoped_ptr<AppCacheResponseReader> response_reader_; 376 scoped_ptr<AppCacheResponseReader> response_reader_;
380 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; 377 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_;
381 scoped_refptr<net::IOBuffer> data_buffer_; 378 scoped_refptr<net::IOBuffer> data_buffer_;
382 int64 expected_total_size_; 379 int64 expected_total_size_;
383 int amount_headers_read_; 380 int amount_headers_read_;
384 int amount_data_read_; 381 int amount_data_read_;
385 net::OldCompletionCallbackImpl<CheckResponseHelper> read_info_callback_;
386 net::OldCompletionCallbackImpl<CheckResponseHelper> read_data_callback_;
387 DISALLOW_COPY_AND_ASSIGN(CheckResponseHelper); 382 DISALLOW_COPY_AND_ASSIGN(CheckResponseHelper);
388 }; 383 };
389 384
390 void AppCacheService::CheckResponseHelper::OnGroupLoaded( 385 void AppCacheService::CheckResponseHelper::OnGroupLoaded(
391 AppCacheGroup* group, const GURL& manifest_url) { 386 AppCacheGroup* group, const GURL& manifest_url) {
392 DCHECK_EQ(manifest_url_, manifest_url); 387 DCHECK_EQ(manifest_url_, manifest_url);
393 if (!group || !group->newest_complete_cache() || group->is_being_deleted() || 388 if (!group || !group->newest_complete_cache() || group->is_being_deleted() ||
394 group->is_obsolete()) { 389 group->is_obsolete()) {
395 AppCacheHistograms::CountCheckResponseResult( 390 AppCacheHistograms::CountCheckResponseResult(
396 AppCacheHistograms::MANIFEST_OUT_OF_DATE); 391 AppCacheHistograms::MANIFEST_OUT_OF_DATE);
(...skipping 14 matching lines...) Expand all
411 } 406 }
412 delete this; 407 delete this;
413 return; 408 return;
414 } 409 }
415 410
416 // Verify that we can read the response info and data. 411 // Verify that we can read the response info and data.
417 expected_total_size_ = entry->response_size(); 412 expected_total_size_ = entry->response_size();
418 response_reader_.reset(service_->storage()->CreateResponseReader( 413 response_reader_.reset(service_->storage()->CreateResponseReader(
419 manifest_url_, group->group_id(), response_id_)); 414 manifest_url_, group->group_id(), response_id_));
420 info_buffer_ = new HttpResponseInfoIOBuffer(); 415 info_buffer_ = new HttpResponseInfoIOBuffer();
421 response_reader_->ReadInfo(info_buffer_, &read_info_callback_); 416 response_reader_->ReadInfo(
417 info_buffer_, base::Bind(&CheckResponseHelper::OnReadInfoComplete,
418 base::Unretained(this)));
422 } 419 }
423 420
424 void AppCacheService::CheckResponseHelper::OnReadInfoComplete(int result) { 421 void AppCacheService::CheckResponseHelper::OnReadInfoComplete(int result) {
425 if (result < 0) { 422 if (result < 0) {
426 AppCacheHistograms::CountCheckResponseResult( 423 AppCacheHistograms::CountCheckResponseResult(
427 AppCacheHistograms::READ_HEADERS_ERROR); 424 AppCacheHistograms::READ_HEADERS_ERROR);
428 service_->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); 425 service_->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback());
429 delete this; 426 delete this;
430 return; 427 return;
431 } 428 }
432 amount_headers_read_ = result; 429 amount_headers_read_ = result;
433 430
434 // Start reading the data. 431 // Start reading the data.
435 data_buffer_ = new net::IOBuffer(kIOBufferSize); 432 data_buffer_ = new net::IOBuffer(kIOBufferSize);
436 response_reader_->ReadData(data_buffer_, kIOBufferSize, 433 response_reader_->ReadData(
437 &read_data_callback_); 434 data_buffer_, kIOBufferSize,
435 base::Bind(&CheckResponseHelper::OnReadDataComplete,
436 base::Unretained(this)));
438 } 437 }
439 438
440 void AppCacheService::CheckResponseHelper::OnReadDataComplete(int result) { 439 void AppCacheService::CheckResponseHelper::OnReadDataComplete(int result) {
441 if (result > 0) { 440 if (result > 0) {
442 // Keep reading until we've read thru everything or failed to read. 441 // Keep reading until we've read thru everything or failed to read.
443 amount_data_read_ += result; 442 amount_data_read_ += result;
444 response_reader_->ReadData(data_buffer_, kIOBufferSize, 443 response_reader_->ReadData(
445 &read_data_callback_); 444 data_buffer_, kIOBufferSize,
445 base::Bind(&CheckResponseHelper::OnReadDataComplete,
446 base::Unretained(this)));
446 return; 447 return;
447 } 448 }
448 449
449 AppCacheHistograms::CheckResponseResultType check_result; 450 AppCacheHistograms::CheckResponseResultType check_result;
450 if (result < 0) 451 if (result < 0)
451 check_result = AppCacheHistograms::READ_DATA_ERROR; 452 check_result = AppCacheHistograms::READ_DATA_ERROR;
452 else if (info_buffer_->response_data_size != amount_data_read_ || 453 else if (info_buffer_->response_data_size != amount_data_read_ ||
453 expected_total_size_ != amount_data_read_ + amount_headers_read_) 454 expected_total_size_ != amount_data_read_ + amount_headers_read_)
454 check_result = AppCacheHistograms::UNEXPECTED_DATA_SIZE; 455 check_result = AppCacheHistograms::UNEXPECTED_DATA_SIZE;
455 else 456 else
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 backends_.insert( 552 backends_.insert(
552 BackendMap::value_type(backend_impl->process_id(), backend_impl)); 553 BackendMap::value_type(backend_impl->process_id(), backend_impl));
553 } 554 }
554 555
555 void AppCacheService::UnregisterBackend( 556 void AppCacheService::UnregisterBackend(
556 AppCacheBackendImpl* backend_impl) { 557 AppCacheBackendImpl* backend_impl) {
557 backends_.erase(backend_impl->process_id()); 558 backends_.erase(backend_impl->process_id());
558 } 559 }
559 560
560 } // namespace appcache 561 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_response_unittest.cc ('k') | webkit/appcache/appcache_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698