| 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 574e62925ace61d2cb8d60c36e767eae41599438..1fc5b3532d1007dec84a94267c0b181234f36388 100644
|
| --- a/chrome/browser/extensions/api/system_info/system_info_provider.h
|
| +++ b/chrome/browser/extensions/api/system_info/system_info_provider.h
|
| @@ -29,6 +29,13 @@ namespace extensions {
|
| //
|
| // Template parameter T is the system information type. It could be the
|
| // structure type generated by IDL parser.
|
| +//
|
| +// The class member |info_| is accessed on multiple threads, but that the whole
|
| +// class is being guarded by SystemInfoProvider.
|
| +//
|
| +// |info_| is accessed on the UI thread while |is_waiting_for_completion_| is
|
| +// false and on the BlockingPool under |worker_pool_token_| while
|
| +// |is_waiting_for_completion_| is true.
|
| template<class T>
|
| class SystemInfoProvider
|
| : public base::RefCountedThreadSafe<SystemInfoProvider<T> > {
|
| @@ -68,33 +75,49 @@ class SystemInfoProvider
|
|
|
| is_waiting_for_completion_ = true;
|
|
|
| + StartQueryInfoImpl();
|
| + }
|
| +
|
| + protected:
|
| + // Default implementation of querying system information.
|
| + //
|
| + // While overriding, there are two things need to do:
|
| + // 1). Bind custom callback function for query system information.
|
| + // 2). Post the custom task to blocking pool.
|
| + 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.
|
| + //
|
| + // The parameter query_callback should invoke QueryInfo directly or indirectly
|
| + // to query the system information and return to UI thread when the query is
|
| + // completed.
|
| + 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
|
| // false is returned.
|
| + // TODO(Haojian): Remove the parameter T-typed pointer, replacing with void
|
| + // QueryInfo().
|
| virtual bool QueryInfo(T* info) = 0;
|
|
|
| - virtual void QueryOnWorkerPool() {
|
| - bool success = QueryInfo(&info_);
|
| - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this, success));
|
| - }
|
| -
|
| // Called on UI thread. The |success| parameter means whether it succeeds
|
| // to get the information.
|
| - virtual void OnQueryCompleted(bool success) {
|
| + void OnQueryCompleted(bool success) {
|
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
|
|
| while (!callbacks_.empty()) {
|
| @@ -104,7 +127,7 @@ class SystemInfoProvider
|
| }
|
|
|
| is_waiting_for_completion_ = false;
|
| - }
|
| + }
|
|
|
| // Template function for creating the single shared provider instance.
|
| // Template paramter I is the type of SystemInfoProvider implementation.
|
| @@ -121,6 +144,14 @@ class SystemInfoProvider
|
| T info_;
|
|
|
| private:
|
| + // TODO(Haojian): Use PostBlockingPoolTaskAndReply to avoid unnecessary
|
| + // trampolines trip.
|
| + void QueryOnWorkerPool() {
|
| + bool success = QueryInfo(&info_);
|
| + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this, success));
|
| + }
|
| +
|
| // The single shared provider instance. We create it only when needed.
|
| static typename base::LazyInstance<
|
| scoped_refptr<SystemInfoProvider<T> > > single_shared_provider_;
|
|
|