blob: 07f233ba09072171b07c46299f5c389ef01af221 [file] [log] [blame]
Ben Murdochbb1529c2013-08-08 10:24:53 +01001// 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.
4
5#include "chrome/browser/extensions/api/system_info/system_info_provider.h"
6
7namespace extensions {
8
9SystemInfoProvider::SystemInfoProvider()
10 : is_waiting_for_completion_(false) {
11 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
12 worker_pool_ = pool->GetSequencedTaskRunnerWithShutdownBehavior(
13 pool->GetSequenceToken(),
14 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
15}
16
17SystemInfoProvider::~SystemInfoProvider() {}
18
19void SystemInfoProvider::PrepareQueryOnUIThread() {}
20
21void SystemInfoProvider::InitializeProvider(const base::Closure&
22 do_query_info_callback) {
23 do_query_info_callback.Run();
24}
25
26void SystemInfoProvider::StartQueryInfo(
27 const QueryInfoCompletionCallback& callback) {
28 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
29 DCHECK(!callback.is_null());
30
31 callbacks_.push(callback);
32
33 if (is_waiting_for_completion_)
34 return;
35
36 is_waiting_for_completion_ = true;
37
38 InitializeProvider(base::Bind(
39 &SystemInfoProvider::StartQueryInfoPostInitialization, this));
40}
41
42void SystemInfoProvider::OnQueryCompleted(bool success) {
43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
44
45 while (!callbacks_.empty()) {
46 QueryInfoCompletionCallback callback = callbacks_.front();
47 callback.Run(success);
48 callbacks_.pop();
49 }
50
51 is_waiting_for_completion_ = false;
52}
53
54void SystemInfoProvider::StartQueryInfoPostInitialization() {
55 PrepareQueryOnUIThread();
56 // Post the custom query info task to blocking pool for information querying
57 // and reply with OnQueryCompleted.
58 base::PostTaskAndReplyWithResult(
59 worker_pool_,
60 FROM_HERE,
61 base::Bind(&SystemInfoProvider::QueryInfo, this),
62 base::Bind(&SystemInfoProvider::OnQueryCompleted, this));
63}
64
65} // namespace extensions