Infobar material design refresh: bg color
[chromium-blink-merge.git] / components / web_resource / notification_promo_mobile_ntp.cc
blobf3bcee08725b24173727a7650d84fb2dfa2fabe0
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.
5 #include "components/web_resource/notification_promo_mobile_ntp.h"
7 #include "base/values.h"
8 #include "components/web_resource/notification_promo.h"
10 namespace web_resource {
12 NotificationPromoMobileNtp::NotificationPromoMobileNtp(PrefService* local_state)
13 : valid_(false),
14 action_args_(NULL),
15 payload_(NULL),
16 notification_promo_(local_state) {}
18 NotificationPromoMobileNtp::~NotificationPromoMobileNtp() {}
20 bool NotificationPromoMobileNtp::InitFromPrefs() {
21 notification_promo_.InitFromPrefs(NotificationPromo::MOBILE_NTP_SYNC_PROMO);
22 return InitFromNotificationPromo();
25 bool NotificationPromoMobileNtp::InitFromJson(
26 const base::DictionaryValue& json) {
27 notification_promo_.InitFromJson(json,
28 NotificationPromo::MOBILE_NTP_SYNC_PROMO);
29 return InitFromNotificationPromo();
32 bool NotificationPromoMobileNtp::CanShow() const {
33 return valid() && notification_promo_.CanShow();
36 bool NotificationPromoMobileNtp::InitFromNotificationPromo() {
37 valid_ = false;
38 requires_mobile_only_sync_ = true;
39 requires_sync_ = true;
40 show_on_most_visited_ = false;
41 show_on_open_tabs_ = true;
42 show_as_virtual_computer_ = true;
43 action_args_ = NULL;
45 // These fields are mandatory and must be specified in the promo.
46 payload_ = notification_promo_.promo_payload();
47 if (!payload_ || !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_) || !action_args_) {
51 return false;
54 // The rest of the fields are optional.
55 valid_ = true;
56 payload_->GetBoolean("promo_requires_mobile_only_sync",
57 &requires_mobile_only_sync_);
58 payload_->GetBoolean("promo_requires_sync", &requires_sync_);
59 payload_->GetBoolean("promo_show_on_most_visited", &show_on_most_visited_);
60 payload_->GetBoolean("promo_show_on_open_tabs", &show_on_open_tabs_);
61 payload_->GetBoolean("promo_show_as_virtual_computer",
62 &show_as_virtual_computer_);
63 payload_->GetString("promo_virtual_computer_title", &virtual_computer_title_);
64 payload_->GetString("promo_virtual_computer_lastsync",
65 &virtual_computer_lastsync_);
67 return valid_;
70 } // namespace web_resource