| 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/web_resource/notification_promo.h" | 5 #include "chrome/browser/web_resource/notification_promo.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 399 |
| 400 // static | 400 // static |
| 401 void NotificationPromo::RegisterUserPrefs(PrefService* prefs) { | 401 void NotificationPromo::RegisterUserPrefs(PrefService* prefs) { |
| 402 ClearDeprecatedPrefs(prefs); | 402 ClearDeprecatedPrefs(prefs); |
| 403 prefs->RegisterDictionaryPref(kPrefPromoObject, | 403 prefs->RegisterDictionaryPref(kPrefPromoObject, |
| 404 new base::DictionaryValue, | 404 new base::DictionaryValue, |
| 405 PrefService::UNSYNCABLE_PREF); | 405 PrefService::UNSYNCABLE_PREF); |
| 406 } | 406 } |
| 407 | 407 |
| 408 void NotificationPromo::WritePrefs() { | 408 void NotificationPromo::WritePrefs() { |
| 409 DVLOG(1) << "WritePrefs"; | |
| 410 base::DictionaryValue* ntp_promo = new base::DictionaryValue; | 409 base::DictionaryValue* ntp_promo = new base::DictionaryValue; |
| 411 ntp_promo->SetString(kPrefPromoText, promo_text_); | 410 ntp_promo->SetString(kPrefPromoText, promo_text_); |
| 412 ntp_promo->Set(kPrefPromoPayload, promo_payload_->DeepCopy()); | 411 ntp_promo->Set(kPrefPromoPayload, promo_payload_->DeepCopy()); |
| 413 ntp_promo->SetDouble(kPrefPromoStart, start_); | 412 ntp_promo->SetDouble(kPrefPromoStart, start_); |
| 414 ntp_promo->SetDouble(kPrefPromoEnd, end_); | 413 ntp_promo->SetDouble(kPrefPromoEnd, end_); |
| 415 | 414 |
| 416 ntp_promo->SetInteger(kPrefPromoNumGroups, num_groups_); | 415 ntp_promo->SetInteger(kPrefPromoNumGroups, num_groups_); |
| 417 ntp_promo->SetInteger(kPrefPromoSegment, initial_segment_); | 416 ntp_promo->SetInteger(kPrefPromoSegment, initial_segment_); |
| 418 ntp_promo->SetInteger(kPrefPromoIncrement, increment_); | 417 ntp_promo->SetInteger(kPrefPromoIncrement, increment_); |
| 419 ntp_promo->SetInteger(kPrefPromoIncrementFrequency, time_slice_); | 418 ntp_promo->SetInteger(kPrefPromoIncrementFrequency, time_slice_); |
| 420 ntp_promo->SetInteger(kPrefPromoIncrementMax, max_group_); | 419 ntp_promo->SetInteger(kPrefPromoIncrementMax, max_group_); |
| 421 | 420 |
| 422 ntp_promo->SetInteger(kPrefPromoMaxViews, max_views_); | 421 ntp_promo->SetInteger(kPrefPromoMaxViews, max_views_); |
| 423 | 422 |
| 424 ntp_promo->SetInteger(kPrefPromoGroup, group_); | 423 ntp_promo->SetInteger(kPrefPromoGroup, group_); |
| 425 ntp_promo->SetInteger(kPrefPromoViews, views_); | 424 ntp_promo->SetInteger(kPrefPromoViews, views_); |
| 426 ntp_promo->SetBoolean(kPrefPromoClosed, closed_); | 425 ntp_promo->SetBoolean(kPrefPromoClosed, closed_); |
| 427 | 426 |
| 428 ntp_promo->SetBoolean(kPrefPromoGPlusRequired, gplus_required_); | 427 ntp_promo->SetBoolean(kPrefPromoGPlusRequired, gplus_required_); |
| 429 | 428 |
| 430 base::ListValue* promo_list = new base::ListValue; | 429 base::ListValue* promo_list = new base::ListValue; |
| 431 promo_list->Set(0, ntp_promo); // Only support 1 promo for now. | 430 promo_list->Set(0, ntp_promo); // Only support 1 promo for now. |
| 432 | 431 |
| 433 base::DictionaryValue promo_dict; | 432 base::DictionaryValue promo_dict; |
| 433 promo_dict.MergeDictionary(prefs_->GetDictionary(kPrefPromoObject)); |
| 434 promo_dict.Set(PromoTypeToString(promo_type_), promo_list); | 434 promo_dict.Set(PromoTypeToString(promo_type_), promo_list); |
| 435 prefs_->Set(kPrefPromoObject, promo_dict); | 435 prefs_->Set(kPrefPromoObject, promo_dict); |
| 436 DVLOG(1) << "WritePrefs " << promo_dict; |
| 436 } | 437 } |
| 437 | 438 |
| 438 void NotificationPromo::InitFromPrefs(PromoType promo_type) { | 439 void NotificationPromo::InitFromPrefs(PromoType promo_type) { |
| 439 promo_type_ = promo_type; | 440 promo_type_ = promo_type; |
| 440 const base::DictionaryValue* promo_dict = | 441 const base::DictionaryValue* promo_dict = |
| 441 prefs_->GetDictionary(kPrefPromoObject); | 442 prefs_->GetDictionary(kPrefPromoObject); |
| 442 if (!promo_dict) | 443 if (!promo_dict) |
| 443 return; | 444 return; |
| 444 | 445 |
| 445 const base::ListValue* promo_list = NULL; | 446 const base::ListValue* promo_list = NULL; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 if (group_ < initial_segment_) | 537 if (group_ < initial_segment_) |
| 537 return start_; | 538 return start_; |
| 538 return start_ + | 539 return start_ + |
| 539 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) | 540 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) |
| 540 * time_slice_; | 541 * time_slice_; |
| 541 } | 542 } |
| 542 | 543 |
| 543 double NotificationPromo::EndTime() const { | 544 double NotificationPromo::EndTime() const { |
| 544 return end_; | 545 return end_; |
| 545 } | 546 } |
| OLD | NEW |