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.
5 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_info.h"
7 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "sync/api/sync_data.h"
10 #include "sync/protocol/synced_notification_app_info_specifics.pb.h"
12 using chrome::ImageHolder;
13 using chrome::ImageHolderDelegate;
17 SyncedNotificationAppInfo::SyncedNotificationAppInfo(
18 Profile* const profile,
19 const std::string& settings_display_name,
20 SyncedNotificationAppInfoService* synced_notification_app_info_service)
22 settings_display_name_(settings_display_name),
23 synced_notification_app_info_service_(
24 synced_notification_app_info_service) {}
26 SyncedNotificationAppInfo::~SyncedNotificationAppInfo() {}
28 GURL SyncedNotificationAppInfo::settings_icon_url() {
29 if (settings_holder_ != NULL)
30 return settings_holder_->low_dpi_url();
35 bool SyncedNotificationAppInfo::HasAppId(const std::string& app_id) {
36 std::vector<std::string>::iterator it;
38 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) {
46 void SyncedNotificationAppInfo::AddAppId(const std::string& app_id) {
50 app_ids_.push_back(app_id);
53 void SyncedNotificationAppInfo::RemoveAppId(const std::string& app_id) {
54 std::vector<std::string>::iterator it;
56 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) {
64 void SyncedNotificationAppInfo::SetWelcomeLinkUrl(
65 const GURL& welcome_link_url) {
66 welcome_link_url_ = welcome_link_url;
69 void SyncedNotificationAppInfo::SetSettingsURLs(
70 const GURL& settings_low_dpi, const GURL& settings_high_dpi) {
71 settings_holder_.reset(new ImageHolder(settings_low_dpi,
77 void SyncedNotificationAppInfo::SetMonochromeURLs(
78 const GURL& monochrome_low_dpi, const GURL& monochrome_high_dpi) {
79 monochrome_holder_.reset(new ImageHolder(monochrome_low_dpi,
85 void SyncedNotificationAppInfo::SetWelcomeURLs(
86 const GURL& welcome_low_dpi, const GURL& welcome_high_dpi) {
87 welcome_holder_.reset(new ImageHolder(welcome_low_dpi,
93 gfx::Image SyncedNotificationAppInfo::icon() {
94 if (settings_holder_ != NULL)
95 return settings_holder_->low_dpi_image();
100 std::vector<std::string> SyncedNotificationAppInfo::GetAppIdList() {
101 std::vector<std::string> app_id_list;
102 std::vector<std::string>::iterator it;
103 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) {
104 app_id_list.push_back(*it);
110 // TODO: rename, queing now happens elsewhere.
111 // Fill up the queue of bitmaps to fetch.
112 void SyncedNotificationAppInfo::QueueBitmapFetchJobs() {
113 // If there are no bitmaps to fetch, call OnBitmapFetchesDone.
114 if (AreAllBitmapsFetched()) {
115 synced_notification_app_info_service_->OnBitmapFetchesDone(
116 added_app_ids_, removed_app_ids_);
117 DVLOG(2) << "AppInfo object with no bitmaps, we should add some. "
118 << this->settings_display_name_;
123 // Start the bitmap fetching. When it is complete, the callback
124 // will notify the ChromeNotifierService of the new app info availablity.
125 void SyncedNotificationAppInfo::StartBitmapFetch() {
126 if (settings_holder_.get() != NULL)
127 settings_holder_->StartFetch();
128 if (monochrome_holder_.get() != NULL)
129 monochrome_holder_->StartFetch();
130 if (welcome_holder_.get() != NULL)
131 welcome_holder_->StartFetch();
134 // Method inherited from ImageHolderDelegate
135 void SyncedNotificationAppInfo::OnFetchComplete() {
136 if (AreAllBitmapsFetched()) {
137 if (synced_notification_app_info_service_ != NULL) {
138 synced_notification_app_info_service_->OnBitmapFetchesDone(
139 added_app_ids_, removed_app_ids_);
144 // Check to see if we have responses for all the bitmaps we got a URL for.
145 bool SyncedNotificationAppInfo::AreAllBitmapsFetched() {
147 (settings_holder_.get() == NULL || settings_holder_->IsFetchingDone()) &&
148 (monochrome_holder_.get() == NULL ||
149 monochrome_holder_->IsFetchingDone()) &&
150 (welcome_holder_.get() == NULL || welcome_holder_->IsFetchingDone());
155 message_center::NotifierId SyncedNotificationAppInfo::GetNotifierId() {
156 return message_center::NotifierId(
157 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE,
158 settings_display_name_);
161 } // namespace notifier