Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / chromecast / common / chromecast_config.h
blob23482c6be4d876fa4f3f7ca8d54d10b14a740003
1 // Copyright 2014 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 // Chromecast-specific configurations retrieved from and stored into a given
6 // configuration file.
8 #ifndef CHROMECAST_COMMON_CHROMECAST_CONFIG_H_
9 #define CHROMECAST_COMMON_CHROMECAST_CONFIG_H_
11 #include <string>
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/prefs/pref_service.h"
17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/threading/thread_checker.h"
20 class PrefRegistrySimple;
22 namespace chromecast {
24 // Manages configuration for Chromecast via PrefService.
25 // It uses JsonPrefStore internally and/so the format of config file is same to
26 // that of JsonPrefStore.
27 // It is NOT thread-safe; all functions must be run on the same thread as
28 // the object is created.
29 class ChromecastConfig {
30 public:
31 // Creates new singleton instance of ChromecastConfig.
32 static void Create(PrefRegistrySimple* registry);
34 // Returns the singleton instance of ChromecastConfig.
35 static ChromecastConfig* GetInstance();
37 // Saves configs into configuration file.
38 void Save() const;
40 // Returns string value for |key|, if present.
41 const std::string GetValue(const std::string& key) const;
43 // Returns integer value for |key|, if present.
44 const int GetIntValue(const std::string& key) const;
46 // Sets new string value for |key|.
47 void SetValue(const std::string& key, const std::string& value) const;
49 // Sets new int value for |key|.
50 void SetIntValue(const std::string& key, int value) const;
52 // Whether or not a value has been set for |key|.
53 bool HasValue(const std::string& key) const;
55 scoped_refptr<base::SequencedWorkerPool> worker_pool() const {
56 return worker_pool_;
59 PrefService* pref_service() const { return pref_service_.get(); }
61 private:
62 ChromecastConfig();
63 ~ChromecastConfig();
65 // Loads configs from config file. Returns true if successful.
66 bool Load(PrefRegistrySimple* registry);
68 // Registers any needed preferences for the current platform.
69 void RegisterPlatformPrefs(PrefRegistrySimple* registry);
71 // Global singleton instance.
72 static ChromecastConfig* g_instance_;
74 const base::FilePath config_path_;
75 const scoped_refptr<base::SequencedWorkerPool> worker_pool_;
76 scoped_ptr<PrefService> pref_service_;
78 base::ThreadChecker thread_checker_;
80 DISALLOW_COPY_AND_ASSIGN(ChromecastConfig);
83 } // namespace chromecast
85 #endif // CHROMECAST_COMMON_CHROMECAST_CONFIG_H_