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

Side by Side Diff: content/browser/appcache/appcache_update_job.cc

Issue 949293002: Implement a poor man's PostAfterStartupTask() function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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 "content/browser/appcache/appcache_update_job.h" 5 #include "content/browser/appcache/appcache_update_job.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/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/profiler/scoped_tracker.h" 11 #include "base/profiler/scoped_tracker.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "content/browser/appcache/appcache_group.h" 14 #include "content/browser/appcache/appcache_group.h"
15 #include "content/browser/appcache/appcache_histograms.h" 15 #include "content/browser/appcache/appcache_histograms.h"
16 #include "content/public/browser/browser_thread.h"
16 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
17 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
18 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
19 #include "net/base/request_priority.h" 20 #include "net/base/request_priority.h"
20 #include "net/http/http_request_headers.h" 21 #include "net/http/http_request_headers.h"
21 #include "net/http/http_response_headers.h" 22 #include "net/http/http_response_headers.h"
22 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
23 24
24 namespace content { 25 namespace content {
25 26
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 : service_(service), 365 : service_(service),
365 manifest_url_(group->manifest_url()), 366 manifest_url_(group->manifest_url()),
366 group_(group), 367 group_(group),
367 update_type_(UNKNOWN_TYPE), 368 update_type_(UNKNOWN_TYPE),
368 internal_state_(FETCH_MANIFEST), 369 internal_state_(FETCH_MANIFEST),
369 master_entries_completed_(0), 370 master_entries_completed_(0),
370 url_fetches_completed_(0), 371 url_fetches_completed_(0),
371 manifest_fetcher_(NULL), 372 manifest_fetcher_(NULL),
372 manifest_has_valid_mime_type_(false), 373 manifest_has_valid_mime_type_(false),
373 stored_state_(UNSTORED), 374 stored_state_(UNSTORED),
374 storage_(service->storage()) { 375 storage_(service->storage()),
376 weak_factory_(this) {
375 service_->AddObserver(this); 377 service_->AddObserver(this);
376 } 378 }
377 379
378 AppCacheUpdateJob::~AppCacheUpdateJob() { 380 AppCacheUpdateJob::~AppCacheUpdateJob() {
379 if (service_) 381 if (service_)
380 service_->RemoveObserver(this); 382 service_->RemoveObserver(this);
381 if (internal_state_ != COMPLETED) 383 if (internal_state_ != COMPLETED)
382 Cancel(); 384 Cancel();
383 385
384 DCHECK(!manifest_fetcher_); 386 DCHECK(!manifest_fetcher_);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 update_type_ = CACHE_ATTEMPT; 446 update_type_ = CACHE_ATTEMPT;
445 DCHECK(host); 447 DCHECK(host);
446 NotifySingleHost(host, APPCACHE_CHECKING_EVENT); 448 NotifySingleHost(host, APPCACHE_CHECKING_EVENT);
447 } 449 }
448 450
449 if (!new_master_resource.is_empty()) { 451 if (!new_master_resource.is_empty()) {
450 AddMasterEntryToFetchList(host, new_master_resource, 452 AddMasterEntryToFetchList(host, new_master_resource,
451 is_new_pending_master_entry); 453 is_new_pending_master_entry);
452 } 454 }
453 455
454 FetchManifest(true); 456 BrowserThread::PostAfterStartupTask(
457 FROM_HERE,
458 base::MessageLoop::current()->task_runner(),
459 base::Bind(&AppCacheUpdateJob::FetchManifest,
460 weak_factory_.GetWeakPtr(),
461 true));
455 } 462 }
456 463
457 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() { 464 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() {
458 AppCacheResponseWriter* writer = 465 AppCacheResponseWriter* writer =
459 storage_->CreateResponseWriter(manifest_url_, 466 storage_->CreateResponseWriter(manifest_url_,
460 group_->group_id()); 467 group_->group_id());
461 stored_response_ids_.push_back(writer->response_id()); 468 stored_response_ids_.push_back(writer->response_id());
462 return writer; 469 return writer;
463 } 470 }
464 471
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 1628
1622 // Break the connection with the group so the group cannot call delete 1629 // Break the connection with the group so the group cannot call delete
1623 // on this object after we've posted a task to delete ourselves. 1630 // on this object after we've posted a task to delete ourselves.
1624 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); 1631 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE);
1625 group_ = NULL; 1632 group_ = NULL;
1626 1633
1627 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 1634 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1628 } 1635 }
1629 1636
1630 } // namespace content 1637 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698