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

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: Update 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 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 11 matching lines...) Expand all
22 // The SystemInfoProvider is designed to query system information on the worker 22 // The SystemInfoProvider is designed to query system information on the worker
23 // pool. It also maintains a queue of callbacks on the UI thread which are 23 // pool. It also maintains a queue of callbacks on the UI thread which are
24 // waiting for the completion of querying operation. Once the query operation 24 // waiting for the completion of querying operation. Once the query operation
25 // is completed, all pending callbacks in the queue get called on the UI 25 // is completed, all pending callbacks in the queue get called on the UI
26 // thread. In this way, it avoids frequent querying operation in case of lots 26 // thread. In this way, it avoids frequent querying operation in case of lots
27 // of query requests, e.g. calling systemInfo.cpu.get repeatedly in an 27 // of query requests, e.g. calling systemInfo.cpu.get repeatedly in an
28 // extension process. 28 // extension process.
29 // 29 //
30 // Template parameter T is the system information type. It could be the 30 // Template parameter T is the system information type. It could be the
31 // structure type generated by IDL parser. 31 // structure type generated by IDL parser.
32 //
33 // The class member info_ is accessed on multiple threads, but that the whole
34 // class is being guarded by SystemInfoProvider.
Jeffrey Yasskin 2013/07/02 23:00:50 What does this mean? Normally I'd expect a mutex t
Hongbo Min 2013/07/03 04:59:40 You might miss some background of this class imple
Haojian Wu 2013/07/03 16:23:49 Please see hongbo's explanation at here:https://co
32 template<class T> 35 template<class T>
33 class SystemInfoProvider 36 class SystemInfoProvider
34 : public base::RefCountedThreadSafe<SystemInfoProvider<T> > { 37 : public base::RefCountedThreadSafe<SystemInfoProvider<T> > {
35 public: 38 public:
36 // Callback type for completing to get information. The callback accepts 39 // Callback type for completing to get information. The callback accepts
37 // two arguments. The first one is the information got already, the second 40 // two arguments. The first one is the information got already, the second
38 // one indicates whether its contents are valid, for example, no error 41 // one indicates whether its contents are valid, for example, no error
39 // occurs in querying the information. 42 // occurs in querying the information.
40 typedef base::Callback<void(const T&, bool)> QueryInfoCompletionCallback; 43 typedef base::Callback<void(const T&, bool)> QueryInfoCompletionCallback;
41 typedef std::queue<QueryInfoCompletionCallback> CallbackQueue; 44 typedef std::queue<QueryInfoCompletionCallback> CallbackQueue;
(...skipping 19 matching lines...) Expand all
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 64 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
62 DCHECK(!callback.is_null()); 65 DCHECK(!callback.is_null());
63 66
64 callbacks_.push(callback); 67 callbacks_.push(callback);
65 68
66 if (is_waiting_for_completion_) 69 if (is_waiting_for_completion_)
67 return; 70 return;
68 71
69 is_waiting_for_completion_ = true; 72 is_waiting_for_completion_ = true;
70 73
74 StartQueryInfoImpl();
75 }
76
77 protected:
78 // Default implementation of querying system information.
Jeffrey Yasskin 2013/07/02 23:00:50 Virtual functions need a comment saying how to ove
Haojian Wu 2013/07/03 16:23:49 Done.
79 virtual void StartQueryInfoImpl() {
80 base::Closure callback =
81 base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, this);
82 PostQueryTaskToBlockingPool(FROM_HERE, callback);
83 }
84
85 // Post a task to blocking pool for information querying.
Jeffrey Yasskin 2013/07/02 23:00:50 "for information querying" is too vague. What does
Haojian Wu 2013/07/03 16:23:49 Done.
86 void PostQueryTaskToBlockingPool(const tracked_objects::Location& from_here,
87 const base::Closure& query_callback) {
88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
71 base::SequencedWorkerPool* worker_pool = 89 base::SequencedWorkerPool* worker_pool =
72 content::BrowserThread::GetBlockingPool(); 90 content::BrowserThread::GetBlockingPool();
73 // The query task posted to the worker pool won't block shutdown, and any 91 // The query task posted to the worker pool won't block shutdown, and any
74 // running query task at shutdown time will be ignored. 92 // running query task at shutdown time will be ignored.
75 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior( 93 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior(
76 worker_pool_token_, 94 worker_pool_token_, from_here, query_callback,
77 FROM_HERE,
78 base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, this),
79 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 95 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
80 } 96 }
81 97
82 protected:
83 // Query the system information synchronously and output the result to the 98 // Query the system information synchronously and output the result to the
84 // |info| parameter. The |info| contents MUST be reset firstly in its 99 // |info| parameter. The |info| contents MUST be reset firstly in its
85 // platform specific implementation. Return true if it succeeds, otherwise 100 // platform specific implementation. Return true if it succeeds, otherwise
86 // false is returned. 101 // false is returned.
102 // TODO(Haojian): Remove the parameter T-typed pointer.
Jeffrey Yasskin 2013/07/02 23:00:50 And replace it with what?
Haojian Wu 2013/07/03 16:23:49 Replace with bool QueryInfo() instead. Update the
Jeffrey Yasskin 2013/07/03 21:44:48 No, this signature gives the subclass access to a
Haojian Wu 2013/07/04 00:41:17 Actually the subclass can access T-typed info_ dir
87 virtual bool QueryInfo(T* info) = 0; 103 virtual bool QueryInfo(T* info) = 0;
88 104
105 // TODO(Haojian): Use PostBlockingPoolTaskAndReply to avoid unnecessary
Jeffrey Yasskin 2013/07/02 23:00:50 Why can't you do this now?
Hongbo Min 2013/07/03 04:59:40 After discussion with Billock@ and Lei@, we agree
Haojian Wu 2013/07/03 16:23:49 Since this work will make a big change of SystemIn
Jeffrey Yasskin 2013/07/03 21:44:48 In https://codereview.chromium.org/18290002/ I see
Haojian Wu 2013/07/04 00:41:17 Thanks for the useful suggestions. I will update t
106 // trampolines trip.
89 virtual void QueryOnWorkerPool() { 107 virtual void QueryOnWorkerPool() {
Jeffrey Yasskin 2013/07/02 23:00:50 This virtual function also needs a description of
Haojian Wu 2013/07/03 16:23:49 This function can be non-virtual and replace it wi
90 bool success = QueryInfo(&info_); 108 bool success = QueryInfo(&info_);
91 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 109 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
92 base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this, success)); 110 base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this, success));
93 } 111 }
94 112
95 // Called on UI thread. The |success| parameter means whether it succeeds 113 // Called on UI thread. The |success| parameter means whether it succeeds
96 // to get the information. 114 // to get the information.
97 virtual void OnQueryCompleted(bool success) { 115 virtual void OnQueryCompleted(bool success) {
98 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 116 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
99 117
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 }; 158 };
141 159
142 // Static member intialization. 160 // Static member intialization.
143 template<class T> 161 template<class T>
144 typename base::LazyInstance<scoped_refptr<SystemInfoProvider<T> > > 162 typename base::LazyInstance<scoped_refptr<SystemInfoProvider<T> > >
145 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER; 163 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER;
146 164
147 } // namespace extensions 165 } // namespace extensions
148 166
149 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_ 167 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_SYSTEM_INFO_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698