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