OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/extensions/api/system_memory/memory_info_provider.h" | |
6 | |
7 #include "base/sys_info.h" | |
8 | |
9 namespace extensions { | |
10 | |
11 using api::system_memory::MemoryInfo; | |
12 | |
13 // Static member intialization. | |
14 base::LazyInstance<scoped_refptr<MemoryInfoProvider> > | |
15 MemoryInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; | |
16 | |
17 MemoryInfoProvider::MemoryInfoProvider() {} | |
18 | |
19 MemoryInfoProvider::~MemoryInfoProvider() {} | |
20 | |
21 const MemoryInfo& MemoryInfoProvider::memory_info() const { | |
22 return info_; | |
23 } | |
24 | |
25 void MemoryInfoProvider::InitializeForTesting( | |
26 scoped_refptr<MemoryInfoProvider> provider) { | |
27 DCHECK(provider.get() != NULL); | |
28 provider_.Get() = provider; | |
29 } | |
30 | |
31 bool MemoryInfoProvider::QueryInfo() { | |
32 info_.capacity = static_cast<double>(base::SysInfo::AmountOfPhysicalMemory()); | |
33 info_.available_capacity = | |
34 static_cast<double>(base::SysInfo::AmountOfAvailablePhysicalMemory()); | |
35 return true; | |
36 } | |
37 | |
38 // static | |
39 MemoryInfoProvider* MemoryInfoProvider::Get() { | |
40 if (provider_.Get().get() == NULL) | |
41 provider_.Get() = new MemoryInfoProvider(); | |
42 return provider_.Get().get(); | |
43 } | |
44 | |
45 } // namespace extensions | |
OLD | NEW |