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