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.
5 // Chromecast-specific configurations retrieved from and stored into a given
8 #ifndef CHROMECAST_COMMON_CHROMECAST_CONFIG_H_
9 #define CHROMECAST_COMMON_CHROMECAST_CONFIG_H_
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
{
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.
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 scoped_refptr
<base::SequencedWorkerPool
> worker_pool() const {
56 PrefService
* pref_service() const { return pref_service_
.get(); }
62 // Loads configs from config file. Returns true if successful.
63 bool Load(PrefRegistrySimple
* registry
);
65 // Registers any needed preferences for the current platform.
66 void RegisterPlatformPrefs(PrefRegistrySimple
* registry
);
68 // Global singleton instance.
69 static ChromecastConfig
* g_instance_
;
71 const base::FilePath config_path_
;
72 const scoped_refptr
<base::SequencedWorkerPool
> worker_pool_
;
73 scoped_ptr
<PrefService
> pref_service_
;
75 base::ThreadChecker thread_checker_
;
77 DISALLOW_COPY_AND_ASSIGN(ChromecastConfig
);
80 } // namespace chromecast
82 #endif // CHROMECAST_COMMON_CHROMECAST_CONFIG_H_