| OLD | NEW |
| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 is_waiting_for_completion_ = true; | 70 is_waiting_for_completion_ = true; |
| 71 | 71 |
| 72 base::SequencedWorkerPool* worker_pool = | 72 base::SequencedWorkerPool* worker_pool = |
| 73 content::BrowserThread::GetBlockingPool(); | 73 content::BrowserThread::GetBlockingPool(); |
| 74 // The query task posted to the worker pool won't block shutdown, and any | 74 // The query task posted to the worker pool won't block shutdown, and any |
| 75 // running query task at shutdown time will be ignored. | 75 // running query task at shutdown time will be ignored. |
| 76 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior( | 76 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior( |
| 77 worker_pool_token_, | 77 worker_pool_token_, |
| 78 FROM_HERE, | 78 FROM_HERE, |
| 79 base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, | 79 base::Bind(&SystemInfoProvider<T>::QueryOnWorkerPool, this), |
| 80 base::Unretained(this)), | |
| 81 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 80 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 82 } | 81 } |
| 83 | 82 |
| 83 protected: |
| 84 // Query the system information synchronously and output the result to the | 84 // Query the system information synchronously and output the result to the |
| 85 // |info| parameter. The |info| contents MUST be reset firstly in its | 85 // |info| parameter. The |info| contents MUST be reset firstly in its |
| 86 // platform specific implementation. Return true if it succeeds, otherwise | 86 // platform specific implementation. Return true if it succeeds, otherwise |
| 87 // false is returned. | 87 // false is returned. |
| 88 virtual bool QueryInfo(T* info) = 0; | 88 virtual bool QueryInfo(T* info) = 0; |
| 89 | 89 |
| 90 protected: | |
| 91 virtual void QueryOnWorkerPool() { | 90 virtual void QueryOnWorkerPool() { |
| 92 bool success = QueryInfo(&info_); | 91 bool success = QueryInfo(&info_); |
| 93 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 92 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 94 base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, | 93 base::Bind(&SystemInfoProvider<T>::OnQueryCompleted, this, success)); |
| 95 base::Unretained(this), success)); | |
| 96 } | 94 } |
| 97 | 95 |
| 98 // Called on UI thread. The |success| parameter means whether it succeeds | 96 // Called on UI thread. The |success| parameter means whether it succeeds |
| 99 // to get the information. | 97 // to get the information. |
| 100 virtual void OnQueryCompleted(bool success) { | 98 virtual void OnQueryCompleted(bool success) { |
| 101 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 99 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 102 | 100 |
| 103 while (!callbacks_.empty()) { | 101 while (!callbacks_.empty()) { |
| 104 QueryInfoCompletionCallback callback = callbacks_.front(); | 102 QueryInfoCompletionCallback callback = callbacks_.front(); |
| 105 callback.Run(info_, success); | 103 callback.Run(info_, success); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 }; | 141 }; |
| 144 | 142 |
| 145 // Static member intialization. | 143 // Static member intialization. |
| 146 template<class T> | 144 template<class T> |
| 147 typename base::LazyInstance<scoped_refptr<SystemInfoProvider<T> > > | 145 typename base::LazyInstance<scoped_refptr<SystemInfoProvider<T> > > |
| 148 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER; | 146 SystemInfoProvider<T>::single_shared_provider_ = LAZY_INSTANCE_INITIALIZER; |
| 149 | 147 |
| 150 } // namespace extensions | 148 } // namespace extensions |
| 151 | 149 |
| 152 #endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_PROVIDER_H_ | 150 #endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_PROVIDER_H_ |
| OLD | NEW |