Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/extensions/api/system_info_cpu/system_info_cpu_api.cc

Issue 10830240: Add the implementation skeleton for systeminfo.cpu API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update patch according to mihaip's comment Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/api/system_info_cpu/system_info_cpu_api.h"
5
6 #include "base/logging.h"
7 #include "content/public/browser/browser_thread.h"
8 #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h"
9
10 namespace extensions {
11 using api::experimental_system_info_cpu::CpuInfo;
12 using api::experimental_system_info_cpu::CpuCoreInfo;
13 using content::BrowserThread;
14
15 SystemInfoCpuGetFunction::SystemInfoCpuGetFunction() {
16 }
17
18 SystemInfoCpuGetFunction::~SystemInfoCpuGetFunction() {
19 // Delete the provider that was created on FILE thread.
20 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, provider_);
21 }
22
23 bool SystemInfoCpuGetFunction::RunImpl() {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
25 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
26 base::Bind(&SystemInfoCpuGetFunction::WorkOnFileThread, this));
27 return true;
28 }
29
30 void SystemInfoCpuGetFunction::WorkOnFileThread() {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
32 provider_ = CpuInfoProvider::Create();
33 GetCpuInfoOnFileThread();
34 }
35
36 void SystemInfoCpuGetFunction::GetCpuInfoOnFileThread() {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
38 bool success = false;
39
40 CpuInfo info;
41 if (provider_ && provider_->GetCpuInfo(&info)) {
42 SetResult(info.ToValue().release());
43 success = true;
44 } else {
45 SetError("Error in querying cpu information!");
46 }
47 // Respond on UI thread.
48 BrowserThread::PostTask(
49 BrowserThread::UI, FROM_HERE,
50 base::Bind(&SystemInfoCpuGetFunction::RespondOnUIThread, this, success));
51 }
52
53
54 void SystemInfoCpuGetFunction::RespondOnUIThread(bool success) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 SendResponse(success);
57 }
58
59 // A mock implementation of CpuInfoProver for temporary usage.
60 // Will be moved out when the platform specific implementation are done.
61 class MockCpuInfoProvider : public CpuInfoProvider {
62 public:
63 MockCpuInfoProvider() {}
64 virtual ~MockCpuInfoProvider() {}
65 virtual bool GetCpuInfo(CpuInfo* info) OVERRIDE;
66 };
67
68 bool MockCpuInfoProvider::GetCpuInfo(CpuInfo* info) {
69 if (!info) return false;
70 linked_ptr<CpuCoreInfo> core(new CpuCoreInfo());
71 core->load = 53;
72 info->cores.push_back(core);
73 return true;
74 }
75
76 // static
77 CpuInfoProvider* CpuInfoProvider::Create() {
78 return new MockCpuInfoProvider();
79 }
80
81 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698