Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / api / system_info / system_info_provider.cc
blob3c2cf5fd38c91064d041fe67544ee3bff02624b4
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 "extensions/browser/api/system_info/system_info_provider.h"
7 #include "base/bind.h"
8 #include "content/public/browser/browser_thread.h"
10 namespace extensions {
12 SystemInfoProvider::SystemInfoProvider() : is_waiting_for_completion_(false) {
13 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
14 worker_pool_ = pool->GetSequencedTaskRunnerWithShutdownBehavior(
15 pool->GetSequenceToken(),
16 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
19 SystemInfoProvider::~SystemInfoProvider() {
22 void SystemInfoProvider::PrepareQueryOnUIThread() {
25 void SystemInfoProvider::InitializeProvider(
26 const base::Closure& do_query_info_callback) {
27 do_query_info_callback.Run();
30 void SystemInfoProvider::StartQueryInfo(
31 const QueryInfoCompletionCallback& callback) {
32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
33 DCHECK(!callback.is_null());
35 callbacks_.push(callback);
37 if (is_waiting_for_completion_)
38 return;
40 is_waiting_for_completion_ = true;
42 InitializeProvider(
43 base::Bind(&SystemInfoProvider::StartQueryInfoPostInitialization, this));
46 void SystemInfoProvider::OnQueryCompleted(bool success) {
47 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
49 while (!callbacks_.empty()) {
50 QueryInfoCompletionCallback callback = callbacks_.front();
51 callback.Run(success);
52 callbacks_.pop();
55 is_waiting_for_completion_ = false;
58 void SystemInfoProvider::StartQueryInfoPostInitialization() {
59 PrepareQueryOnUIThread();
60 // Post the custom query info task to blocking pool for information querying
61 // and reply with OnQueryCompleted.
62 base::PostTaskAndReplyWithResult(
63 worker_pool_.get(),
64 FROM_HERE,
65 base::Bind(&SystemInfoProvider::QueryInfo, this),
66 base::Bind(&SystemInfoProvider::OnQueryCompleted, this));
69 } // namespace extensions