| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | |
| 10 #include <string> | 9 #include <string> |
| 11 | 10 |
| 12 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 15 #include "base/timer.h" | 14 #include "base/timer.h" |
| 16 #include "base/values.h" | 15 #include "base/values.h" |
| 17 #include "content/common/url_fetcher.h" | 16 #include "content/common/url_fetcher.h" |
| 18 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 19 | 18 |
| 20 class FilePath; | 19 class FilePath; |
| 21 class PrefService; | 20 class PrefService; |
| 22 | 21 |
| 23 namespace base { | 22 namespace base { |
| 24 class DictionaryValue; | 23 class DictionaryValue; |
| 25 class ListValue; | 24 class ListValue; |
| 26 class Time; | |
| 27 } | 25 } |
| 28 | 26 |
| 29 namespace chromeos { | 27 namespace chromeos { |
| 30 | 28 |
| 31 namespace system { | 29 namespace system { |
| 32 class StatisticsProvider; | 30 class StatisticsProvider; |
| 33 } // system | 31 } // system |
| 34 | 32 |
| 35 // Base class for OEM customization document classes. | 33 // Base class for OEM customization document classes. |
| 36 class CustomizationDocument { | 34 class CustomizationDocument { |
| 37 public: | 35 public: |
| 38 virtual ~CustomizationDocument(); | 36 virtual ~CustomizationDocument(); |
| 39 | 37 |
| 40 // Return true if the document was successfully fetched and parsed. | 38 // Return true if the document was successfully fetched and parsed. |
| 41 bool IsReady() const { return root_.get(); } | 39 bool IsReady() const { return root_.get(); } |
| 42 | 40 |
| 43 protected: | 41 protected: |
| 44 CustomizationDocument(); | 42 explicit CustomizationDocument(const std::string& accepted_version); |
| 45 | 43 |
| 46 virtual bool LoadManifestFromFile(const FilePath& manifest_path); | 44 virtual bool LoadManifestFromFile(const FilePath& manifest_path); |
| 47 virtual bool LoadManifestFromString(const std::string& manifest); | 45 virtual bool LoadManifestFromString(const std::string& manifest); |
| 48 | 46 |
| 49 std::string GetLocaleSpecificString(const std::string& locale, | 47 std::string GetLocaleSpecificString(const std::string& locale, |
| 50 const std::string& dictionary_name, | 48 const std::string& dictionary_name, |
| 51 const std::string& entry_name) const; | 49 const std::string& entry_name) const; |
| 52 | 50 |
| 53 scoped_ptr<base::DictionaryValue> root_; | 51 scoped_ptr<base::DictionaryValue> root_; |
| 54 | 52 |
| 53 // Value of the "version" attribute that is supported. |
| 54 // Otherwise config is not loaded. |
| 55 std::string accepted_version_; |
| 56 |
| 55 private: | 57 private: |
| 56 DISALLOW_COPY_AND_ASSIGN(CustomizationDocument); | 58 DISALLOW_COPY_AND_ASSIGN(CustomizationDocument); |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 // OEM startup customization document class. | 61 // OEM startup customization document class. |
| 60 // Now StartupCustomizationDocument is loaded in c-tor so just after create it | 62 // Now StartupCustomizationDocument is loaded in c-tor so just after create it |
| 61 // may be ready or not (if manifest is missing or corrupted) and this state | 63 // may be ready or not (if manifest is missing or corrupted) and this state |
| 62 // won't be changed later (i.e. IsReady() always return the same value). | 64 // won't be changed later (i.e. IsReady() always return the same value). |
| 63 class StartupCustomizationDocument : public CustomizationDocument { | 65 class StartupCustomizationDocument : public CustomizationDocument { |
| 64 public: | 66 public: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 }; | 106 }; |
| 105 | 107 |
| 106 // OEM services customization document class. | 108 // OEM services customization document class. |
| 107 // ServicesCustomizationDocument is fetched from network or local file but on | 109 // ServicesCustomizationDocument is fetched from network or local file but on |
| 108 // FILE thread therefore it may not be ready just after creation. Fetching of | 110 // FILE thread therefore it may not be ready just after creation. Fetching of |
| 109 // the manifest should be initiated outside this class by calling | 111 // the manifest should be initiated outside this class by calling |
| 110 // StartFetching() method. User of the file should check IsReady before use it. | 112 // StartFetching() method. User of the file should check IsReady before use it. |
| 111 class ServicesCustomizationDocument : public CustomizationDocument, | 113 class ServicesCustomizationDocument : public CustomizationDocument, |
| 112 private URLFetcher::Delegate { | 114 private URLFetcher::Delegate { |
| 113 public: | 115 public: |
| 114 // OEM specific carrier deal. | |
| 115 class CarrierDeal { | |
| 116 public: | |
| 117 explicit CarrierDeal(base::DictionaryValue* deal_dict); | |
| 118 ~CarrierDeal(); | |
| 119 | |
| 120 // Returns string with the specified |locale| and |id|. | |
| 121 // If there's no version for |locale|, default one is returned. | |
| 122 // If there's no string with specified |id|, empty string is returned. | |
| 123 std::string GetLocalizedString(const std::string& locale, | |
| 124 const std::string& id) const; | |
| 125 | |
| 126 const std::string& deal_locale() const { return deal_locale_; } | |
| 127 const std::string& info_url() const { return info_url_; } | |
| 128 const std::string& top_up_url() const { return top_up_url_; } | |
| 129 int notification_count() const { return notification_count_; } | |
| 130 base::Time expire_date() const { return expire_date_; } | |
| 131 | |
| 132 private: | |
| 133 std::string deal_locale_; | |
| 134 std::string info_url_; | |
| 135 std::string top_up_url_; | |
| 136 int notification_count_; | |
| 137 base::Time expire_date_; | |
| 138 base::DictionaryValue* localized_strings_; | |
| 139 | |
| 140 DISALLOW_COPY_AND_ASSIGN(CarrierDeal); | |
| 141 }; | |
| 142 | |
| 143 // Carrier ID (ex. "Verizon (us)") mapping to carrier deals. | |
| 144 typedef std::map<std::string, CarrierDeal*> CarrierDeals; | |
| 145 | |
| 146 static ServicesCustomizationDocument* GetInstance(); | 116 static ServicesCustomizationDocument* GetInstance(); |
| 147 | 117 |
| 148 // Registers preferences. | 118 // Registers preferences. |
| 149 static void RegisterPrefs(PrefService* local_state); | 119 static void RegisterPrefs(PrefService* local_state); |
| 150 | 120 |
| 151 // Return true if the customization was applied. Customization is applied only | 121 // Return true if the customization was applied. Customization is applied only |
| 152 // once per machine. | 122 // once per machine. |
| 153 static bool WasApplied(); | 123 static bool WasApplied(); |
| 154 | 124 |
| 155 // Start fetching customization document. | 125 // Start fetching customization document. |
| 156 void StartFetching(); | 126 void StartFetching(); |
| 157 | 127 |
| 158 // Apply customization and save in machine options that customization was | 128 // Apply customization and save in machine options that customization was |
| 159 // applied successfully. Return true if customization was applied. | 129 // applied successfully. Return true if customization was applied. |
| 160 bool ApplyCustomization(); | 130 bool ApplyCustomization(); |
| 161 | 131 |
| 162 std::string GetInitialStartPage(const std::string& locale) const; | 132 std::string GetInitialStartPage(const std::string& locale) const; |
| 163 std::string GetSupportPage(const std::string& locale) const; | 133 std::string GetSupportPage(const std::string& locale) const; |
| 164 | 134 |
| 165 // Returns carrier deal by specified |carrier_id|. | |
| 166 // Also checks deal restrictions, such as deal locale (launch locale) and | |
| 167 // deal expiration date if |check_restrictions| is true. | |
| 168 const ServicesCustomizationDocument::CarrierDeal* GetCarrierDeal( | |
| 169 const std::string& carrier_id, bool check_restrictions) const; | |
| 170 | |
| 171 protected: | |
| 172 virtual bool LoadManifestFromString(const std::string& manifest) OVERRIDE; | |
| 173 | |
| 174 private: | 135 private: |
| 175 FRIEND_TEST(ServicesCustomizationDocumentTest, Basic); | 136 FRIEND_TEST_ALL_PREFIXES(ServicesCustomizationDocumentTest, Basic); |
| 176 FRIEND_TEST(ServicesCustomizationDocumentTest, BadManifest); | 137 FRIEND_TEST_ALL_PREFIXES(ServicesCustomizationDocumentTest, BadManifest); |
| 177 FRIEND_TEST(ServicesCustomizationDocumentTest, DealOtherLocale); | |
| 178 FRIEND_TEST(ServicesCustomizationDocumentTest, NoDealRestrictions); | |
| 179 FRIEND_TEST(ServicesCustomizationDocumentTest, OldDeal); | |
| 180 friend struct DefaultSingletonTraits<ServicesCustomizationDocument>; | 138 friend struct DefaultSingletonTraits<ServicesCustomizationDocument>; |
| 181 | 139 |
| 182 // C-tor for singleton construction. | 140 // C-tor for singleton construction. |
| 183 ServicesCustomizationDocument(); | 141 ServicesCustomizationDocument(); |
| 184 | 142 |
| 185 // C-tor for test construction. | 143 // C-tor for test construction. |
| 186 ServicesCustomizationDocument(const std::string& manifest, | 144 explicit ServicesCustomizationDocument(const std::string& manifest); |
| 187 const std::string& initial_locale); | |
| 188 | 145 |
| 189 virtual ~ServicesCustomizationDocument(); | 146 virtual ~ServicesCustomizationDocument(); |
| 190 | 147 |
| 191 // Save applied state in machine settings. | 148 // Save applied state in machine settings. |
| 192 static void SetApplied(bool val); | 149 static void SetApplied(bool val); |
| 193 | 150 |
| 194 // Overriden from URLFetcher::Delegate: | 151 // Overriden from URLFetcher::Delegate: |
| 195 virtual void OnURLFetchComplete(const URLFetcher* source, | 152 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 196 const GURL& url, | 153 const GURL& url, |
| 197 const net::URLRequestStatus& status, | 154 const net::URLRequestStatus& status, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 210 | 167 |
| 211 // URLFetcher instance. | 168 // URLFetcher instance. |
| 212 scoped_ptr<URLFetcher> url_fetcher_; | 169 scoped_ptr<URLFetcher> url_fetcher_; |
| 213 | 170 |
| 214 // Timer to retry fetching file if network is not available. | 171 // Timer to retry fetching file if network is not available. |
| 215 base::OneShotTimer<ServicesCustomizationDocument> retry_timer_; | 172 base::OneShotTimer<ServicesCustomizationDocument> retry_timer_; |
| 216 | 173 |
| 217 // How many times we already tried to fetch customization manifest file. | 174 // How many times we already tried to fetch customization manifest file. |
| 218 int num_retries_; | 175 int num_retries_; |
| 219 | 176 |
| 220 // Carrier-specific deals. | |
| 221 CarrierDeals carrier_deals_; | |
| 222 | |
| 223 // Initial locale value. | |
| 224 std::string initial_locale_; | |
| 225 | |
| 226 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); | 177 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); |
| 227 }; | 178 }; |
| 228 | 179 |
| 229 } // namespace chromeos | 180 } // namespace chromeos |
| 230 | 181 |
| 231 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ | 182 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ |
| OLD | NEW |