Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: chrome/browser/chromeos/customization_document.cc

Issue 7778043: [cros] Support global carrier config. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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.
67 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied"; 57 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied";
68 58
69 // Maximum number of retries to fetch file if network is not available. 59 // Maximum number of retries to fetch file if network is not available.
70 const int kMaxFetchRetries = 3; 60 const int kMaxFetchRetries = 3;
71 61
72 // Delay between file fetch retries if network is not available. 62 // Delay between file fetch retries if network is not available.
73 const int kRetriesDelayInSec = 2; 63 const int kRetriesDelayInSec = 2;
74 64
75 } // anonymous namespace 65 } // anonymous namespace
76 66
77 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ServicesCustomizationDocument); 67 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ServicesCustomizationDocument);
78 68
79 namespace chromeos { 69 namespace chromeos {
80 70
81 // CustomizationDocument implementation. --------------------------------------- 71 // CustomizationDocument implementation. ---------------------------------------
82 72
83 CustomizationDocument::CustomizationDocument() {} 73 CustomizationDocument::CustomizationDocument(
74 const std::string& accepted_version)
75 : accepted_version_(accepted_version) {}
84 76
85 CustomizationDocument::~CustomizationDocument() {} 77 CustomizationDocument::~CustomizationDocument() {}
86 78
87 bool CustomizationDocument::LoadManifestFromFile( 79 bool CustomizationDocument::LoadManifestFromFile(
88 const FilePath& manifest_path) { 80 const FilePath& manifest_path) {
89 std::string manifest; 81 std::string manifest;
90 if (!file_util::ReadFileToString(manifest_path, &manifest)) 82 if (!file_util::ReadFileToString(manifest_path, &manifest))
91 return false; 83 return false;
92 return LoadManifestFromString(manifest); 84 return LoadManifestFromString(manifest);
93 } 85 }
94 86
95 bool CustomizationDocument::LoadManifestFromString( 87 bool CustomizationDocument::LoadManifestFromString(
96 const std::string& manifest) { 88 const std::string& manifest) {
97 scoped_ptr<Value> root(base::JSONReader::Read(manifest, true)); 89 int error_code = 0;
90 std::string error;
91 scoped_ptr<Value> root(base::JSONReader::ReadAndReturnError(manifest,
92 true,
93 &error_code,
94 &error));
95 if (error_code != base::JSONReader::JSON_NO_ERROR)
96 LOG(ERROR) << error;
98 DCHECK(root.get() != NULL); 97 DCHECK(root.get() != NULL);
99 if (root.get() == NULL) 98 if (root.get() == NULL)
100 return false; 99 return false;
101 DCHECK(root->GetType() == Value::TYPE_DICTIONARY); 100 DCHECK(root->GetType() == Value::TYPE_DICTIONARY);
102 if (root->GetType() == Value::TYPE_DICTIONARY) { 101 if (root->GetType() == Value::TYPE_DICTIONARY) {
103 root_.reset(static_cast<DictionaryValue*>(root.release())); 102 root_.reset(static_cast<DictionaryValue*>(root.release()));
104 std::string result; 103 std::string result;
105 if (root_->GetString(kVersionAttr, &result) && 104 if (root_->GetString(kVersionAttr, &result) &&
106 result == kAcceptedManifestVersion) 105 result == accepted_version_)
107 return true; 106 return true;
108 107
109 LOG(ERROR) << "Wrong customization manifest version"; 108 LOG(ERROR) << "Wrong customization manifest version";
110 root_.reset(NULL); 109 root_.reset(NULL);
111 } 110 }
112 return false; 111 return false;
113 } 112 }
114 113
115 std::string CustomizationDocument::GetLocaleSpecificString( 114 std::string CustomizationDocument::GetLocaleSpecificString(
116 const std::string& locale, 115 const std::string& locale,
(...skipping 16 matching lines...) Expand all
133 std::string result; 132 std::string result;
134 if (default_dictionary->GetString(entry_name, &result)) 133 if (default_dictionary->GetString(entry_name, &result))
135 return result; 134 return result;
136 } 135 }
137 136
138 return std::string(); 137 return std::string();
139 } 138 }
140 139
141 // StartupCustomizationDocument implementation. -------------------------------- 140 // StartupCustomizationDocument implementation. --------------------------------
142 141
143 StartupCustomizationDocument::StartupCustomizationDocument() { 142 StartupCustomizationDocument::StartupCustomizationDocument()
143 : CustomizationDocument(kAcceptedManifestVersion) {
144 { 144 {
145 // Loading manifest causes us to do blocking IO on UI thread. 145 // Loading manifest causes us to do blocking IO on UI thread.
146 // Temporarily allow it until we fix http://crosbug.com/11103 146 // Temporarily allow it until we fix http://crosbug.com/11103
147 base::ThreadRestrictions::ScopedAllowIO allow_io; 147 base::ThreadRestrictions::ScopedAllowIO allow_io;
148 LoadManifestFromFile(FilePath(kStartupCustomizationManifestPath)); 148 LoadManifestFromFile(FilePath(kStartupCustomizationManifestPath));
149 } 149 }
150 Init(chromeos::system::StatisticsProvider::GetInstance()); 150 Init(chromeos::system::StatisticsProvider::GetInstance());
151 } 151 }
152 152
153 StartupCustomizationDocument::StartupCustomizationDocument( 153 StartupCustomizationDocument::StartupCustomizationDocument(
154 chromeos::system::StatisticsProvider* statistics_provider, 154 chromeos::system::StatisticsProvider* statistics_provider,
155 const std::string& manifest) { 155 const std::string& manifest)
156 : CustomizationDocument(kAcceptedManifestVersion) {
156 LoadManifestFromString(manifest); 157 LoadManifestFromString(manifest);
157 Init(statistics_provider); 158 Init(statistics_provider);
158 } 159 }
159 160
160 StartupCustomizationDocument::~StartupCustomizationDocument() {} 161 StartupCustomizationDocument::~StartupCustomizationDocument() {}
161 162
162 StartupCustomizationDocument* StartupCustomizationDocument::GetInstance() { 163 StartupCustomizationDocument* StartupCustomizationDocument::GetInstance() {
163 return Singleton<StartupCustomizationDocument, 164 return Singleton<StartupCustomizationDocument,
164 DefaultSingletonTraits<StartupCustomizationDocument> >::get(); 165 DefaultSingletonTraits<StartupCustomizationDocument> >::get();
165 } 166 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return GetLocaleSpecificString(locale, kSetupContentAttr, kHelpPageAttr); 220 return GetLocaleSpecificString(locale, kSetupContentAttr, kHelpPageAttr);
220 } 221 }
221 222
222 std::string StartupCustomizationDocument::GetEULAPage( 223 std::string StartupCustomizationDocument::GetEULAPage(
223 const std::string& locale) const { 224 const std::string& locale) const {
224 return GetLocaleSpecificString(locale, kSetupContentAttr, kEulaPageAttr); 225 return GetLocaleSpecificString(locale, kSetupContentAttr, kEulaPageAttr);
225 } 226 }
226 227
227 // ServicesCustomizationDocument implementation. ------------------------------- 228 // ServicesCustomizationDocument implementation. -------------------------------
228 229
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, &notification_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() 230 ServicesCustomizationDocument::ServicesCustomizationDocument()
265 : url_(kServicesCustomizationManifestUrl), 231 : CustomizationDocument(kAcceptedManifestVersion),
266 initial_locale_(WizardController::GetInitialLocale()) { 232 url_(kServicesCustomizationManifestUrl) {
267 } 233 }
268 234
269 ServicesCustomizationDocument::ServicesCustomizationDocument( 235 ServicesCustomizationDocument::ServicesCustomizationDocument(
270 const std::string& manifest, const std::string& initial_locale) 236 const std::string& manifest)
271 : initial_locale_(initial_locale) { 237 : CustomizationDocument(kAcceptedManifestVersion) {
272 LoadManifestFromString(manifest); 238 LoadManifestFromString(manifest);
273 } 239 }
274 240
275 ServicesCustomizationDocument::~ServicesCustomizationDocument() {} 241 ServicesCustomizationDocument::~ServicesCustomizationDocument() {}
276 242
277 // static 243 // static
278 ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() { 244 ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() {
279 return Singleton<ServicesCustomizationDocument, 245 return Singleton<ServicesCustomizationDocument,
280 DefaultSingletonTraits<ServicesCustomizationDocument> >::get(); 246 DefaultSingletonTraits<ServicesCustomizationDocument> >::get();
281 } 247 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 return GetLocaleSpecificString( 334 return GetLocaleSpecificString(
369 locale, kAppContentAttr, kInitialStartPageAttr); 335 locale, kAppContentAttr, kInitialStartPageAttr);
370 } 336 }
371 337
372 std::string ServicesCustomizationDocument::GetSupportPage( 338 std::string ServicesCustomizationDocument::GetSupportPage(
373 const std::string& locale) const { 339 const std::string& locale) const {
374 return GetLocaleSpecificString( 340 return GetLocaleSpecificString(
375 locale, kAppContentAttr, kSupportPageAttr); 341 locale, kAppContentAttr, kSupportPageAttr);
376 } 342 }
377 343
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 344 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/customization_document.h ('k') | chrome/browser/chromeos/customization_document_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698