| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 struct PromoMapEntry { | 103 struct PromoMapEntry { |
| 104 NotificationPromo::PromoType promo_type; | 104 NotificationPromo::PromoType promo_type; |
| 105 const char* promo_type_str; | 105 const char* promo_type_str; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 const PromoMapEntry kPromoMap[] = { | 108 const PromoMapEntry kPromoMap[] = { |
| 109 { NotificationPromo::NO_PROMO, "" }, | 109 { NotificationPromo::NO_PROMO, "" }, |
| 110 { NotificationPromo::NTP_NOTIFICATION_PROMO, "ntp_notification_promo" }, | 110 { NotificationPromo::NTP_NOTIFICATION_PROMO, "ntp_notification_promo" }, |
| 111 { NotificationPromo::BUBBLE_PROMO, "bubble_promo" }, | 111 { NotificationPromo::NTP_BUBBLE_PROMO, "ntp_bubble_promo" }, |
| 112 { NotificationPromo::MOBILE_NTP_SYNC_PROMO, "mobile_ntp_sync_promo" }, | 112 { NotificationPromo::MOBILE_NTP_SYNC_PROMO, "mobile_ntp_sync_promo" }, |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 // Convert PromoType to appropriate string. | 115 // Convert PromoType to appropriate string. |
| 116 const char* PromoTypeToString(NotificationPromo::PromoType promo_type) { | 116 const char* PromoTypeToString(NotificationPromo::PromoType promo_type) { |
| 117 for (size_t i = 0; i < arraysize(kPromoMap); ++i) { | 117 for (size_t i = 0; i < arraysize(kPromoMap); ++i) { |
| 118 if (kPromoMap[i].promo_type == promo_type) | 118 if (kPromoMap[i].promo_type == promo_type) |
| 119 return kPromoMap[i].promo_type_str; | 119 return kPromoMap[i].promo_type_str; |
| 120 } | 120 } |
| 121 NOTREACHED(); | 121 NOTREACHED(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 DCHECK(profile); | 292 DCHECK(profile); |
| 293 DCHECK(prefs_); | 293 DCHECK(prefs_); |
| 294 } | 294 } |
| 295 | 295 |
| 296 NotificationPromo::~NotificationPromo() {} | 296 NotificationPromo::~NotificationPromo() {} |
| 297 | 297 |
| 298 void NotificationPromo::InitFromJson(const DictionaryValue& json, | 298 void NotificationPromo::InitFromJson(const DictionaryValue& json, |
| 299 PromoType promo_type) { | 299 PromoType promo_type) { |
| 300 promo_type_ = promo_type; | 300 promo_type_ = promo_type; |
| 301 const ListValue* promo_list = NULL; | 301 const ListValue* promo_list = NULL; |
| 302 if (!json.GetList(PromoTypeToString(promo_type_), &promo_list)) { | 302 DVLOG(1) << "InitFromJson " << PromoTypeToString(promo_type_); |
| 303 LOG(ERROR) << "Malformed JSON: not " << PromoTypeToString(promo_type_); | 303 if (!json.GetList(PromoTypeToString(promo_type_), &promo_list)) |
| 304 return; | 304 return; |
| 305 } | |
| 306 | 305 |
| 307 // No support for multiple promos yet. Only consider the first one. | 306 // No support for multiple promos yet. Only consider the first one. |
| 308 const DictionaryValue* promo = NULL; | 307 const DictionaryValue* promo = NULL; |
| 309 if (!promo_list->GetDictionary(0, &promo)) | 308 if (!promo_list->GetDictionary(0, &promo)) |
| 310 return; | 309 return; |
| 311 | 310 |
| 312 // Date. | 311 // Date. |
| 313 const ListValue* date_list = NULL; | 312 const ListValue* date_list = NULL; |
| 314 if (promo->GetList("date", &date_list)) { | 313 if (promo->GetList("date", &date_list)) { |
| 315 const DictionaryValue* date; | 314 const DictionaryValue* date; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 if (group_ < initial_segment_) | 536 if (group_ < initial_segment_) |
| 538 return start_; | 537 return start_; |
| 539 return start_ + | 538 return start_ + |
| 540 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) | 539 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) |
| 541 * time_slice_; | 540 * time_slice_; |
| 542 } | 541 } |
| 543 | 542 |
| 544 double NotificationPromo::EndTime() const { | 543 double NotificationPromo::EndTime() const { |
| 545 return end_; | 544 return end_; |
| 546 } | 545 } |
| OLD | NEW |