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

Unified Diff: chrome/browser/component_updater/component_updater_service.cc

Issue 385013002: Componentize component_updater: Replace content::BrowserThread usage with task runners (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove extraneous includes Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/component_updater_service.cc
diff --git a/chrome/browser/component_updater/component_updater_service.cc b/chrome/browser/component_updater/component_updater_service.cc
index 3fa2aca335d12fdca14abb265d4438a02933ee22..faecf0bd37864e52016a56826c4d7dd6ed4f3b9e 100644
--- a/chrome/browser/component_updater/component_updater_service.cc
+++ b/chrome/browser/component_updater/component_updater_service.cc
@@ -19,6 +19,7 @@
#include "base/sequenced_task_runner.h"
#include "base/stl_util.h"
#include "base/threading/sequenced_worker_pool.h"
+#include "base/threading/thread_checker.h"
#include "base/timer/timer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/component_unpacker.h"
@@ -139,7 +140,7 @@ void UnblockandReapAllThrottles(CUResourceThrottle::WeakPtrVector* throttles) {
// the tasks. Also when we do network requests there is only one |url_fetcher_|
// in flight at a time.
// There are no locks in this code, the main structure |work_items_| is mutated
-// only from the UI thread. The unpack and installation is done in a blocking
+// only from the main thread. The unpack and installation is done in a blocking
// pool thread. The network requests are done in the IO thread or in the file
// thread.
class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater {
@@ -157,6 +158,8 @@ class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater {
virtual bool GetComponentDetails(const std::string& component_id,
CrxUpdateItem* item) const OVERRIDE;
virtual OnDemandUpdater& GetOnDemandUpdater() OVERRIDE;
+ virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
+ OVERRIDE;
// Overrides for OnDemandUpdater.
virtual content::ResourceThrottle* GetOnDemandResourceThrottle(
@@ -260,6 +263,8 @@ class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater {
base::OneShotTimer<CrxUpdateService> timer_;
+ base::ThreadChecker thread_checker_;
+
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
bool running_;
@@ -274,16 +279,12 @@ class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater {
CrxUpdateService::CrxUpdateService(Configurator* config)
: config_(config),
ping_manager_(new PingManager(*config)),
- blocking_task_runner_(
- BrowserThread::GetBlockingPool()->
- GetSequencedTaskRunnerWithShutdownBehavior(
- BrowserThread::GetBlockingPool()->GetSequenceToken(),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
+ blocking_task_runner_(config->GetSequencedTaskRunner()),
running_(false) {
}
CrxUpdateService::~CrxUpdateService() {
- // Because we are a singleton, at this point only the UI thread should be
+ // Because we are a singleton, at this point only the main thread should be
// alive, this simplifies the management of the work that could be in
// flight in other threads.
Stop();
@@ -291,12 +292,12 @@ CrxUpdateService::~CrxUpdateService() {
}
void CrxUpdateService::AddObserver(Observer* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
observer_list_.AddObserver(observer);
}
void CrxUpdateService::RemoveObserver(Observer* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
observer_list_.RemoveObserver(observer);
}
@@ -348,7 +349,7 @@ bool CrxUpdateService::HasOnDemandItems() const {
// - a long delay when a full check/update cycle has completed for all
// components.
void CrxUpdateService::ScheduleNextRun(StepDelayInterval step_delay) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!update_checker_);
CHECK(!timer_.IsRunning());
// It could be the case that Stop() had been called while a url request
@@ -394,7 +395,7 @@ void CrxUpdateService::ScheduleNextRun(StepDelayInterval step_delay) {
// Given a extension-like component id, find the associated component.
CrxUpdateItem* CrxUpdateService::FindUpdateItemById(
const std::string& id) const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
CrxUpdateItem::FindById finder(id);
UpdateItems::const_iterator it =
std::find_if(work_items_.begin(), work_items_.end(), finder);
@@ -407,7 +408,7 @@ CrxUpdateItem* CrxUpdateService::FindUpdateItemById(
// TODO(waffles): Do we want to add DCHECKS for valid state transitions here?
void CrxUpdateService::ChangeItemState(CrxUpdateItem* item,
CrxUpdateItem::Status to) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
if (to == CrxUpdateItem::kNoUpdate || to == CrxUpdateItem::kUpdated ||
to == CrxUpdateItem::kUpToDate) {
item->on_demand = false;
@@ -450,7 +451,7 @@ void CrxUpdateService::ChangeItemState(CrxUpdateItem* item,
// |to| status and returns how many have been changed.
size_t CrxUpdateService::ChangeItemStatus(CrxUpdateItem::Status from,
CrxUpdateItem::Status to) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
size_t count = 0;
for (UpdateItems::iterator it = work_items_.begin();
it != work_items_.end();
@@ -468,7 +469,7 @@ size_t CrxUpdateService::ChangeItemStatus(CrxUpdateItem::Status from,
// it will be replaced and the return code is kReplaced.
ComponentUpdateService::Status CrxUpdateService::RegisterComponent(
const CrxComponent& component) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
if (component.pk_hash.empty() || !component.version.IsValid() ||
!component.installer)
return kError;
@@ -507,7 +508,7 @@ ComponentUpdateService::Status CrxUpdateService::RegisterComponent(
}
std::vector<std::string> CrxUpdateService::GetComponentIDs() const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
std::vector<std::string> component_ids;
for (UpdateItems::const_iterator it = work_items_.begin();
it != work_items_.end();
@@ -520,7 +521,7 @@ std::vector<std::string> CrxUpdateService::GetComponentIDs() const {
bool CrxUpdateService::GetComponentDetails(const std::string& component_id,
CrxUpdateItem* item) const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
const CrxUpdateItem* crx_update_item(FindUpdateItemById(component_id));
if (crx_update_item)
*item = *crx_update_item;
@@ -531,11 +532,16 @@ OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() {
return *this;
}
+scoped_refptr<base::SequencedTaskRunner>
+CrxUpdateService::GetSequencedTaskRunner() {
+ return config_->GetSequencedTaskRunner();
+}
+
// This is the main loop of the component updater. It updates one component
// at a time if updates are available. Otherwise, it does an update check or
// takes a long sleep until the loop runs again.
void CrxUpdateService::ProcessPendingItems() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
CrxUpdateItem* ready_upgrade = FindReadyComponent();
if (ready_upgrade) {
@@ -655,9 +661,11 @@ void CrxUpdateService::UpdateComponent(CrxUpdateItem* workitem) {
allow_background_download &&
config_->UseBackgroundDownloader();
- crx_downloader_.reset(CrxDownloader::Create(is_background_download,
- config_->RequestContext(),
- blocking_task_runner_));
+ crx_downloader_.reset(
+ CrxDownloader::Create(is_background_download,
+ config_->RequestContext(),
+ blocking_task_runner_,
+ config_->GetSingleThreadTaskRunner()));
crx_downloader_->set_progress_callback(
base::Bind(&CrxUpdateService::DownloadProgress,
base::Unretained(this),
@@ -672,7 +680,7 @@ void CrxUpdateService::UpdateCheckComplete(
int error,
const std::string& error_message,
const UpdateResponse::Results& results) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
update_checker_.reset();
if (!error)
OnUpdateCheckSucceeded(results);
@@ -688,7 +696,7 @@ void CrxUpdateService::UpdateCheckComplete(
void CrxUpdateService::OnUpdateCheckSucceeded(
const UpdateResponse::Results& results) {
size_t num_updates_pending = 0;
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
VLOG(1) << "Update check succeeded.";
std::vector<UpdateResponse::Result>::const_iterator it;
for (it = results.list.begin(); it != results.list.end(); ++it) {
@@ -768,7 +776,7 @@ void CrxUpdateService::OnUpdateCheckSucceeded(
void CrxUpdateService::OnUpdateCheckFailed(int error,
const std::string& error_message) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(error);
size_t count =
ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kNoUpdate);
@@ -783,7 +791,7 @@ void CrxUpdateService::OnUpdateCheckFailed(int error,
void CrxUpdateService::DownloadProgress(
const std::string& component_id,
const CrxDownloader::Result& download_result) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
NotifyObservers(Observer::COMPONENT_UPDATE_DOWNLOADING, component_id);
}
@@ -793,7 +801,7 @@ void CrxUpdateService::DownloadProgress(
void CrxUpdateService::DownloadComplete(
scoped_ptr<CRXContext> crx_context,
const CrxDownloader::Result& download_result) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
CrxUpdateItem* crx = FindUpdateItemById(crx_context->id);
DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff ||
@@ -894,7 +902,7 @@ void CrxUpdateService::EndUnpacking(const std::string& component_id,
void CrxUpdateService::DoneInstalling(const std::string& component_id,
ComponentUnpacker::Error error,
int extra_code) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
ErrorCategory error_category = kErrorNone;
switch (error) {
@@ -942,7 +950,7 @@ void CrxUpdateService::DoneInstalling(const std::string& component_id,
void CrxUpdateService::NotifyObservers(Observer::Events event,
const std::string& id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
FOR_EACH_OBSERVER(Observer, observer_list_, OnEvent(event, id));
}
@@ -965,7 +973,7 @@ content::ResourceThrottle* CrxUpdateService::GetOnDemandResourceThrottle(
void CrxUpdateService::OnNewResourceThrottle(
base::WeakPtr<CUResourceThrottle> rt,
const std::string& crx_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(thread_checker_.CalledOnValidThread());
// Check if we can on-demand update, else unblock the request anyway.
CrxUpdateItem* item = FindUpdateItemById(crx_id);
Status status = OnDemandUpdateWithCooldown(item);
« no previous file with comments | « chrome/browser/component_updater/component_updater_service.h ('k') | chrome/browser/component_updater/crx_downloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698