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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/api/system_info/system_info_provider.h"
8 #include "content/public/browser/browser_thread.h"
10 namespace extensions {
12 SystemInfoProvider::SystemInfoProvider()
13 : is_waiting_for_completion_(false) {
14 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
15 worker_pool_ = pool->GetSequencedTaskRunnerWithShutdownBehavior(
16 pool->GetSequenceToken(),
17 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
20 SystemInfoProvider::~SystemInfoProvider() {}
22 void SystemInfoProvider::PrepareQueryOnUIThread() {}
24 void SystemInfoProvider::InitializeProvider(const base::Closure&
25 do_query_info_callback) {
26 do_query_info_callback.Run();
29 void SystemInfoProvider::StartQueryInfo(
30 const QueryInfoCompletionCallback& callback) {
31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
32 DCHECK(!callback.is_null());
34 callbacks_.push(callback);
36 if (is_waiting_for_completion_)
39 is_waiting_for_completion_ = true;
41 InitializeProvider(base::Bind(
42 &SystemInfoProvider::StartQueryInfoPostInitialization, this));
45 void SystemInfoProvider::OnQueryCompleted(bool success) {
46 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
48 while (!callbacks_.empty()) {
49 QueryInfoCompletionCallback callback = callbacks_.front();
50 callback.Run(success);
54 is_waiting_for_completion_ = false;
57 void SystemInfoProvider::StartQueryInfoPostInitialization() {
58 PrepareQueryOnUIThread();
59 // Post the custom query info task to blocking pool for information querying
60 // and reply with OnQueryCompleted.
61 base::PostTaskAndReplyWithResult(
64 base::Bind(&SystemInfoProvider::QueryInfo, this),
65 base::Bind(&SystemInfoProvider::OnQueryCompleted, this));
68 } // namespace extensions