| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/chromeos/mobile_config.h" | 5 #include "chrome/browser/chromeos/mobile_config.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // Carrier deal attributes. | 37 // Carrier deal attributes. |
| 38 const char kDealIdAttr[] = "deal_id"; | 38 const char kDealIdAttr[] = "deal_id"; |
| 39 const char kDealLocalesAttr[] = "locales"; | 39 const char kDealLocalesAttr[] = "locales"; |
| 40 | 40 |
| 41 const char kInfoURLAttr[] = "info_url"; | 41 const char kInfoURLAttr[] = "info_url"; |
| 42 const char kNotificationCountAttr[] = "notification_count"; | 42 const char kNotificationCountAttr[] = "notification_count"; |
| 43 const char kDealExpireDateAttr[] = "expire_date"; | 43 const char kDealExpireDateAttr[] = "expire_date"; |
| 44 const char kLocalizedContentAttr[] = "localized_content"; | 44 const char kLocalizedContentAttr[] = "localized_content"; |
| 45 const char kNotificationTextAttr[] = "notification_text"; | 45 const char kNotificationTextAttr[] = "notification_text"; |
| 46 | 46 |
| 47 // Initial locale carrier config attributes. |
| 48 const char kInitialLocalesAttr[] = "initial_locales"; |
| 49 const char kSetupURLAttr[] = "setup_url"; |
| 50 |
| 47 // Local config properties. | 51 // Local config properties. |
| 48 const char kExcludeDealsAttr[] = "exclude_deals"; | 52 const char kExcludeDealsAttr[] = "exclude_deals"; |
| 49 | 53 |
| 50 // Location of the global carrier config. | 54 // Location of the global carrier config. |
| 51 const char kGlobalCarrierConfigPath[] = | 55 const char kGlobalCarrierConfigPath[] = |
| 52 "/usr/share/chromeos-assets/mobile/carrier_config.json"; | 56 "/usr/share/chromeos-assets/mobile/carrier_config.json"; |
| 53 | 57 |
| 54 // Location of the local carrier config. | 58 // Location of the local carrier config. |
| 55 const char kLocalCarrierConfigPath[] = | 59 const char kLocalCarrierConfigPath[] = |
| 56 "/opt/oem/etc/carrier_config.json"; | 60 "/opt/oem/etc/carrier_config.json"; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 189 } |
| 186 } | 190 } |
| 187 } | 191 } |
| 188 } | 192 } |
| 189 } | 193 } |
| 190 | 194 |
| 191 void MobileConfig::Carrier::RemoveDeals() { | 195 void MobileConfig::Carrier::RemoveDeals() { |
| 192 STLDeleteValues(&deals_); | 196 STLDeleteValues(&deals_); |
| 193 } | 197 } |
| 194 | 198 |
| 199 // MobileConfig::LocaleConfig implementation. ---------------------------------- |
| 200 |
| 201 MobileConfig::LocaleConfig::LocaleConfig(DictionaryValue* locale_dict) { |
| 202 InitFromDictionary(locale_dict); |
| 203 } |
| 204 |
| 205 MobileConfig::LocaleConfig::~LocaleConfig() { |
| 206 } |
| 207 |
| 208 void MobileConfig::LocaleConfig::InitFromDictionary( |
| 209 base::DictionaryValue* locale_dict) { |
| 210 locale_dict->GetString(kSetupURLAttr, &setup_url_); |
| 211 } |
| 212 |
| 195 // MobileConfig implementation, public ----------------------------------------- | 213 // MobileConfig implementation, public ----------------------------------------- |
| 196 | 214 |
| 197 // static | 215 // static |
| 198 MobileConfig* MobileConfig::GetInstance() { | 216 MobileConfig* MobileConfig::GetInstance() { |
| 199 return Singleton<MobileConfig, | 217 return Singleton<MobileConfig, |
| 200 DefaultSingletonTraits<MobileConfig> >::get(); | 218 DefaultSingletonTraits<MobileConfig> >::get(); |
| 201 } | 219 } |
| 202 | 220 |
| 203 const MobileConfig::Carrier* MobileConfig::GetCarrier( | 221 const MobileConfig::Carrier* MobileConfig::GetCarrier( |
| 204 const std::string& carrier_id) const { | 222 const std::string& carrier_id) const { |
| 205 CarrierIdMap::const_iterator id_iter = carrier_id_map_.find(carrier_id); | 223 CarrierIdMap::const_iterator id_iter = carrier_id_map_.find(carrier_id); |
| 206 std::string internal_id; | 224 std::string internal_id; |
| 207 if (id_iter != carrier_id_map_.end()) | 225 if (id_iter != carrier_id_map_.end()) |
| 208 internal_id = id_iter->second; | 226 internal_id = id_iter->second; |
| 209 else | 227 else |
| 210 return NULL; | 228 return NULL; |
| 211 Carriers::const_iterator iter = carriers_.find(internal_id); | 229 Carriers::const_iterator iter = carriers_.find(internal_id); |
| 212 if (iter != carriers_.end()) | 230 if (iter != carriers_.end()) |
| 213 return iter->second; | 231 return iter->second; |
| 214 else | 232 else |
| 215 return NULL; | 233 return NULL; |
| 216 } | 234 } |
| 217 | 235 |
| 236 const MobileConfig::LocaleConfig* MobileConfig::GetLocaleConfig() const { |
| 237 return locale_config_.get(); |
| 238 } |
| 239 |
| 218 // MobileConfig implementation, protected -------------------------------------- | 240 // MobileConfig implementation, protected -------------------------------------- |
| 219 | 241 |
| 220 bool MobileConfig::LoadManifestFromString(const std::string& manifest) { | 242 bool MobileConfig::LoadManifestFromString(const std::string& manifest) { |
| 221 if (!CustomizationDocument::LoadManifestFromString(manifest)) | 243 if (!CustomizationDocument::LoadManifestFromString(manifest)) |
| 222 return false; | 244 return false; |
| 223 | 245 |
| 224 // Local config specific attribute. | 246 // Local config specific attribute. |
| 225 bool exclude_deals = false; | 247 bool exclude_deals = false; |
| 226 if (root_.get() && | 248 if (root_.get() && |
| 227 root_->GetBoolean(kExcludeDealsAttr, &exclude_deals) && | 249 root_->GetBoolean(kExcludeDealsAttr, &exclude_deals) && |
| (...skipping 29 matching lines...) Expand all Loading... |
| 257 } else { | 279 } else { |
| 258 // Trivial case - using same ID for external/internal one. | 280 // Trivial case - using same ID for external/internal one. |
| 259 carrier_id_map_[internal_id] = internal_id; | 281 carrier_id_map_[internal_id] = internal_id; |
| 260 } | 282 } |
| 261 carriers_[internal_id] = carrier; | 283 carriers_[internal_id] = carrier; |
| 262 } | 284 } |
| 263 } | 285 } |
| 264 } | 286 } |
| 265 } | 287 } |
| 266 | 288 |
| 289 DictionaryValue* initial_locales = NULL; |
| 290 if (root_.get() && root_->GetDictionary(kInitialLocalesAttr, |
| 291 &initial_locales)) { |
| 292 DictionaryValue* locale_config_dict = NULL; |
| 293 // Search for a config based on current initial locale. |
| 294 if (initial_locales->GetDictionary(initial_locale_, |
| 295 &locale_config_dict)) { |
| 296 locale_config_.reset(new LocaleConfig(locale_config_dict)); |
| 297 } |
| 298 } |
| 299 |
| 267 return true; | 300 return true; |
| 268 } | 301 } |
| 269 | 302 |
| 270 // MobileConfig implementation, private ---------------------------------------- | 303 // MobileConfig implementation, private ---------------------------------------- |
| 271 | 304 |
| 272 MobileConfig::MobileConfig() | 305 MobileConfig::MobileConfig() |
| 273 : CustomizationDocument(kAcceptedConfigVersion), | 306 : CustomizationDocument(kAcceptedConfigVersion), |
| 274 initial_locale_(WizardController::GetInitialLocale()) { | 307 initial_locale_(WizardController::GetInitialLocale()) { |
| 275 LoadConfig(); | 308 LoadConfig(); |
| 276 } | 309 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 << local_config_file.value(); | 367 << local_config_file.value(); |
| 335 } | 368 } |
| 336 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 369 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 337 base::Bind(&MobileConfig::ProcessConfig, | 370 base::Bind(&MobileConfig::ProcessConfig, |
| 338 base::Unretained(this), // singleton. | 371 base::Unretained(this), // singleton. |
| 339 global_config, | 372 global_config, |
| 340 local_config)); | 373 local_config)); |
| 341 } | 374 } |
| 342 | 375 |
| 343 } // namespace chromeos | 376 } // namespace chromeos |
| OLD | NEW |