Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2406)

Unified Diff: chrome/browser/notifications/sync_notifier/synced_notification_app_info.cc

Issue 193773003: Turn on and use the AppInfo data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn on app info: fix windows build Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2ae480afa8503331480d8084ca45e248480f6cad 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() {}
@@ -55,4 +68,120 @@ void SyncedNotificationAppInfo::GetAppIdList(
}
}
+// 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;
+ }
+
+ AddBitmapToFetchQueue(settings_low_dpi_icon_url_);
+ AddBitmapToFetchQueue(settings_high_dpi_icon_url_);
+ AddBitmapToFetchQueue(monochrome_low_dpi_icon_url_);
+ AddBitmapToFetchQueue(monochrome_high_dpi_icon_url_);
+ AddBitmapToFetchQueue(welcome_low_dpi_icon_url_);
+ AddBitmapToFetchQueue(welcome_high_dpi_icon_url_);
+}
+
+// If this bitmap has a valid GURL, create a fetcher for it.
+void SyncedNotificationAppInfo::AddBitmapToFetchQueue(const GURL& url) {
dewittj 2014/03/17 21:43:43 This is improperly named since there is not a queu
Pete Williamson 2014/03/21 01:22:31 Renamed to CreateBitmapFetcher everywhere.
+ // 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()) {
+ fetchers_.push_back(new chrome::BitmapFetcher(url, this));
+ DVLOG(2) << __FUNCTION__ << "Pushing bitmap " << url;
+ }
+}
+
+// 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.
+
+ // 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_));
+}
+
} // namespace notifier

Powered by Google App Engine
This is Rietveld 408576698