| OLD | NEW |
| (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 #include "chrome/browser/chromeos/customization_document.h" |
| 18 |
| 19 class FilePath; |
| 20 |
| 21 namespace base { |
| 22 class DictionaryValue; |
| 23 class ListValue; |
| 24 } |
| 25 |
| 26 namespace chromeos { |
| 27 |
| 28 // Class that processes mobile (carrier) configuration. |
| 29 // Confugration is defined as a JSON file - global and local one. |
| 30 // First global configuration is loaded then local one. |
| 31 // All global config is inherited unless some carrier properties are overidden |
| 32 // or carrier deals are explicitly market as non inherited. |
| 33 // TODO(nkostylev): Load local config. |
| 34 class MobileConfig : public CustomizationDocument { |
| 35 public: |
| 36 // Carrier deal. |
| 37 class CarrierDeal { |
| 38 public: |
| 39 explicit CarrierDeal(base::DictionaryValue* deal_dict); |
| 40 ~CarrierDeal(); |
| 41 |
| 42 // Returns string with the specified |locale| and |id|. |
| 43 // If there's no version for |locale|, default one is returned. |
| 44 // If there's no string with specified |id|, empty string is returned. |
| 45 std::string GetLocalizedString(const std::string& locale, |
| 46 const std::string& id) const; |
| 47 |
| 48 const std::string& deal_id() const { return deal_id_; } |
| 49 const std::vector<std::string>& locales() const { return locales_; } |
| 50 const std::string& info_url() const { return info_url_; } |
| 51 int notification_count() const { return notification_count_; } |
| 52 base::Time expire_date() const { return expire_date_; } |
| 53 |
| 54 private: |
| 55 std::string deal_id_; |
| 56 std::vector<std::string> locales_; |
| 57 std::string info_url_; |
| 58 int notification_count_; |
| 59 base::Time expire_date_; |
| 60 base::DictionaryValue* localized_strings_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(CarrierDeal); |
| 63 }; |
| 64 |
| 65 // Carrier config. |
| 66 class Carrier { |
| 67 public: |
| 68 explicit Carrier(base::DictionaryValue* carrier_dict, |
| 69 const std::string& initial_locale); |
| 70 ~Carrier(); |
| 71 |
| 72 const std::vector<std::string>& external_ids() { return external_ids_; } |
| 73 const std::string& top_up_url() const { return top_up_url_; } |
| 74 |
| 75 // Returns "default" carrier deal i.e. first deal defined or NULL |
| 76 // if there're no deals defined. |
| 77 const CarrierDeal* GetDefaultDeal() const; |
| 78 |
| 79 // Returns carrier deal by ID. |
| 80 const CarrierDeal* GetDeal(const std::string& deal_id) const; |
| 81 |
| 82 private: |
| 83 // Maps deal id to deal instance. |
| 84 typedef std::map<std::string, CarrierDeal*> CarrierDeals; |
| 85 |
| 86 std::string top_up_url_; |
| 87 std::vector<std::string> external_ids_; |
| 88 |
| 89 CarrierDeals deals_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(Carrier); |
| 92 }; |
| 93 |
| 94 // External carrier ID (ex. "Verizon (us)") mapping to internal carrier ID. |
| 95 typedef std::map<std::string, std::string> CarrierIdMap; |
| 96 |
| 97 // Internal carrier ID mapping to Carrier config. |
| 98 typedef std::map<std::string, Carrier*> Carriers; |
| 99 |
| 100 static MobileConfig* GetInstance(); |
| 101 |
| 102 // Loads carrier configuration. |
| 103 void LoadConfig(); |
| 104 |
| 105 // Returns carrier by external ID. |
| 106 const MobileConfig::Carrier* GetCarrier(const std::string& carrier_id) const; |
| 107 |
| 108 protected: |
| 109 virtual bool LoadManifestFromString(const std::string& manifest) OVERRIDE; |
| 110 |
| 111 private: |
| 112 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, Basic); |
| 113 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, BadManifest); |
| 114 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, DealOtherLocale); |
| 115 FRIEND_TEST_ALL_PREFIXES(MobileConfigTest, OldDeal); |
| 116 friend struct DefaultSingletonTraits<MobileConfig>; |
| 117 |
| 118 // C-tor for singleton construction. |
| 119 MobileConfig(); |
| 120 |
| 121 // C-tor for test construction. |
| 122 MobileConfig(const std::string& config, |
| 123 const std::string& initial_locale); |
| 124 |
| 125 virtual ~MobileConfig(); |
| 126 |
| 127 // Executes on FILE thread and reads file to string. |
| 128 void ReadFileInBackground(const FilePath& file); |
| 129 |
| 130 // Maps external carrier ID to internal carrier ID. |
| 131 CarrierIdMap carrier_id_map_; |
| 132 |
| 133 // Carrier configuration (including carrier deals). |
| 134 Carriers carriers_; |
| 135 |
| 136 // Initial locale value. |
| 137 std::string initial_locale_; |
| 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(MobileConfig); |
| 140 }; |
| 141 |
| 142 } // namespace chromeos |
| 143 |
| 144 #endif // CHROME_BROWSER_CHROMEOS_MOBILE_CONFIG_H_ |
| OLD | NEW |