Home | History | Annotate | Download | only in web_resource
      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 #ifndef CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_MOBILE_NTP_H_
      6 #define CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_MOBILE_NTP_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "chrome/browser/web_resource/notification_promo.h"
     12 
     13 namespace base {
     14 class DictionaryValue;
     15 class ListValue;
     16 }
     17 
     18 // Helper class for NotificationPromo that deals with mobile_ntp promos.
     19 class NotificationPromoMobileNtp {
     20  public:
     21   NotificationPromoMobileNtp();
     22   ~NotificationPromoMobileNtp();
     23 
     24   // Initialize from prefs/JSON.
     25   // Return true if the mobile NTP promotion is valid.
     26   bool InitFromPrefs();
     27   bool InitFromJson(const base::DictionaryValue& json);
     28 
     29   // Return true if the promo is valid and can be shown.
     30   bool CanShow() const;
     31 
     32   bool valid() const { return valid_; }
     33   const std::string& text() const { return text_; }
     34   const std::string& text_long() const { return text_long_; }
     35   const std::string& action_type() const { return action_type_; }
     36   const base::ListValue* action_args() const { return action_args_; }
     37   bool requires_mobile_only_sync() const { return requires_mobile_only_sync_; }
     38   bool requires_sync() const { return requires_sync_; }
     39   bool show_on_most_visited() const { return show_on_most_visited_; }
     40   bool show_on_open_tabs() const { return show_on_open_tabs_; }
     41   bool show_as_virtual_computer() const { return show_as_virtual_computer_; }
     42   const std::string& virtual_computer_title() const {
     43     return virtual_computer_title_;
     44   }
     45   const std::string& virtual_computer_lastsync() const {
     46     return virtual_computer_lastsync_;
     47   }
     48   const base::DictionaryValue* payload() const { return payload_; }
     49   const NotificationPromo& notification_promo() const {
     50     return notification_promo_;
     51   }
     52 
     53  private:
     54   // Initialize the state and validity from the low-level notification_promo_.
     55   bool InitFromNotificationPromo();
     56 
     57   // True if InitFromPrefs/JSON was called and all mandatory fields were found.
     58   bool valid_;
     59   // The short text of the promotion (e.g. for Most Visited and Open Tabs).
     60   std::string text_;
     61   // The long text of the promotion (e.g. for Open Tabs when no tabs are open).
     62   std::string text_long_;
     63   // The action that the promotion triggers (e.g. "ACTION_EMAIL").
     64   std::string action_type_;
     65   // The title of the virtual computer (e.g. when shown on Open Tabs).
     66   std::string virtual_computer_title_;
     67   // The detailed info for the virtual computer (e.g. when shown on Open Tabs).
     68   std::string virtual_computer_lastsync_;
     69   // True if the promo should be shown only if no desktop sessions were open.
     70   bool requires_mobile_only_sync_;
     71   // True if the promo should be shown only if the user is signed in to Chrome.
     72   bool requires_sync_;
     73   // True if the promo should be shown on Most Visited pane.
     74   bool show_on_most_visited_;
     75   // True if the promo should be shown on Open Tabs pane.
     76   bool show_on_open_tabs_;
     77   // True if the promo should show the virtual computer (e.g. on Open Tabs).
     78   bool show_as_virtual_computer_;
     79   // Arguments for the action (e.g. [subject, body] for "ACTION_EMAIL").
     80   const base::ListValue* action_args_;
     81   // The entire payload for the promo.
     82   const base::DictionaryValue* payload_;
     83   // The lower-level notification promo.
     84   NotificationPromo notification_promo_;
     85 
     86   DISALLOW_COPY_AND_ASSIGN(NotificationPromoMobileNtp);
     87 };
     88 
     89 #endif  // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_MOBILE_NTP_H_
     90