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

Side by Side Diff: chrome/browser/chromeos/mobile_config.h

Issue 7778043: [cros] Support global carrier config. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_CHROMEOS_MOBILE_CONFIG_H_
6 #define CHROME_BROWSER_CHROMEOS_MOBILE_CONFIG_H_
7 #pragma once
8
9 #include <map>
10 #include <string>
11 #include <vector>
12
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h"
16 #include "base/time.h"
17
18 class FilePath;
19
20 namespace base {
21 class DictionaryValue;
22 class ListValue;
23 }
24
25 namespace chromeos {
26
27 // Class that processes mobile (carrier) configuration.
28 // Confugration is defined as a JSON file - global and local one.
29 // First global configuration is loaded then local one.
Dmitry Polukhin 2011/09/05 06:33:11 It looks like local file is not implemented yet, r
Nikita (slow) 2011/09/05 10:13:44 Yes, I'll do that in next CL.
30 // All global config is inherited unless some carrier properties are overidden
31 // or carrier deals are explicitly market as non inherited.
32 class MobileConfig {
Dmitry Polukhin 2011/09/05 06:33:11 What about inheriting from CustomizationDocument,
Nikita (slow) 2011/09/05 10:13:44 Done.
33 public:
34 // Carrier deal.
35 class CarrierDeal {
36 public:
37 explicit CarrierDeal(base::DictionaryValue* deal_dict);
38 ~CarrierDeal();
39
40 // Returns string with the specified |locale| and |id|.
41 // If there's no version for |locale|, default one is returned.
42 // If there's no string with specified |id|, empty string is returned.
43 std::string GetLocalizedString(const std::string& locale,
44 const std::string& id) const;
45
46 const std::string& deal_id() const { return deal_id_; }
47 const std::vector<std::string>& locales() const { return locales_; }
48 const std::string& info_url() const { return info_url_; }
49 int notification_count() const { return notification_count_; }
50 base::Time expire_date() const { return expire_date_; }
51
52 private:
53 std::string deal_id_;
54 std::vector<std::string> locales_;
55 std::string info_url_;
56 int notification_count_;
57 base::Time expire_date_;
58 base::DictionaryValue* localized_strings_;
59
60 DISALLOW_COPY_AND_ASSIGN(CarrierDeal);
61 };
62
63 // Carrier config.
64 class Carrier {
65 public:
66 explicit Carrier(base::DictionaryValue* carrier_dict,
67 const std::string& initial_locale);
68 ~Carrier();
69
70 const std::vector<std::string>& external_ids() { return external_ids_; }
71 const std::string& top_up_url() const { return top_up_url_; }
72
73 // Returns "default" carrier deal i.e. first deal defined or NULL
74 // if there're no deals defined.
75 const CarrierDeal* GetDefaultDeal() const;
76
77 // Returns carrier deal by ID.
78 const CarrierDeal* GetDeal(const std::string& deal_id) const;
79
80 private:
81 // Maps deal id to deal instance.
82 typedef std::map<std::string, CarrierDeal*> CarrierDeals;
83
84 std::string top_up_url_;
85 std::vector<std::string> external_ids_;
86
87 CarrierDeals deals_;
88
89 DISALLOW_COPY_AND_ASSIGN(Carrier);
90 };
91
92 // External carrier ID (ex. "Verizon (us)") mapping to internal carrier ID.
93 typedef std::map<std::string, std::string> CarrierIdMap;
94
95 // Internal carrier ID mapping to Carrier config.
96 typedef std::map<std::string, Carrier*> Carriers;
97
98 static MobileConfig* GetInstance();
99
100 // Returns true if config is ready (i.e. has been loaded).
101 bool IsReady();
102
103 // Loads carrier configuration.
104 void LoadConfig();
105
106 // Returns carrier by external ID.
107 const MobileConfig::Carrier* GetCarrier(
108 const std::string& carrier_id) const;
109
110 private:
111 FRIEND_TEST(MobileConfigTest, Basic);
Dmitry Polukhin 2011/09/05 06:33:11 Please replace with FRIEND_TEST_ALL_PREFIXES.
Nikita (slow) 2011/09/05 10:13:44 Done.
112 FRIEND_TEST(MobileConfigTest, BadManifest);
113 FRIEND_TEST(MobileConfigTest, DealOtherLocale);
114 FRIEND_TEST(MobileConfigTest, OldDeal);
115 friend struct DefaultSingletonTraits<MobileConfig>;
116
117 // C-tor for singleton construction.
118 MobileConfig();
119
120 // C-tor for test construction.
121 MobileConfig(const std::string& config,
122 const std::string& initial_locale);
123
124 ~MobileConfig();
125
126 bool LoadConfigFromString(const std::string& config);
127
128 // Executes on FILE thread and reads file to string.
129 void ReadFileInBackground(const FilePath& file);
130
131 scoped_ptr<base::DictionaryValue> root_;
132
133 // Maps external carrier ID to internal carrier ID.
134 CarrierIdMap carrier_id_map_;
135
136 // Carrier configuration (including carrier deals).
137 Carriers carriers_;
138
139 // Initial locale value.
140 std::string initial_locale_;
141
142 DISALLOW_COPY_AND_ASSIGN(MobileConfig);
143 };
144
145 } // namespace chromeos
146
147 #endif // CHROME_BROWSER_CHROMEOS_MOBILE_CONFIG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698