1 // Copyright 2014 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 // This class represents the metadata for a service sending synced 6 // notifications. 7 8 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_INFO_H_ 9 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_INFO_H_ 10 11 #include <string> 12 #include <vector> 13 14 #include "base/memory/scoped_vector.h" 15 #include "chrome/browser/image_holder.h" 16 #include "ui/gfx/image/image.h" 17 #include "ui/message_center/notifier_settings.h" 18 #include "url/gurl.h" 19 20 class Profile; 21 22 namespace notifier { 23 24 class SyncedNotificationAppInfoService; 25 26 class SyncedNotificationAppInfo : public chrome::ImageHolderDelegate { 27 public: 28 SyncedNotificationAppInfo( 29 Profile* const profile, 30 const std::string& settings_display_name, 31 SyncedNotificationAppInfoService* synced_notification_app_info_service); 32 virtual ~SyncedNotificationAppInfo(); 33 34 // Return true if the app id is present in this AppInfo protobuf. 35 bool HasAppId(const std::string& app_id); 36 37 // Add an app id to the supported set for this AppInfo protobuf. 38 void AddAppId(const std::string& app_id); 39 40 // Remove an app id from the set for this AppInfo protobuf. 41 void RemoveAppId(const std::string& app_id); 42 settings_display_name()43 std::string settings_display_name() const { return settings_display_name_; } 44 45 // Sets/gets the link to navigate to when the user clicks on the body of the 46 // app's welcome notification. 47 void SetWelcomeLinkUrl(const GURL& settings_link_url); welcome_link_url()48 GURL welcome_link_url() const { return welcome_link_url_; } 49 50 // Set the URL for the low and high DPI bitmaps for the settings dialog. 51 void SetSettingsURLs(const GURL& settings_low_dpi, 52 const GURL& settings_high_dpi); 53 54 // Set the URL for the low and high DPI bitmaps for indicating the sending 55 // service. 56 void SetMonochromeURLs(const GURL& monochrome_low_dpi, 57 const GURL& monochrome_high_dpi); 58 59 // Set the URL for the low and high DPI bitmaps for use by the welcome dialog. 60 void SetWelcomeURLs(const GURL& welcome_low_dpi, 61 const GURL& welcome_high_dpi); 62 63 GURL settings_icon_url(); 64 65 // If an app info is updated, keep track of the newly added app ids so we can 66 // later inform the chrome_notifier_service to show any newly enabled 67 // notifications. set_added_app_ids(std::vector<std::string> added_app_ids)68 void set_added_app_ids(std::vector<std::string> added_app_ids) { 69 added_app_ids_ = added_app_ids; 70 } 71 added_app_ids()72 std::vector<std::string> added_app_ids() { return added_app_ids_; } 73 74 // If an app info is updated removing app ids, keep track of the removed app 75 // ids so we can later remove any affected notifications. set_removed_app_ids(std::vector<std::string> removed_app_ids)76 void set_removed_app_ids(std::vector<std::string> removed_app_ids) { 77 removed_app_ids_ = removed_app_ids; 78 } 79 removed_app_ids()80 std::vector<std::string> removed_app_ids() { return removed_app_ids_; } 81 82 // TODO(petewil): Check resolution of system and return the right icon. 83 gfx::Image icon(); 84 85 // Build a vector of app_ids that this app_info contains. 86 std::vector<std::string> GetAppIdList(); 87 88 // Set up for fetching all the bitmaps in this AppInfo. 89 void QueueBitmapFetchJobs(); 90 91 // Start the bitmap fetching. When it is complete, the callback 92 // will notify the ChromeNotifierService of the new app info availablity. 93 void StartBitmapFetch(); 94 95 // Method inherited from ImageHolderDelegate 96 virtual void OnFetchComplete() OVERRIDE; 97 98 // Check to see if we have responses for all the bitmaps we need. 99 bool AreAllBitmapsFetched(); 100 101 // Construct a Message Center NotifierId from this synced notification app 102 // info object. 103 message_center::NotifierId GetNotifierId(); 104 105 private: 106 // TODO(petewil): We need a unique id for a key. We will use the settings 107 // display name, but it would be more robust with a unique id. 108 Profile* profile_; 109 std::vector<std::string> app_ids_; 110 std::string settings_display_name_; 111 GURL welcome_link_url_; 112 113 // The 1x and 2x versions of the icon for settings, small. 114 scoped_ptr<chrome::ImageHolder> settings_holder_; 115 // Monochrome icons for app badging (1x and 2x), small. 116 scoped_ptr<chrome::ImageHolder> monochrome_holder_; 117 // Welcome dialog icon (1x and 2x), large. 118 scoped_ptr<chrome::ImageHolder> welcome_holder_; 119 // A landing page link for settings/welcome toast. 120 GURL welcome_landing_page_url_; 121 std::vector<std::string> added_app_ids_; 122 std::vector<std::string> removed_app_ids_; 123 SyncedNotificationAppInfoService* synced_notification_app_info_service_; 124 125 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoTest, AddRemoveTest); 126 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoTest, GetAppIdListTest); 127 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoTest, 128 CreateBitmapFetcherTest); 129 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoTest, OnFetchCompleteTest); 130 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoTest, 131 QueueBitmapFetchJobsTest); 132 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoTest, 133 AreAllBitmapsFetchedTest); 134 135 DISALLOW_COPY_AND_ASSIGN(SyncedNotificationAppInfo); 136 }; 137 138 } // namespace notifier 139 140 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_INFO_H_ 141