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

Side by Side Diff: chrome/browser/extensions/api/system_info/system_info_provider.h

Issue 16707002: [SystemInfo API] Rewrite storage info provider using storage monitor impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TODO in SystemInfoProvider Created 7 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_ 4 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_
5 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_ 5 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
62 DCHECK(!callback.is_null()); 62 DCHECK(!callback.is_null());
63 63
64 callbacks_.push(callback); 64 callbacks_.push(callback);
65 65
66 if (is_waiting_for_completion_) 66 if (is_waiting_for_completion_)
67 return; 67 return;
68 68
69 is_waiting_for_completion_ = true; 69 is_waiting_for_completion_ = true;
70 70
71 StartQueryInfoImpl();
72 }
73
74 protected:
75 // Default implementation of querying system information.
76 virtual void StartQueryInfoImpl() {
77 base::Closure callback =
78 base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, this);
79 PostQueryTaskToBlockingPool(FROM_HERE, callback);
80 }
81
82 // Post a task to blocking pool for information querying.
83 void PostQueryTaskToBlockingPool(const tracked_objects::Location& from_here,
84 const base::Closure& query_callback) {
85 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
71 base::SequencedWorkerPool* worker_pool = 86 base::SequencedWorkerPool* worker_pool =
72 content::BrowserThread::GetBlockingPool(); 87 content::BrowserThread::GetBlockingPool();
73 // The query task posted to the worker pool won't block shutdown, and any 88 // The query task posted to the worker pool won't block shutdown, and any
74 // running query task at shutdown time will be ignored. 89 // running query task at shutdown time will be ignored.
75 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior( 90 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior(
76 worker_pool_token_, 91 worker_pool_token_, from_here, query_callback,
77 FROM_HERE,
78 base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, this),
79 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 92 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
80 } 93 }
81 94
82 protected:
83 // Query the system information synchronously and output the result to the 95 // Query the system information synchronously and output the result to the
84 // |info| parameter. The |info| contents MUST be reset firstly in its 96 // |info| parameter. The |info| contents MUST be reset firstly in its
85 // platform specific implementation. Return true if it succeeds, otherwise 97 // platform specific implementation. Return true if it succeeds, otherwise
86 // false is returned. 98 // false is returned.
99 // TODO(Haojian): Remove the parameter T-typed pointer.
87 virtual bool QueryInfo(T* info) = 0; 100 virtual bool QueryInfo(T* info) = 0;
88 101
102 // TODO(Haojian): use PostBlockingPoolTaskAndReply to avoid unnecessay
Lei Zhang 2013/06/25 04:49:55 nit: typo (unnecessay)
Haojian Wu 2013/06/26 03:22:40 Done.
103 // trampolines trip.
89 virtual void QueryOnWorkerPool() { 104 virtual void QueryOnWorkerPool() {
90 bool success = QueryInfo(&info_); 105 bool success = QueryInfo(&info_);
91 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 106 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
92 base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this, success)); 107 base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this, success));
93 } 108 }
94 109
95 // Called on UI thread. The |success| parameter means whether it succeeds 110 // Called on UI thread. The |success| parameter means whether it succeeds
96 // to get the information. 111 // to get the information.
97 virtual void OnQueryCompleted(bool success) { 112 virtual void OnQueryCompleted(bool success) {
98 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 }; 155 };
141 156
142 // Static member intialization. 157 // Static member intialization.
143 template<class T> 158 template<class T>
144 typename base::LazyInstance<scoped_refptr<SystemInfoProvider<T> > > 159 typename base::LazyInstance<scoped_refptr<SystemInfoProvider<T> > >
145 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER; 160 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER;
146 161
147 } // namespace extensions 162 } // namespace extensions
148 163
149 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_ 164 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698