Chromium Code Reviews| Index: chrome/browser/extensions/api/system_info_cpu/system_info_cpu_api.cc |
| diff --git a/chrome/browser/extensions/api/system_info_cpu/system_info_cpu_api.cc b/chrome/browser/extensions/api/system_info_cpu/system_info_cpu_api.cc |
| index d226cb8fbd8ea226fe9c3d037b500246ea4934e0..ab2e77ecce4a62118062c81d75876566be6b8731 100644 |
| --- a/chrome/browser/extensions/api/system_info_cpu/system_info_cpu_api.cc |
| +++ b/chrome/browser/extensions/api/system_info_cpu/system_info_cpu_api.cc |
| @@ -1,81 +1,34 @@ |
| // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| + |
| #include "chrome/browser/extensions/api/system_info_cpu/system_info_cpu_api.h" |
| -#include "base/logging.h" |
| -#include "content/public/browser/browser_thread.h" |
| #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h" |
| namespace extensions { |
| + |
| using api::experimental_system_info_cpu::CpuInfo; |
| -using api::experimental_system_info_cpu::CpuCoreInfo; |
| -using content::BrowserThread; |
| SystemInfoCpuGetFunction::SystemInfoCpuGetFunction() { |
| } |
| SystemInfoCpuGetFunction::~SystemInfoCpuGetFunction() { |
| - // Delete the provider that was created on FILE thread. |
| - BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, provider_); |
| } |
| bool SystemInfoCpuGetFunction::RunImpl() { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&SystemInfoCpuGetFunction::WorkOnFileThread, this)); |
| + CpuInfoProvider::Get()->StartGetInfo( |
| + base::Bind(&SystemInfoCpuGetFunction::OnGetCpuInfoCompleted, this)); |
| return true; |
| } |
| -void SystemInfoCpuGetFunction::WorkOnFileThread() { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| - provider_ = CpuInfoProvider::Create(); |
| - GetCpuInfoOnFileThread(); |
| -} |
| - |
| -void SystemInfoCpuGetFunction::GetCpuInfoOnFileThread() { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| - bool success = false; |
| - |
| - CpuInfo info; |
| - if (provider_ && provider_->GetCpuInfo(&info)) { |
| +void SystemInfoCpuGetFunction::OnGetCpuInfoCompleted(const CpuInfo& info, |
| + bool success) { |
| + if (success) |
| SetResult(info.ToValue().release()); |
| - success = true; |
| - } else { |
| - SetError("Error in querying cpu information!"); |
| - } |
| - // Respond on UI thread. |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind(&SystemInfoCpuGetFunction::RespondOnUIThread, this, success)); |
| -} |
| - |
| - |
| -void SystemInfoCpuGetFunction::RespondOnUIThread(bool success) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + else |
| + SetError("Error occurs when querying cpu information."); |
|
Mihai Parparita -not on Chrome
2012/08/21 01:14:52
Nit: "Error occurred when querying CPU information
Hongbo Min
2012/08/21 03:07:11
Done.
|
| SendResponse(success); |
| } |
| -// A mock implementation of CpuInfoProver for temporary usage. |
| -// Will be moved out when the platform specific implementation are done. |
| -class MockCpuInfoProvider : public CpuInfoProvider { |
| - public: |
| - MockCpuInfoProvider() {} |
| - virtual ~MockCpuInfoProvider() {} |
| - virtual bool GetCpuInfo(CpuInfo* info) OVERRIDE; |
| -}; |
| - |
| -bool MockCpuInfoProvider::GetCpuInfo(CpuInfo* info) { |
| - if (!info) return false; |
| - linked_ptr<CpuCoreInfo> core(new CpuCoreInfo()); |
| - core->load = 53; |
| - info->cores.push_back(core); |
| - return true; |
| -} |
| - |
| -// static |
| -CpuInfoProvider* CpuInfoProvider::Create() { |
| - return new MockCpuInfoProvider(); |
| -} |
| - |
| } // namespace extensions |