Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / chromeos / mobile_config.h
blobd422ed4cd76606ddfcaac79e5aa73e7005b5a99e
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_CHROMEOS_MOBILE_CONFIG_H_
6 #define CHROME_BROWSER_CHROMEOS_MOBILE_CONFIG_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/singleton.h"
15 #include "base/time.h"
16 #include "chrome/browser/chromeos/customization_document.h"
18 class FilePath;
20 namespace base {
21 class DictionaryValue;
24 namespace chromeos {
26 // Class that processes mobile (carrier) configuration.
27 // Confugration is defined as a JSON file - global and local one.
28 // First global configuration is loaded then local one if it exists.
29 // Notes on global/local configuration:
30 // 1. All global config data is inherited unless some carrier properties
31 // are overidden or carrier deals are explicitly marked as excluded.
32 // 2. Local config could mark that all carrier deals should be excluded or
33 // only specific carrier deals are excluded.
34 // 3. New ID mappings in local config are not supported.
35 // 4. If local config exists, at least trivial global config should exist too.
36 // 5. If any error occurs while parsing global/local config,
37 // MobileConfig::IsReady() will return false.
38 class MobileConfig : public CustomizationDocument {
39 public:
40 // Carrier deal.
41 class CarrierDeal {
42 public:
43 explicit CarrierDeal(base::DictionaryValue* deal_dict);
44 ~CarrierDeal();
46 // Returns string with the specified |locale| and |id|.
47 // If there's no version for |locale|, default one is returned.
48 // If there's no string with specified |id|, empty string is returned.
49 std::string GetLocalizedString(const std::string& locale,
50 const std::string& id) const;
52 const std::string& deal_id() const { return deal_id_; }
53 const std::vector<std::string>& locales() const { return locales_; }
54 const std::string& info_url() const { return info_url_; }
55 int notification_count() const { return notification_count_; }
56 base::Time expire_date() const { return expire_date_; }
58 private:
59 std::string deal_id_;
60 std::vector<std::string> locales_;
61 std::string info_url_;
62 int notification_count_;
63 base::Time expire_date_;
64 base::DictionaryValue* localized_strings_;
66 DISALLOW_COPY_AND_ASSIGN(CarrierDeal);
69 // Carrier config.
70 class Carrier {
71 public:
72 Carrier(base::DictionaryValue* carrier_dict,
73 const std::string& initial_locale);
74 ~Carrier();
76 const std::vector<std::string>& external_ids() { return external_ids_; }
77 const std::string& top_up_url() const { return top_up_url_; }
78 bool show_portal_button() const { return show_portal_button_; }
80 // Returns "default" carrier deal i.e. first deal defined or NULL
81 // if there're no deals defined.
82 const CarrierDeal* GetDefaultDeal() const;
84 // Returns carrier deal by ID.
85 const CarrierDeal* GetDeal(const std::string& deal_id) const;
87 // Initializes carrier from supplied dictionary.
88 // Multiple calls supported (i.e. second call for local config).
89 void InitFromDictionary(base::DictionaryValue* carrier_dict,
90 const std::string& initial_locale);
92 // Removes all carrier deals. Might be executed when local config is loaded.
93 void RemoveDeals();
95 private:
96 // Maps deal id to deal instance.
97 typedef std::map<std::string, CarrierDeal*> CarrierDeals;
99 // List of external IDs that should map to this carrier.
100 std::vector<std::string> external_ids_;
102 // Top-up URL. Used in network menu ("View account" link) +
103 // carrier name in network details (in settings) is a link.
104 std::string top_up_url_;
106 // If true, show a separate "View account" button on network details page
107 // even if device is activated and doesn't need new data plan.
108 // It's not shown when one of the "Buy plan" / "Activate" is shown.
109 // All "Buy plan" / "Activate" / "View account" buttons launch
110 // carrier portal (chrome://mobilesetup/ extension).
111 bool show_portal_button_;
113 CarrierDeals deals_;
115 DISALLOW_COPY_AND_ASSIGN(Carrier);
118 // Carrier config for a specific initial locale.
119 class LocaleConfig {
120 public:
121 explicit LocaleConfig(base::DictionaryValue* locale_dict);
122 ~LocaleConfig();
124 const std::string& setup_url() const { return setup_url_; }
126 // Initializes local config carrier from supplied dictionary.
127 // Multiple calls supported (i.e. second call for local config).
128 void InitFromDictionary(base::DictionaryValue* locale_dict);
130 private:
131 // Carrier setup URL. Used in network menu ("Set-up Mobile Data" link).
132 // Displayed when SIM card is not installed on the device with a
133 // particular initial locale.
134 std::string setup_url_;
136 DISALLOW_COPY_AND_ASSIGN(LocaleConfig);
139 // External carrier ID (ex. "Verizon (us)") mapping to internal carrier ID.
140 typedef std::map<std::string, std::string> CarrierIdMap;
142 // Internal carrier ID mapping to Carrier config.
143 typedef std::map<std::string, Carrier*> Carriers;
145 static MobileConfig* GetInstance();
147 // Returns carrier by external ID or NULL if there's no such carrier.
148 const MobileConfig::Carrier* GetCarrier(const std::string& carrier_id) const;
150 // Returns locale specific config by initial locale or NULL
151 // if there's no such config defined.
152 const MobileConfig::LocaleConfig* GetLocaleConfig() const;
154 protected:
155 virtual bool LoadManifestFromString(const std::string& manifest) OVERRIDE;
157 private:
158 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, Basic);
159 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, BadManifest);
160 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, DealOtherLocale);
161 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, OldDeal);
162 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, LocalConfigNoDeals);
163 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, LocalConfig);
164 friend struct DefaultSingletonTraits<MobileConfig>;
166 // C-tor for singleton construction.
167 MobileConfig();
169 // C-tor for test construction.
170 MobileConfig(const std::string& config,
171 const std::string& initial_locale);
173 virtual ~MobileConfig();
175 // Loads carrier configuration.
176 void LoadConfig();
178 // Processes global/local config.
179 void ProcessConfig(const std::string& global_config,
180 const std::string& local_config);
182 // Executes on FILE thread and reads config files to string.
183 void ReadConfigInBackground(const FilePath& global_config_file,
184 const FilePath& local_config_file);
186 // Maps external carrier ID to internal carrier ID.
187 CarrierIdMap carrier_id_map_;
189 // Carrier configuration (including carrier deals).
190 Carriers carriers_;
192 // Initial locale specific config if defined.
193 scoped_ptr<LocaleConfig> locale_config_;
195 // Initial locale value.
196 std::string initial_locale_;
198 // Root value of the local config (if it exists).
199 // Global config is stored in root_ of the base class.
200 scoped_ptr<base::DictionaryValue> local_config_root_;
202 DISALLOW_COPY_AND_ASSIGN(MobileConfig);
205 } // namespace chromeos
207 #endif // CHROME_BROWSER_CHROMEOS_MOBILE_CONFIG_H_