| 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 #include "chrome/browser/chromeos/customization_document.h" | 5 #include "chrome/browser/chromeos/customization_document.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 const char kHelpPageAttr[] = "help_page"; | 37 const char kHelpPageAttr[] = "help_page"; |
| 38 const char kEulaPageAttr[] = "eula_page"; | 38 const char kEulaPageAttr[] = "eula_page"; |
| 39 const char kAppContentAttr[] = "app_content"; | 39 const char kAppContentAttr[] = "app_content"; |
| 40 const char kInitialStartPageAttr[] = "initial_start_page"; | 40 const char kInitialStartPageAttr[] = "initial_start_page"; |
| 41 const char kSupportPageAttr[] = "support_page"; | 41 const char kSupportPageAttr[] = "support_page"; |
| 42 | 42 |
| 43 const char kAcceptedManifestVersion[] = "1.0"; | 43 const char kAcceptedManifestVersion[] = "1.0"; |
| 44 | 44 |
| 45 const char kHardwareClass[] = "hardware_class"; | 45 const char kHardwareClass[] = "hardware_class"; |
| 46 | 46 |
| 47 // Carrier deals attributes. | |
| 48 const char kCarrierDealsAttr[] = "carrier_deals"; | |
| 49 const char kDealLocaleAttr[] = "deal_locale"; | |
| 50 const char kInfoURLAttr[] = "info_url"; | |
| 51 const char kTopUpURLAttr[] = "top_up_url"; | |
| 52 const char kNotificationCountAttr[] = "notification_count"; | |
| 53 const char kDealExpireDateAttr[] = "expire_date"; | |
| 54 const char kLocalizedContentAttr[] = "localized_content"; | |
| 55 const char kNotificationTextAttr[] = "notification_text"; | |
| 56 | |
| 57 // Path to OEM partner startup customization manifest. | 47 // Path to OEM partner startup customization manifest. |
| 58 const char kStartupCustomizationManifestPath[] = | 48 const char kStartupCustomizationManifestPath[] = |
| 59 "/opt/oem/etc/startup_manifest.json"; | 49 "/opt/oem/etc/startup_manifest.json"; |
| 60 | 50 |
| 61 // URL where to fetch OEM services customization manifest from. | 51 // URL where to fetch OEM services customization manifest from. |
| 62 const char kServicesCustomizationManifestUrl[] = | 52 const char kServicesCustomizationManifestUrl[] = |
| 63 "file:///opt/oem/etc/services_manifest.json"; | 53 "file:///opt/oem/etc/services_manifest.json"; |
| 64 | 54 |
| 65 // Name of local state option that tracks if services customization has been | 55 // Name of local state option that tracks if services customization has been |
| 66 // applied. | 56 // applied. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 return GetLocaleSpecificString(locale, kSetupContentAttr, kHelpPageAttr); | 209 return GetLocaleSpecificString(locale, kSetupContentAttr, kHelpPageAttr); |
| 220 } | 210 } |
| 221 | 211 |
| 222 std::string StartupCustomizationDocument::GetEULAPage( | 212 std::string StartupCustomizationDocument::GetEULAPage( |
| 223 const std::string& locale) const { | 213 const std::string& locale) const { |
| 224 return GetLocaleSpecificString(locale, kSetupContentAttr, kEulaPageAttr); | 214 return GetLocaleSpecificString(locale, kSetupContentAttr, kEulaPageAttr); |
| 225 } | 215 } |
| 226 | 216 |
| 227 // ServicesCustomizationDocument implementation. ------------------------------- | 217 // ServicesCustomizationDocument implementation. ------------------------------- |
| 228 | 218 |
| 229 ServicesCustomizationDocument::CarrierDeal::CarrierDeal( | |
| 230 DictionaryValue* deal_dict) | |
| 231 : notification_count_(0), | |
| 232 localized_strings_(NULL) { | |
| 233 deal_dict->GetString(kDealLocaleAttr, &deal_locale_); | |
| 234 deal_dict->GetString(kInfoURLAttr, &info_url_); | |
| 235 deal_dict->GetString(kTopUpURLAttr, &top_up_url_); | |
| 236 deal_dict->GetInteger(kNotificationCountAttr, ¬ification_count_); | |
| 237 std::string date_string; | |
| 238 if (deal_dict->GetString(kDealExpireDateAttr, &date_string)) { | |
| 239 if (!base::Time::FromString(date_string.c_str(), &expire_date_)) | |
| 240 LOG(ERROR) << "Error parsing deal_expire_date: " << date_string; | |
| 241 } | |
| 242 deal_dict->GetDictionary(kLocalizedContentAttr, &localized_strings_); | |
| 243 } | |
| 244 | |
| 245 ServicesCustomizationDocument::CarrierDeal::~CarrierDeal() { | |
| 246 } | |
| 247 | |
| 248 std::string ServicesCustomizationDocument::CarrierDeal::GetLocalizedString( | |
| 249 const std::string& locale, const std::string& id) const { | |
| 250 std::string result; | |
| 251 if (localized_strings_) { | |
| 252 DictionaryValue* locale_dict = NULL; | |
| 253 if (localized_strings_->GetDictionary(locale, &locale_dict) && | |
| 254 locale_dict->GetString(id, &result)) { | |
| 255 return result; | |
| 256 } else if (localized_strings_->GetDictionary(kDefaultAttr, &locale_dict) && | |
| 257 locale_dict->GetString(id, &result)) { | |
| 258 return result; | |
| 259 } | |
| 260 } | |
| 261 return result; | |
| 262 } | |
| 263 | |
| 264 ServicesCustomizationDocument::ServicesCustomizationDocument() | 219 ServicesCustomizationDocument::ServicesCustomizationDocument() |
| 265 : url_(kServicesCustomizationManifestUrl), | 220 : url_(kServicesCustomizationManifestUrl) { |
| 266 initial_locale_(WizardController::GetInitialLocale()) { | |
| 267 } | 221 } |
| 268 | 222 |
| 269 ServicesCustomizationDocument::ServicesCustomizationDocument( | 223 ServicesCustomizationDocument::ServicesCustomizationDocument( |
| 270 const std::string& manifest, const std::string& initial_locale) | 224 const std::string& manifest) { |
| 271 : initial_locale_(initial_locale) { | |
| 272 LoadManifestFromString(manifest); | 225 LoadManifestFromString(manifest); |
| 273 } | 226 } |
| 274 | 227 |
| 275 ServicesCustomizationDocument::~ServicesCustomizationDocument() {} | 228 ServicesCustomizationDocument::~ServicesCustomizationDocument() {} |
| 276 | 229 |
| 277 // static | 230 // static |
| 278 ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() { | 231 ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() { |
| 279 return Singleton<ServicesCustomizationDocument, | 232 return Singleton<ServicesCustomizationDocument, |
| 280 DefaultSingletonTraits<ServicesCustomizationDocument> >::get(); | 233 DefaultSingletonTraits<ServicesCustomizationDocument> >::get(); |
| 281 } | 234 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 return GetLocaleSpecificString( | 321 return GetLocaleSpecificString( |
| 369 locale, kAppContentAttr, kInitialStartPageAttr); | 322 locale, kAppContentAttr, kInitialStartPageAttr); |
| 370 } | 323 } |
| 371 | 324 |
| 372 std::string ServicesCustomizationDocument::GetSupportPage( | 325 std::string ServicesCustomizationDocument::GetSupportPage( |
| 373 const std::string& locale) const { | 326 const std::string& locale) const { |
| 374 return GetLocaleSpecificString( | 327 return GetLocaleSpecificString( |
| 375 locale, kAppContentAttr, kSupportPageAttr); | 328 locale, kAppContentAttr, kSupportPageAttr); |
| 376 } | 329 } |
| 377 | 330 |
| 378 const ServicesCustomizationDocument::CarrierDeal* | |
| 379 ServicesCustomizationDocument::GetCarrierDeal(const std::string& carrier_id, | |
| 380 bool check_restrictions) const { | |
| 381 CarrierDeals::const_iterator iter = carrier_deals_.find(carrier_id); | |
| 382 if (iter != carrier_deals_.end()) { | |
| 383 CarrierDeal* deal = iter->second; | |
| 384 if (check_restrictions) { | |
| 385 // Deal locale has to match initial_locale (= launch country). | |
| 386 if (initial_locale_ != deal->deal_locale()) | |
| 387 return NULL; | |
| 388 // Make sure that deal is still active, | |
| 389 // i.e. if deal expire date is defined, check it. | |
| 390 if (!deal->expire_date().is_null() && | |
| 391 deal->expire_date() <= base::Time::Now()) { | |
| 392 return NULL; | |
| 393 } | |
| 394 } | |
| 395 return deal; | |
| 396 } else { | |
| 397 return NULL; | |
| 398 } | |
| 399 } | |
| 400 | |
| 401 bool ServicesCustomizationDocument::LoadManifestFromString( | |
| 402 const std::string& manifest) { | |
| 403 if (!CustomizationDocument::LoadManifestFromString(manifest)) | |
| 404 return false; | |
| 405 | |
| 406 DictionaryValue* carriers = NULL; | |
| 407 if (root_.get() && root_->GetDictionary(kCarrierDealsAttr, &carriers)) { | |
| 408 for (DictionaryValue::key_iterator iter = carriers->begin_keys(); | |
| 409 iter != carriers->end_keys(); ++iter) { | |
| 410 DictionaryValue* carrier_deal = NULL; | |
| 411 if (carriers->GetDictionary(*iter, &carrier_deal)) { | |
| 412 carrier_deals_[*iter] = new CarrierDeal(carrier_deal); | |
| 413 } | |
| 414 } | |
| 415 } | |
| 416 return true; | |
| 417 } | |
| 418 | |
| 419 } // namespace chromeos | 331 } // namespace chromeos |
| OLD | NEW |