blob: f83dd79f0a4e4964a69ea4cc257f4236935021b4 [file] [log] [blame]
Ben Murdocha3f7b4e2013-07-24 10:36:34 +01001// 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#ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_MEMORY_MEMORY_INFO_PROVIDER_H_
6#define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_MEMORY_MEMORY_INFO_PROVIDER_H_
7
Ben Murdochbb1529c2013-08-08 10:24:53 +01008#include "base/lazy_instance.h"
Ben Murdocha3f7b4e2013-07-24 10:36:34 +01009#include "chrome/browser/extensions/api/system_info/system_info_provider.h"
10#include "chrome/common/extensions/api/system_memory.h"
11
12namespace extensions {
13
Ben Murdochbb1529c2013-08-08 10:24:53 +010014class MemoryInfoProvider : public SystemInfoProvider {
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010015 public:
16 static MemoryInfoProvider* Get();
17
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010018 const api::system_memory::MemoryInfo& memory_info() const;
19
Ben Murdochbb1529c2013-08-08 10:24:53 +010020 static void InitializeForTesting(scoped_refptr<MemoryInfoProvider> provider);
21
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010022 private:
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010023 friend class MockMemoryInfoProviderImpl;
24
25 MemoryInfoProvider();
26 virtual ~MemoryInfoProvider();
27
Ben Murdochbb1529c2013-08-08 10:24:53 +010028 // Overriden from SystemInfoProvider.
29 virtual bool QueryInfo() OVERRIDE;
30
31 // The last information filled up by QueryInfo and is accessed on multiple
32 // threads, but the whole class is being guarded by SystemInfoProvider base
33 // class.
34 //
35 // |info_| is accessed on the UI thread while |is_waiting_for_completion_| is
36 // false and on the sequenced worker pool while |is_waiting_for_completion_|
37 // is true.
38 api::system_memory::MemoryInfo info_;
39
40 static base::LazyInstance<scoped_refptr<MemoryInfoProvider> > provider_;
41
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010042 DISALLOW_COPY_AND_ASSIGN(MemoryInfoProvider);
43};
44
45} // namespace extensions
46
47#endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_MEMORY_MEMORY_INFO_PROVIDER_H_