OLD | NEW |
---|---|
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/rand_util.h" | |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "content/browser/appcache/appcache_group.h" | 15 #include "content/browser/appcache/appcache_group.h" |
15 #include "content/browser/appcache/appcache_histograms.h" | 16 #include "content/browser/appcache/appcache_histograms.h" |
17 #include "content/public/browser/browser_main_runner.h" | |
16 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
17 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
18 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
19 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
20 #include "net/http/http_request_headers.h" | 22 #include "net/http/http_request_headers.h" |
21 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
22 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
23 | 25 |
24 namespace content { | 26 namespace content { |
25 | 27 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 : service_(service), | 366 : service_(service), |
365 manifest_url_(group->manifest_url()), | 367 manifest_url_(group->manifest_url()), |
366 group_(group), | 368 group_(group), |
367 update_type_(UNKNOWN_TYPE), | 369 update_type_(UNKNOWN_TYPE), |
368 internal_state_(FETCH_MANIFEST), | 370 internal_state_(FETCH_MANIFEST), |
369 master_entries_completed_(0), | 371 master_entries_completed_(0), |
370 url_fetches_completed_(0), | 372 url_fetches_completed_(0), |
371 manifest_fetcher_(NULL), | 373 manifest_fetcher_(NULL), |
372 manifest_has_valid_mime_type_(false), | 374 manifest_has_valid_mime_type_(false), |
373 stored_state_(UNSTORED), | 375 stored_state_(UNSTORED), |
374 storage_(service->storage()) { | 376 storage_(service->storage()), |
377 weak_factory_(this) { | |
375 service_->AddObserver(this); | 378 service_->AddObserver(this); |
376 } | 379 } |
377 | 380 |
378 AppCacheUpdateJob::~AppCacheUpdateJob() { | 381 AppCacheUpdateJob::~AppCacheUpdateJob() { |
379 if (service_) | 382 if (service_) |
380 service_->RemoveObserver(this); | 383 service_->RemoveObserver(this); |
381 if (internal_state_ != COMPLETED) | 384 if (internal_state_ != COMPLETED) |
382 Cancel(); | 385 Cancel(); |
383 | 386 |
384 DCHECK(!manifest_fetcher_); | 387 DCHECK(!manifest_fetcher_); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 update_type_ = CACHE_ATTEMPT; | 447 update_type_ = CACHE_ATTEMPT; |
445 DCHECK(host); | 448 DCHECK(host); |
446 NotifySingleHost(host, APPCACHE_CHECKING_EVENT); | 449 NotifySingleHost(host, APPCACHE_CHECKING_EVENT); |
447 } | 450 } |
448 | 451 |
449 if (!new_master_resource.is_empty()) { | 452 if (!new_master_resource.is_empty()) { |
450 AddMasterEntryToFetchList(host, new_master_resource, | 453 AddMasterEntryToFetchList(host, new_master_resource, |
451 is_new_pending_master_entry); | 454 is_new_pending_master_entry); |
452 } | 455 } |
453 | 456 |
457 DelayableStart(); | |
458 } | |
459 | |
460 void AppCacheUpdateJob::DelayableStart() { | |
461 if (IsBrowserStartingUp()) { | |
462 // Defer running update jobs till after startup. | |
463 delayed_start_timer_.Start( | |
464 FROM_HERE, base::TimeDelta::FromSeconds(base::RandInt(5, 15)), | |
cmumford
2015/02/26 23:47:45
Constants for 5 & 15?
Also (I don't know RandInt
| |
465 base::Bind(&AppCacheUpdateJob::DelayableStart, | |
466 weak_factory_.GetWeakPtr())); | |
467 return; | |
468 } | |
454 FetchManifest(true); | 469 FetchManifest(true); |
455 } | 470 } |
456 | 471 |
457 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() { | 472 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() { |
458 AppCacheResponseWriter* writer = | 473 AppCacheResponseWriter* writer = |
459 storage_->CreateResponseWriter(manifest_url_, | 474 storage_->CreateResponseWriter(manifest_url_, |
460 group_->group_id()); | 475 group_->group_id()); |
461 stored_response_ids_.push_back(writer->response_id()); | 476 stored_response_ids_.push_back(writer->response_id()); |
462 return writer; | 477 return writer; |
463 } | 478 } |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1621 | 1636 |
1622 // Break the connection with the group so the group cannot call delete | 1637 // 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. | 1638 // on this object after we've posted a task to delete ourselves. |
1624 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); | 1639 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); |
1625 group_ = NULL; | 1640 group_ = NULL; |
1626 | 1641 |
1627 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1642 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1628 } | 1643 } |
1629 | 1644 |
1630 } // namespace content | 1645 } // namespace content |
OLD | NEW |