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/web_resource/promo_resource_service.h" | 5 #include "chrome/browser/web_resource/promo_resource_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 void PromoResourceService::UnpackWebStoreSignal( | 312 void PromoResourceService::UnpackWebStoreSignal( |
313 const DictionaryValue& parsed_json) { | 313 const DictionaryValue& parsed_json) { |
314 DictionaryValue* topic_dict; | 314 DictionaryValue* topic_dict; |
315 ListValue* answer_list; | 315 ListValue* answer_list; |
316 | 316 |
317 bool is_webstore_active = false; | 317 bool is_webstore_active = false; |
318 bool signal_found = false; | 318 bool signal_found = false; |
319 std::string promo_id = ""; | 319 AppsPromo::PromoData promo_data; |
320 std::string promo_header = ""; | |
321 std::string promo_button = ""; | |
322 std::string promo_link = ""; | 320 std::string promo_link = ""; |
323 std::string promo_expire = ""; | |
324 std::string promo_logo = ""; | 321 std::string promo_logo = ""; |
325 int maximize_setting = 0; | |
326 int target_builds = 0; | 322 int target_builds = 0; |
327 | 323 |
328 if (!parsed_json.GetDictionary("topic", &topic_dict) || | 324 if (!parsed_json.GetDictionary("topic", &topic_dict) || |
329 !topic_dict->GetList("answers", &answer_list)) | 325 !topic_dict->GetList("answers", &answer_list)) |
330 return; | 326 return; |
331 | 327 |
332 for (ListValue::const_iterator answer_iter = answer_list->begin(); | 328 for (ListValue::const_iterator answer_iter = answer_list->begin(); |
333 answer_iter != answer_list->end(); ++answer_iter) { | 329 answer_iter != answer_list->end(); ++answer_iter) { |
334 if (!(*answer_iter)->IsType(Value::TYPE_DICTIONARY)) | 330 if (!(*answer_iter)->IsType(Value::TYPE_DICTIONARY)) |
335 continue; | 331 continue; |
(...skipping 19 matching lines...) Expand all Loading... |
355 name = name.substr(split+1); | 351 name = name.substr(split+1); |
356 split = name.find(':'); | 352 split = name.find(':'); |
357 if (split == std::string::npos || | 353 if (split == std::string::npos || |
358 !base::StringToInt(name.substr(0, split), &target_builds)) | 354 !base::StringToInt(name.substr(0, split), &target_builds)) |
359 continue; | 355 continue; |
360 | 356 |
361 // (3) an integer specifying what users should maximize the promo | 357 // (3) an integer specifying what users should maximize the promo |
362 name = name.substr(split+1); | 358 name = name.substr(split+1); |
363 split = name.find(':'); | 359 split = name.find(':'); |
364 if (split == std::string::npos || | 360 if (split == std::string::npos || |
365 !base::StringToInt(name.substr(0, split), &maximize_setting)) | 361 !base::StringToInt(name.substr(0, split), &promo_data.user_group)) |
366 continue; | 362 continue; |
367 | 363 |
368 // (4) optional text that specifies a URL of a logo image | 364 // (4) optional text that specifies a URL of a logo image |
369 promo_logo = name.substr(split+1); | 365 promo_logo = name.substr(split+1); |
370 | 366 |
371 if (!a_dic->GetString(kAnswerIdProperty, &promo_id) || | 367 if (!a_dic->GetString(kAnswerIdProperty, &promo_data.id) || |
372 !a_dic->GetString(kWebStoreHeaderProperty, &promo_header) || | 368 !a_dic->GetString(kWebStoreHeaderProperty, &promo_data.header) || |
373 !a_dic->GetString(kWebStoreButtonProperty, &promo_button) || | 369 !a_dic->GetString(kWebStoreButtonProperty, &promo_data.button) || |
374 !a_dic->GetString(kWebStoreLinkProperty, &promo_link) || | 370 !a_dic->GetString(kWebStoreLinkProperty, &promo_link) || |
375 !a_dic->GetString(kWebStoreExpireProperty, &promo_expire)) | 371 !a_dic->GetString(kWebStoreExpireProperty, &promo_data.expire)) |
376 continue; | 372 continue; |
377 | 373 |
378 if (IsThisBuildTargeted(target_builds)) { | 374 if (IsThisBuildTargeted(target_builds)) { |
379 // Store the first web store promo that targets the current build. | 375 // The downloader will set the promo prefs and send the |
380 AppsPromo::SetPromo(promo_id, promo_header, promo_button, | 376 // NOTIFICATION_WEB_STORE_PROMO_LOADED notification. |
381 GURL(promo_link), promo_expire, GURL(promo_logo), | 377 promo_data.link = GURL(promo_link); |
382 maximize_setting); | 378 promo_data.logo = GURL(promo_logo); |
| 379 apps_promo_logo_fetcher_.reset( |
| 380 new AppsPromoLogoFetcher(profile_, promo_data)); |
383 signal_found = true; | 381 signal_found = true; |
384 break; | 382 break; |
385 } | 383 } |
386 } | 384 } |
387 | 385 |
388 if (!signal_found) { | 386 if (!signal_found) { |
389 // If no web store promos target this build, then clear all the prefs. | 387 // If no web store promos target this build, then clear all the prefs. |
390 AppsPromo::ClearPromo(); | 388 AppsPromo::ClearPromo(); |
391 } | 389 } |
392 | 390 |
393 AppsPromo::SetWebStoreSupportedForLocale(is_webstore_active); | 391 AppsPromo::SetWebStoreSupportedForLocale(is_webstore_active); |
394 | 392 |
395 NotificationService::current()->Notify( | |
396 chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, | |
397 Source<Profile>(profile_), | |
398 NotificationService::NoDetails()); | |
399 | |
400 return; | 393 return; |
401 } | 394 } |
402 | 395 |
403 void PromoResourceService::UnpackLogoSignal( | 396 void PromoResourceService::UnpackLogoSignal( |
404 const DictionaryValue& parsed_json) { | 397 const DictionaryValue& parsed_json) { |
405 DictionaryValue* topic_dict; | 398 DictionaryValue* topic_dict; |
406 ListValue* answer_list; | 399 ListValue* answer_list; |
407 double old_logo_start = 0; | 400 double old_logo_start = 0; |
408 double old_logo_end = 0; | 401 double old_logo_end = 0; |
409 double logo_start = 0; | 402 double logo_start = 0; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 base::ThreadRestrictions::ScopedAllowIO allow_io; | 479 base::ThreadRestrictions::ScopedAllowIO allow_io; |
487 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 480 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
488 is_promo_build = PromoResourceService::IsBuildTargeted( | 481 is_promo_build = PromoResourceService::IsBuildTargeted( |
489 channel, prefs->GetInteger(prefs::kNTPPromoBuild)); | 482 channel, prefs->GetInteger(prefs::kNTPPromoBuild)); |
490 } | 483 } |
491 | 484 |
492 return !promo_closed && !is_synced && is_promo_build; | 485 return !promo_closed && !is_synced && is_promo_build; |
493 } | 486 } |
494 | 487 |
495 } // namespace PromoResourceServiceUtil | 488 } // namespace PromoResourceServiceUtil |
OLD | NEW |