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

Side by Side Diff: chromecast/common/chromecast_config.h

Issue 443833002: Adds ChromecastConfig to manage cast_shell's PrefService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@build-breakpages
Patch Set: address lcwu's comments Created 6 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
« no previous file with comments | « chromecast/common/cast_paths.cc ('k') | chromecast/common/chromecast_config.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
7
8 #ifndef CHROMECAST_COMMON_CHROMECAST_CONFIG_H_
9 #define CHROMECAST_COMMON_CHROMECAST_CONFIG_H_
10
11 #include <string>
12
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"
19
20 class PrefRegistrySimple;
21
22 namespace chromecast {
23
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);
33
34 // Returns the singleton instance of ChromecastConfig.
35 static ChromecastConfig* GetInstance();
36
37 // Saves configs into configuration file.
38 void Save() const;
39
40 // Returns string value for key, if present.
41 const std::string GetValue(const std::string& key) const;
42
43 // Returns integer value for key, if present.
44 const int GetIntValue(const std::string& key) const;
45
46 // Sets new string value for key.
47 void SetValue(const std::string& key, const std::string& value) const;
48
49 // Sets new int value for key.
50 void SetIntValue(const std::string& key, int value) const;
51
52 scoped_refptr<base::SequencedWorkerPool> worker_pool() const {
53 return worker_pool_;
54 }
55
56 PrefService* pref_service() const { return pref_service_.get(); }
57
58 private:
59 ChromecastConfig();
60 ~ChromecastConfig();
61
62 // Loads configs from config file. Returns true if successful.
63 bool Load(PrefRegistrySimple* registry);
64
65 // Registers any needed preferences for the current platform.
66 void RegisterPlatformPrefs(PrefRegistrySimple* registry);
67
68 // Global singleton instance.
69 static ChromecastConfig* g_instance_;
70
71 const base::FilePath config_path_;
72 const scoped_refptr<base::SequencedWorkerPool> worker_pool_;
73 scoped_ptr<PrefService> pref_service_;
74
75 base::ThreadChecker thread_checker_;
76
77 DISALLOW_COPY_AND_ASSIGN(ChromecastConfig);
78 };
79
80 } // namespace chromecast
81
82 #endif // CHROMECAST_COMMON_CHROMECAST_CONFIG_H_
OLDNEW
« no previous file with comments | « chromecast/common/cast_paths.cc ('k') | chromecast/common/chromecast_config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698