Index: chrome/browser/notifications/sync_notifier/synced_notification_app_info.cc |
diff --git a/chrome/browser/notifications/sync_notifier/synced_notification_app_info.cc b/chrome/browser/notifications/sync_notifier/synced_notification_app_info.cc |
index 1accb2642ffbc0c95fbf054d296f040d89e6d960..c2ebbd04d7bd44ee725582148876971558639265 100644 |
--- a/chrome/browser/notifications/sync_notifier/synced_notification_app_info.cc |
+++ b/chrome/browser/notifications/sync_notifier/synced_notification_app_info.cc |
@@ -4,14 +4,27 @@ |
#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info.h" |
+#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.h" |
+#include "chrome/browser/profiles/profile.h" |
#include "sync/api/sync_data.h" |
#include "sync/protocol/synced_notification_app_info_specifics.pb.h" |
namespace notifier { |
SyncedNotificationAppInfo::SyncedNotificationAppInfo( |
- const std::string& settings_display_name) |
- : settings_display_name_(settings_display_name) {} |
+ Profile* const profile, |
+ const std::string& settings_display_name, |
+ SyncedNotificationAppInfoService* synced_notification_app_info_service) |
+ : profile_(profile), |
+ settings_display_name_(settings_display_name), |
+ settings_low_dpi_icon_fetched_(false), |
+ settings_high_dpi_icon_fetched_(false), |
+ monochrome_low_dpi_icon_fetched_(false), |
+ monochrome_high_dpi_icon_fetched_(false), |
+ welcome_low_dpi_icon_fetched_(false), |
+ welcome_high_dpi_icon_fetched_(false), |
+ synced_notification_app_info_service_( |
+ synced_notification_app_info_service) {} |
SyncedNotificationAppInfo::~SyncedNotificationAppInfo() {} |
@@ -44,15 +57,136 @@ void SyncedNotificationAppInfo::RemoveAppId(const std::string& app_id) { |
} |
} |
-void SyncedNotificationAppInfo::GetAppIdList( |
- std::vector<std::string>* app_id_list) { |
- if (app_id_list == NULL) |
- return; |
- |
+std::vector<std::string> SyncedNotificationAppInfo::GetAppIdList() { |
+ std::vector<std::string> app_id_list; |
std::vector<std::string>::iterator it; |
for (it = app_ids_.begin(); it != app_ids_.end(); ++it) { |
- app_id_list->push_back(*it); |
+ app_id_list.push_back(*it); |
+ } |
+ |
+ return app_id_list; |
+} |
+ |
+// Fill up the queue of bitmaps to fetch. |
+void SyncedNotificationAppInfo::QueueBitmapFetchJobs() { |
+ // If there are no bitmaps to fetch, call OnBitmapFetchesDone. |
+ if (settings_low_dpi_icon_url_.is_empty() && |
+ settings_high_dpi_icon_url_.is_empty() && |
+ monochrome_low_dpi_icon_url_.is_empty() && |
+ monochrome_high_dpi_icon_url_.is_empty() && |
+ welcome_low_dpi_icon_url_.is_empty() && |
+ welcome_high_dpi_icon_url_.is_empty()) { |
+ if (synced_notification_app_info_service_ != NULL) { |
+ synced_notification_app_info_service_->OnBitmapFetchesDone( |
+ added_app_ids_, removed_app_ids_); |
+ } |
+ DVLOG(2) << "AppInfo object with no bitmaps, we should add some. " |
+ << this->settings_display_name_; |
+ return; |
+ } |
+ |
+ CreateBitmapFetcher(settings_low_dpi_icon_url_); |
+ CreateBitmapFetcher(settings_high_dpi_icon_url_); |
+ CreateBitmapFetcher(monochrome_low_dpi_icon_url_); |
+ CreateBitmapFetcher(monochrome_high_dpi_icon_url_); |
+ CreateBitmapFetcher(welcome_low_dpi_icon_url_); |
+ CreateBitmapFetcher(welcome_high_dpi_icon_url_); |
+} |
+ |
+// If this bitmap has a valid GURL, create a fetcher for it. |
+void SyncedNotificationAppInfo::CreateBitmapFetcher(const GURL& url) { |
+ // Check for dups, ignore any request for a dup. |
+ ScopedVector<chrome::BitmapFetcher>::iterator iter; |
+ for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) { |
+ if ((*iter)->url() == url) |
+ return; |
+ } |
+ |
+ if (url.is_valid()) { |
dewittj
2014/03/20 18:00:28
hm, possibly push this check above the loop to avo
Pete Williamson
2014/03/25 00:08:37
Instead, I pushed up the check into the calling fu
|
+ fetchers_.push_back(new chrome::BitmapFetcher(url, this)); |
+ DVLOG(2) << __FUNCTION__ << "Pushing bitmap " << url; |
} |
dewittj
2014/03/20 18:00:28
Should there be some sort of handler for bad URL?
Pete Williamson
2014/03/25 00:08:37
Fixed by pushing up the check into the caller.
Pete Williamson
2014/03/25 00:08:37
handler added in ImageHandler::ImageHandler()
|
} |
+// Start the bitmap fetching. When it is complete, the callback |
+// will notify the ChromeNotifierService of the new app info availablity. |
+void SyncedNotificationAppInfo::StartBitmapFetch() { |
+ // Now that we have queued them all, start the fetching. |
+ ScopedVector<chrome::BitmapFetcher>::iterator iter; |
+ for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) { |
+ (*iter)->Start(profile_); |
+ } |
+} |
+ |
+// Method inherited from BitmapFetcher delegate. |
+void SyncedNotificationAppInfo::OnFetchComplete(const GURL url, |
+ const SkBitmap* bitmap) { |
+ // TODO(petewil): Should I retry if a fetch fails? |
+ |
+ // TODO(petewil): |
+ // Use the ImageSkia functions instead and use 2.0 as scale for the hi dpi |
+ // versions, then combine into one gfx::Image, which I pass to the |
+ // Notification Center. |
dewittj
2014/03/20 18:00:28
Let's actually do that here. CreateFrom1xBitmap i
Pete Williamson
2014/03/25 00:08:37
Done.
|
+ |
+ // Match the bitmap to the URL to put it into the right variable. |
+ if (url == settings_low_dpi_icon_url_) { |
+ settings_low_dpi_icon_fetched_ = true; |
+ if (bitmap != NULL) |
+ settings_low_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); |
+ } else if (url == settings_high_dpi_icon_url_) { |
+ settings_high_dpi_icon_fetched_ = true; |
+ if (bitmap != NULL) |
+ settings_high_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); |
+ } else if (url == monochrome_low_dpi_icon_url_) { |
+ monochrome_low_dpi_icon_fetched_ = true; |
+ if (bitmap != NULL) |
+ monochrome_low_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); |
+ } else if (url == monochrome_high_dpi_icon_url_) { |
+ monochrome_high_dpi_icon_fetched_ = true; |
+ if (bitmap != NULL) |
+ monochrome_high_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); |
+ } else if (url == welcome_low_dpi_icon_url_) { |
+ welcome_low_dpi_icon_fetched_ = true; |
+ if (bitmap != NULL) |
+ welcome_low_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); |
+ } else if (url == welcome_high_dpi_icon_url_) { |
+ welcome_high_dpi_icon_fetched_ = true; |
+ if (bitmap != NULL) |
+ welcome_high_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); |
+ } else { |
+ DVLOG(2) << __FUNCTION__ << "Unmatched bitmap arrived " << url; |
+ } |
+ |
+ // If all bitmaps are accounted for, time to notify the ChromeNotifierService, |
+ // via the SyncedNotificationAppInfoService. |
+ if (AreAllBitmapsFetched()) { |
+ if (synced_notification_app_info_service_ != NULL) { |
+ synced_notification_app_info_service_->OnBitmapFetchesDone( |
+ added_app_ids_, removed_app_ids_); |
+ } |
+ } |
+} |
+ |
+// Check to see if we have responses for all the bitmaps we got a URL for. |
+bool SyncedNotificationAppInfo::AreAllBitmapsFetched() { |
+ return ((settings_low_dpi_icon_url_.is_empty() || |
+ settings_low_dpi_icon_fetched_) && |
+ (settings_high_dpi_icon_url_.is_empty() || |
+ settings_high_dpi_icon_fetched_) && |
+ (monochrome_low_dpi_icon_url_.is_empty() || |
+ monochrome_low_dpi_icon_fetched_) && |
+ (monochrome_high_dpi_icon_url_.is_empty() || |
+ monochrome_high_dpi_icon_fetched_) && |
+ (welcome_low_dpi_icon_url_.is_empty() || |
+ welcome_low_dpi_icon_fetched_) && |
+ (welcome_high_dpi_icon_url_.is_empty() || |
+ welcome_high_dpi_icon_fetched_)); |
+} |
+ |
+message_center::NotifierId SyncedNotificationAppInfo::GetNotifierId() { |
+ return message_center::NotifierId( |
+ message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, |
+ settings_display_name_); |
+} |
+ |
} // namespace notifier |