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

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

Issue 10876041: Polish the SystemInfoProvider template code and refactor StorageInfoProvider based on it (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use string16 instead of wstring to avoid Presubmit warning Created 8 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_SYSTEM_INFO_PROVIDER_H_ 4 #ifndef CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_PROVIDER_H_
5 #define CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_PROVIDER_H_ 5 #define CHROME_BROWSER_EXTENSIONS_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 29 matching lines...) Expand all
40 typedef std::queue<QueryInfoCompletionCallback> CallbackQueue; 40 typedef std::queue<QueryInfoCompletionCallback> CallbackQueue;
41 41
42 SystemInfoProvider() 42 SystemInfoProvider()
43 : is_waiting_for_completion_(false) { 43 : is_waiting_for_completion_(false) {
44 worker_pool_token_ = 44 worker_pool_token_ =
45 content::BrowserThread::GetBlockingPool()->GetSequenceToken(); 45 content::BrowserThread::GetBlockingPool()->GetSequenceToken();
46 } 46 }
47 47
48 virtual ~SystemInfoProvider() {} 48 virtual ~SystemInfoProvider() {}
49 49
50 // Static method to get the single shared instance. Should be implemented
51 // in the impl file for each kind of provider.
52 static SystemInfoProvider<T>* Get();
53
54 // For testing 50 // For testing
55 static void InitializeForTesting(SystemInfoProvider<T>* provider) { 51 static void InitializeForTesting(SystemInfoProvider<T>* provider) {
56 DCHECK(provider != NULL); 52 DCHECK(provider != NULL);
57 single_shared_provider_.Get().reset(provider); 53 single_shared_provider_.Get().reset(provider);
58 } 54 }
59 55
60 // Start to query the system information. Should be called on UI thread. 56 // Start to query the system information. Should be called on UI thread.
61 // The |callback| will get called once the query is completed. 57 // The |callback| will get called once the query is completed.
62 void StartQueryInfo(const QueryInfoCompletionCallback& callback) { 58 void StartQueryInfo(const QueryInfoCompletionCallback& callback) {
63 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 59 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 callback.Run(info_, success); 102 callback.Run(info_, success);
107 callbacks_.pop(); 103 callbacks_.pop();
108 } 104 }
109 105
110 is_waiting_for_completion_ = false; 106 is_waiting_for_completion_ = false;
111 } 107 }
112 108
113 // Template function for creating the single shared provider instance. 109 // Template function for creating the single shared provider instance.
114 // Template paramter I is the type of SystemInfoProvider implementation. 110 // Template paramter I is the type of SystemInfoProvider implementation.
115 template<class I> 111 template<class I>
116 static SystemInfoProvider<T>* GetInstance() { 112 static I* GetInstance() {
117 if (!single_shared_provider_.Get().get()) { 113 if (!single_shared_provider_.Get().get()) {
118 I* impl = new I(); 114 I* impl = new I();
119 single_shared_provider_.Get().reset(impl); 115 single_shared_provider_.Get().reset(impl);
120 } 116 }
121 return single_shared_provider_.Get().get(); 117 return static_cast<I*>(single_shared_provider_.Get().get());
122 } 118 }
123 119
124 // The latest information filled up by QueryInfo implementation. Here we 120 // The latest information filled up by QueryInfo implementation. Here we
125 // assume the T is disallowed to copy constructor, aligns with the structure 121 // assume the T is disallowed to copy constructor, aligns with the structure
126 // type generated by IDL parser. 122 // type generated by IDL parser.
127 T info_; 123 T info_;
128 124
129 private: 125 private:
130 // The single shared provider instance. We create it only when needed. 126 // The single shared provider instance. We create it only when needed.
131 static typename base::LazyInstance< 127 static typename base::LazyInstance<
(...skipping 14 matching lines...) Expand all
146 }; 142 };
147 143
148 // Static member intialization. 144 // Static member intialization.
149 template<class T> 145 template<class T>
150 typename base::LazyInstance<scoped_ptr<SystemInfoProvider<T> > > 146 typename base::LazyInstance<scoped_ptr<SystemInfoProvider<T> > >
151 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER; 147 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER;
152 148
153 } // namespace extensions 149 } // namespace extensions
154 150
155 #endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_PROVIDER_H_ 151 #endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698