Index: chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.cc |
diff --git a/chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.cc b/chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.cc |
index 62995066503f662c69ba954cbb262063eb20f27f..6db3d31f3677f5feaf0cae2f299338d10ea8a351 100644 |
--- a/chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.cc |
+++ b/chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.cc |
@@ -8,6 +8,8 @@ |
#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
+#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_factory.h" |
#include "chrome/browser/profiles/profile.h" |
#include "sync/api/sync_change.h" |
#include "sync/api/sync_change_processor.h" |
@@ -18,9 +20,20 @@ |
namespace notifier { |
+SyncedNotificationSendingServiceSettingsData:: |
+ SyncedNotificationSendingServiceSettingsData( |
+ std::string settings_display_name_param, |
+ gfx::Image settings_icon_param, |
+ message_center::NotifierId notifier_id_param) |
+ : settings_display_name(settings_display_name_param), |
+ settings_icon(settings_icon_param), |
+ notifier_id(notifier_id_param) {} |
+ |
+bool SyncedNotificationAppInfoService::avoid_bitmap_fetching_for_test_ = false; |
+ |
SyncedNotificationAppInfoService::SyncedNotificationAppInfoService( |
Profile* profile) |
- : profile_(profile) {} |
+ : profile_(profile), chrome_notifier_service_(NULL) {} |
SyncedNotificationAppInfoService::~SyncedNotificationAppInfoService() {} |
@@ -139,6 +152,13 @@ syncer::SyncDataList SyncedNotificationAppInfoService::GetAllSyncData( |
return sync_data_list; |
} |
+// When a new protobuf comes in, we will fetch all the bitmaps before reporting |
+// the new protobufs to the ChromeNotifierService. This helps insure that new |
+// protobufs appear at the same time old ones disappear, and that no protobuf |
+// appears before its bitmaps are present. |
+// We also check for duplicate bitmap URLs when loading the bitmaps for a |
+// protobuf, so we aren't left waiting for a second copy of the bitmap to be |
+// fetched before we call the protobuf done. |
void SyncedNotificationAppInfoService::ProcessIncomingAppInfoProtobuf( |
const sync_pb::SyncedNotificationAppInfo& app_info) { |
// Build a local app_info object from the sync data. |
@@ -156,19 +176,66 @@ void SyncedNotificationAppInfoService::ProcessIncomingAppInfoProtobuf( |
SyncedNotificationAppInfo* found = FindSyncedNotificationAppInfoByName(name); |
- if (NULL != found) { |
+ std::vector<std::string> old_app_ids; |
+ std::vector<std::string> new_app_ids; |
+ std::vector<std::string> added_app_ids; |
+ std::vector<std::string> removed_app_ids; |
+ |
+ new_app_ids = incoming->GetAppIdList(); |
+ |
+ if (NULL == found) { |
+ added_app_ids = new_app_ids; |
+ } else { |
// When we have an update, some app id types may be added or removed. |
// Append to lists of added and removed types. |
+ old_app_ids = found->GetAppIdList(); |
+ new_app_ids = incoming->GetAppIdList(); |
FreeSyncedNotificationAppInfoByName(name); |
+ |
+ // Set up for a set difference by sorting the lists. |
+ std::sort(old_app_ids.begin(), old_app_ids.end()); |
+ std::sort(new_app_ids.begin(), new_app_ids.end()); |
+ |
+ // Calculate which app ids are removed (in old, but not in new app ids). |
+ std::set_difference(old_app_ids.begin(), |
+ old_app_ids.end(), |
+ new_app_ids.begin(), |
+ new_app_ids.end(), |
+ std::back_inserter(removed_app_ids)); |
+ |
+ // Calculate which app_ids are added (in new, but not in old app ids). |
+ std::set_difference(new_app_ids.begin(), |
+ new_app_ids.end(), |
+ old_app_ids.begin(), |
+ old_app_ids.end(), |
+ std::back_inserter(added_app_ids)); |
+ } |
+ |
+ // Put these lists into the app_info object. |
+ incoming->set_added_app_ids(added_app_ids); |
+ incoming->set_removed_app_ids(removed_app_ids); |
+ |
+ // Start bitmap fetch. |
+ if (!avoid_bitmap_fetching_for_test_) { |
+ incoming->QueueBitmapFetchJobs(); |
+ incoming->StartBitmapFetch(); |
+ } else { |
+ OnBitmapFetchesDone(incoming->added_app_ids(), incoming->removed_app_ids()); |
} |
sending_service_infos_.push_back(incoming.release()); |
+} |
+void SyncedNotificationAppInfoService::OnBitmapFetchesDone( |
+ std::vector<std::string> added_app_ids, |
+ std::vector<std::string> removed_app_ids) { |
// Tell the Chrome Notifier Service so it can show any notifications that were |
// waiting for the app id to arrive, and to remave any notifications that are |
// no longer supported. |
- // TODO(petewil): Notify CNS of added ids |
- // TODO(petewil): Notify CNS of deleted ids. |
+ if (chrome_notifier_service_ != NULL) { |
+ chrome_notifier_service_->OnAddedAppIds(added_app_ids); |
+ chrome_notifier_service_->OnRemovedAppIds(removed_app_ids); |
+ } |
} |
// Static Method. Convert from a server protobuf to our internal format. |
@@ -186,14 +253,17 @@ SyncedNotificationAppInfoService::CreateSyncedNotificationAppInfoFromProtobuf( |
return app_info.Pass(); |
// Create a new app info object based on the supplied protobuf. |
- app_info.reset(new SyncedNotificationAppInfo(display_name)); |
+ app_info.reset(new SyncedNotificationAppInfo(profile_, display_name, this)); |
// TODO(petewil): Eventually we will add the monochrome icon here, and we may |
// need to fetch the correct url for the current DPI. |
// Add the icon URL, if any. |
if (server_app_info.has_icon()) { |
std::string icon_url = server_app_info.icon().url(); |
- app_info->SetSettingsIcon(GURL(icon_url)); |
+ // Set the URLs for the low and high DPI images. |
+ // TODO(petewil): Since the high DPI image is not available yet, we just |
+ // pass an empty URL for now. Fix this once the high DPI URL is available. |
+ app_info->SetSettingsURLs(GURL(icon_url), GURL()); |
} |
// Add all the AppIds from the protobuf. |
@@ -222,6 +292,38 @@ SyncedNotificationAppInfoService::FindSyncedNotificationAppInfoByName( |
return NULL; |
} |
+// This returns a pointer into a vector that we own. Caller must not free it. |
+// Returns NULL if no match is found. |
+notifier::SyncedNotificationAppInfo* |
+SyncedNotificationAppInfoService::FindSyncedNotificationAppInfoByAppId( |
+ const std::string& app_id) { |
+ for (ScopedVector<SyncedNotificationAppInfo>::const_iterator it = |
+ sending_service_infos_.begin(); |
+ it != sending_service_infos_.end(); |
+ ++it) { |
+ SyncedNotificationAppInfo* app_info = *it; |
+ if (app_info->HasAppId(app_id)) |
+ return *it; |
+ } |
+ |
+ return NULL; |
+} |
+ |
+// Lookup the sending service name for a given app id. |
+std::string SyncedNotificationAppInfoService::FindSendingServiceNameFromAppId( |
+ const std::string app_id) { |
+ for (ScopedVector<SyncedNotificationAppInfo>::const_iterator it = |
+ sending_service_infos_.begin(); |
+ it != sending_service_infos_.end(); |
+ ++it) { |
+ SyncedNotificationAppInfo* app_info = *it; |
+ if (app_info->HasAppId(app_id)) |
+ return app_info->settings_display_name(); |
+ } |
+ |
+ return std::string(); |
+} |
+ |
void SyncedNotificationAppInfoService::FreeSyncedNotificationAppInfoByName( |
const std::string& name) { |
ScopedVector<SyncedNotificationAppInfo>::iterator it = |
@@ -235,6 +337,23 @@ void SyncedNotificationAppInfoService::FreeSyncedNotificationAppInfoByName( |
} |
} |
+std::vector<SyncedNotificationSendingServiceSettingsData> |
+SyncedNotificationAppInfoService::GetAllSendingServiceSettingsData() { |
+ std::vector<SyncedNotificationSendingServiceSettingsData> settings_data; |
+ ScopedVector<SyncedNotificationAppInfo>::iterator it = |
+ sending_service_infos_.begin(); |
+ |
+ for (; it != sending_service_infos_.end(); ++it) { |
+ SyncedNotificationSendingServiceSettingsData this_service( |
+ (*it)->settings_display_name(), |
+ (*it)->icon(), |
+ (*it)->GetNotifierId()); |
+ settings_data.push_back(this_service); |
+ } |
+ |
+ return settings_data; |
+} |
+ |
// Add a new app info to our data structure. This takes ownership |
// of the passed in pointer. |
void SyncedNotificationAppInfoService::Add( |