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

Unified Diff: chrome/browser/extensions/api/system_info/system_info_provider.h

Issue 18290002: [SystemInfo API] Finish TODOs in SystemInfoProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dev_rewrite_storage_info_api
Patch Set: Fix hongbo's comments Created 7 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/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 1fc5b3532d1007dec84a94267c0b181234f36388..6e66859912c58175e04ca2898cb06b6995863a2a 100644
--- a/chrome/browser/extensions/api/system_info/system_info_provider.h
+++ b/chrome/browser/extensions/api/system_info/system_info_provider.h
@@ -44,14 +44,11 @@ class SystemInfoProvider
// two arguments. The first one is the information got already, the second
// one indicates whether its contents are valid, for example, no error
// occurs in querying the information.
- typedef base::Callback<void(const T&, bool)> QueryInfoCompletionCallback;
+ typedef base::Callback<void(bool)> QueryInfoCompletionCallback;
typedef std::queue<QueryInfoCompletionCallback> CallbackQueue;
SystemInfoProvider()
- : is_waiting_for_completion_(false) {
- worker_pool_token_ =
- content::BrowserThread::GetBlockingPool()->GetSequenceToken();
- }
+ : is_waiting_for_completion_(false) {}
virtual ~SystemInfoProvider() {}
@@ -75,59 +72,36 @@ class SystemInfoProvider
is_waiting_for_completion_ = true;
- StartQueryInfoImpl();
+ StartQueryInfoPostInitialization();
Hongbo Min 2013/07/05 05:01:34 What is the major change except for just renaming
Haojian Wu 2013/07/06 05:31:37 In this way we can make OnQueryCompleted method pr
Hongbo Min 2013/07/06 14:26:35 OK. That's an improvement. But I still feel not co
Haojian Wu 2013/07/08 09:26:35 Done.
}
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);
+ // We can override this method with our own custom query info Callback
+ // function which type is bool().
+ virtual void StartQueryInfoPostInitialization() {
+ base::Callback<bool()> query_info_callback =
+ base::Bind(&SystemInfoProvider<T>::QueryInfo, this);
+ StartQueryInfoImpl(query_info_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, query_callback,
- base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
+ // Post the query info task to blocking pool.
+ void StartQueryInfoImpl(const base::Callback<bool()> & query_info_callback) {
+ base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_ =
+ pool->GetSequencedTaskRunnerWithShutdownBehavior(
+ pool->GetSequenceToken(),
+ base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
+ // Post the custom query info task to blocking pool for information querying
+ // and reply with OnQueryCompleted.
+ base::PostTaskAndReplyWithResult(
+ blocking_task_runner_,
+ FROM_HERE,
+ query_info_callback,
+ base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this));
}
- // 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;
-
- // Called on UI thread. The |success| parameter means whether it succeeds
- // to get the information.
- void OnQueryCompleted(bool success) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
-
- while (!callbacks_.empty()) {
- QueryInfoCompletionCallback callback = callbacks_.front();
- callback.Run(info_, success);
- callbacks_.pop();
- }
-
- is_waiting_for_completion_ = false;
- }
+ // Query the system information synchronously and the result is info_.
Hongbo Min 2013/07/05 05:01:34 "Query the system information and put the result i
Haojian Wu 2013/07/06 05:31:37 Done.
+ virtual bool QueryInfo() = 0;
// Template function for creating the single shared provider instance.
// Template paramter I is the type of SystemInfoProvider implementation.
@@ -144,14 +118,21 @@ 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));
+ // Called on UI thread. The |success| parameter means whether it succeeds
+ // to get the information.
+ void OnQueryCompleted(bool success) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ while (!callbacks_.empty()) {
+ QueryInfoCompletionCallback callback = callbacks_.front();
+ callback.Run(success);
+ callbacks_.pop();
+ }
+
+ is_waiting_for_completion_ = false;
}
+
Hongbo Min 2013/07/05 05:01:34 nits: no need to extra blank line.
Haojian Wu 2013/07/06 05:31:37 Done.
// The single shared provider instance. We create it only when needed.
static typename base::LazyInstance<
scoped_refptr<SystemInfoProvider<T> > > single_shared_provider_;
@@ -163,10 +144,6 @@ class SystemInfoProvider
// Indicates if it is waiting for the querying completion.
bool is_waiting_for_completion_;
- // Unqiue sequence token so that the operation of querying inforation can
- // be executed in order.
- base::SequencedWorkerPool::SequenceToken worker_pool_token_;
-
DISALLOW_COPY_AND_ASSIGN(SystemInfoProvider<T>);
};

Powered by Google App Engine
This is Rietveld 408576698