Chromium Code Reviews| Index: chrome/browser/extensions/api/system_info/system_info_provider.h |
| diff --git a/chrome/browser/extensions/api/system_info/system_info_provider.h b/chrome/browser/extensions/api/system_info/system_info_provider.h |
| index 849075dfa193181ec06f169d8f1438ec7440fe55..66f03aa4909fa67584f6ab67f7cdb88734b592dd 100644 |
| --- a/chrome/browser/extensions/api/system_info/system_info_provider.h |
| +++ b/chrome/browser/extensions/api/system_info/system_info_provider.h |
| @@ -40,10 +40,9 @@ class SystemInfoProvider |
| typedef base::Callback<void(const T&, bool)> QueryInfoCompletionCallback; |
| typedef std::queue<QueryInfoCompletionCallback> CallbackQueue; |
| - SystemInfoProvider() |
| - : is_waiting_for_completion_(false) { |
| + SystemInfoProvider() : is_waiting_for_completion_(false) { |
|
Lei Zhang
2013/05/28 08:08:07
(Slightly off-topic) Why are all the implementatio
Hongbo Min
2013/05/28 14:24:01
Because the SystemInfoProvider class is just a tem
Lei Zhang
2013/05/28 21:16:44
It doesn't have to be in the .h file. Maybe after
|
| worker_pool_token_ = |
| - content::BrowserThread::GetBlockingPool()->GetSequenceToken(); |
| + content::BrowserThread::GetBlockingPool()->GetSequenceToken(); |
| } |
| virtual ~SystemInfoProvider() {} |
| @@ -62,24 +61,34 @@ class SystemInfoProvider |
| DCHECK(!callback.is_null()); |
| callbacks_.push(callback); |
| - |
| if (is_waiting_for_completion_) |
| return; |
| - |
| is_waiting_for_completion_ = true; |
| + StartQueryInfoImpl(); |
| + } |
| + |
| + protected: |
| + // Default implementation of querying system information. |
| + virtual void StartQueryInfoImpl() { |
| + base::Closure callback = |
| + base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, this); |
| + PostQueryTaskToBlockingPool(FROM_HERE, callback); |
| + } |
| + |
| + // Post a task to blocking pool for information querying. |
| + void PostQueryTaskToBlockingPool(const tracked_objects::Location& from_here, |
| + const base::Closure& query_callback) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| base::SequencedWorkerPool* worker_pool = |
| content::BrowserThread::GetBlockingPool(); |
| // The query task posted to the worker pool won't block shutdown, and any |
| // running query task at shutdown time will be ignored. |
| worker_pool->PostSequencedWorkerTaskWithShutdownBehavior( |
| - worker_pool_token_, |
| - FROM_HERE, |
| - base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, this), |
| + worker_pool_token_, from_here, query_callback, |
| base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| } |
| - protected: |
| // Query the system information synchronously and output the result to the |
| // |info| parameter. The |info| contents MUST be reset firstly in its |
| // platform specific implementation. Return true if it succeeds, otherwise |