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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/web_resource/notification_promo_mobile_ntp.h" 6 7 #include "base/values.h" 8 #include "chrome/browser/web_resource/notification_promo.h" 9 10 NotificationPromoMobileNtp::NotificationPromoMobileNtp() 11 : valid_(false), 12 action_args_(NULL), 13 payload_(NULL) { 14 } 15 16 NotificationPromoMobileNtp::~NotificationPromoMobileNtp() { 17 } 18 19 bool NotificationPromoMobileNtp::InitFromPrefs() { 20 notification_promo_.InitFromPrefs(NotificationPromo::MOBILE_NTP_SYNC_PROMO); 21 return InitFromNotificationPromo(); 22 } 23 24 bool NotificationPromoMobileNtp::InitFromJson( 25 const base::DictionaryValue& json) { 26 notification_promo_.InitFromJson( 27 json, NotificationPromo::MOBILE_NTP_SYNC_PROMO); 28 return InitFromNotificationPromo(); 29 } 30 31 bool NotificationPromoMobileNtp::CanShow() const { 32 return valid() && notification_promo_.CanShow(); 33 } 34 35 bool NotificationPromoMobileNtp::InitFromNotificationPromo() { 36 valid_ = false; 37 requires_mobile_only_sync_ = true; 38 requires_sync_ = true; 39 show_on_most_visited_ = false; 40 show_on_open_tabs_ = true; 41 show_as_virtual_computer_ = true; 42 action_args_ = NULL; 43 44 // These fields are mandatory and must be specified in the promo. 45 payload_ = notification_promo_.promo_payload(); 46 if (!payload_ || 47 !payload_->GetString("promo_message_short", &text_) || 48 !payload_->GetString("promo_message_long", &text_long_) || 49 !payload_->GetString("promo_action_type", &action_type_) || 50 !payload_->GetList("promo_action_args", &action_args_) || 51 !action_args_) { 52 return false; 53 } 54 55 // The rest of the fields are optional. 56 valid_ = true; 57 payload_->GetBoolean("promo_requires_mobile_only_sync", 58 &requires_mobile_only_sync_); 59 payload_->GetBoolean("promo_requires_sync", &requires_sync_); 60 payload_->GetBoolean("promo_show_on_most_visited", &show_on_most_visited_); 61 payload_->GetBoolean("promo_show_on_open_tabs", &show_on_open_tabs_); 62 payload_->GetBoolean("promo_show_as_virtual_computer", 63 &show_as_virtual_computer_); 64 payload_->GetString("promo_virtual_computer_title", &virtual_computer_title_); 65 payload_->GetString("promo_virtual_computer_lastsync", 66 &virtual_computer_lastsync_); 67 68 return valid_; 69 } 70