Chromium Code Reviews| Index: chrome/browser/chromeos/mobile_config.h |
| diff --git a/chrome/browser/chromeos/mobile_config.h b/chrome/browser/chromeos/mobile_config.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5f5effe7778080e32f9ad76d3d18e9b337f56559 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/mobile_config.h |
| @@ -0,0 +1,147 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_MOBILE_CONFIG_H_ |
| +#define CHROME_BROWSER_CHROMEOS_MOBILE_CONFIG_H_ |
| +#pragma once |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/gtest_prod_util.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/singleton.h" |
| +#include "base/time.h" |
| + |
| +class FilePath; |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +class ListValue; |
| +} |
| + |
| +namespace chromeos { |
| + |
| +// Class that processes mobile (carrier) configuration. |
| +// Confugration is defined as a JSON file - global and local one. |
| +// 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.
|
| +// All global config is inherited unless some carrier properties are overidden |
| +// or carrier deals are explicitly market as non inherited. |
| +class MobileConfig { |
|
Dmitry Polukhin
2011/09/05 06:33:11
What about inheriting from CustomizationDocument,
Nikita (slow)
2011/09/05 10:13:44
Done.
|
| + public: |
| + // Carrier deal. |
| + class CarrierDeal { |
| + public: |
| + explicit CarrierDeal(base::DictionaryValue* deal_dict); |
| + ~CarrierDeal(); |
| + |
| + // Returns string with the specified |locale| and |id|. |
| + // If there's no version for |locale|, default one is returned. |
| + // If there's no string with specified |id|, empty string is returned. |
| + std::string GetLocalizedString(const std::string& locale, |
| + const std::string& id) const; |
| + |
| + const std::string& deal_id() const { return deal_id_; } |
| + const std::vector<std::string>& locales() const { return locales_; } |
| + const std::string& info_url() const { return info_url_; } |
| + int notification_count() const { return notification_count_; } |
| + base::Time expire_date() const { return expire_date_; } |
| + |
| + private: |
| + std::string deal_id_; |
| + std::vector<std::string> locales_; |
| + std::string info_url_; |
| + int notification_count_; |
| + base::Time expire_date_; |
| + base::DictionaryValue* localized_strings_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CarrierDeal); |
| + }; |
| + |
| + // Carrier config. |
| + class Carrier { |
| + public: |
| + explicit Carrier(base::DictionaryValue* carrier_dict, |
| + const std::string& initial_locale); |
| + ~Carrier(); |
| + |
| + const std::vector<std::string>& external_ids() { return external_ids_; } |
| + const std::string& top_up_url() const { return top_up_url_; } |
| + |
| + // Returns "default" carrier deal i.e. first deal defined or NULL |
| + // if there're no deals defined. |
| + const CarrierDeal* GetDefaultDeal() const; |
| + |
| + // Returns carrier deal by ID. |
| + const CarrierDeal* GetDeal(const std::string& deal_id) const; |
| + |
| + private: |
| + // Maps deal id to deal instance. |
| + typedef std::map<std::string, CarrierDeal*> CarrierDeals; |
| + |
| + std::string top_up_url_; |
| + std::vector<std::string> external_ids_; |
| + |
| + CarrierDeals deals_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Carrier); |
| + }; |
| + |
| + // External carrier ID (ex. "Verizon (us)") mapping to internal carrier ID. |
| + typedef std::map<std::string, std::string> CarrierIdMap; |
| + |
| + // Internal carrier ID mapping to Carrier config. |
| + typedef std::map<std::string, Carrier*> Carriers; |
| + |
| + static MobileConfig* GetInstance(); |
| + |
| + // Returns true if config is ready (i.e. has been loaded). |
| + bool IsReady(); |
| + |
| + // Loads carrier configuration. |
| + void LoadConfig(); |
| + |
| + // Returns carrier by external ID. |
| + const MobileConfig::Carrier* GetCarrier( |
| + const std::string& carrier_id) const; |
| + |
| + private: |
| + 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.
|
| + FRIEND_TEST(MobileConfigTest, BadManifest); |
| + FRIEND_TEST(MobileConfigTest, DealOtherLocale); |
| + FRIEND_TEST(MobileConfigTest, OldDeal); |
| + friend struct DefaultSingletonTraits<MobileConfig>; |
| + |
| + // C-tor for singleton construction. |
| + MobileConfig(); |
| + |
| + // C-tor for test construction. |
| + MobileConfig(const std::string& config, |
| + const std::string& initial_locale); |
| + |
| + ~MobileConfig(); |
| + |
| + bool LoadConfigFromString(const std::string& config); |
| + |
| + // Executes on FILE thread and reads file to string. |
| + void ReadFileInBackground(const FilePath& file); |
| + |
| + scoped_ptr<base::DictionaryValue> root_; |
| + |
| + // Maps external carrier ID to internal carrier ID. |
| + CarrierIdMap carrier_id_map_; |
| + |
| + // Carrier configuration (including carrier deals). |
| + Carriers carriers_; |
| + |
| + // Initial locale value. |
| + std::string initial_locale_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MobileConfig); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_MOBILE_CONFIG_H_ |