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..9222d514f504b1904c54c77131f365090971b350 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,11 @@ |
namespace notifier { |
+bool SyncedNotificationAppInfoService::avoid_bitmap_fetching_for_test_ = false; |
dewittj
2014/03/17 21:43:43
maybe a better way to do this is to have a bitmapf
Pete Williamson
2014/03/21 01:22:31
In my opinion the simplicity of having a flag is b
|
+ |
SyncedNotificationAppInfoService::SyncedNotificationAppInfoService( |
Profile* profile) |
- : profile_(profile) {} |
+ : profile_(profile), chrome_notifier_service_(NULL) {} |
SyncedNotificationAppInfoService::~SyncedNotificationAppInfoService() {} |
@@ -156,19 +160,77 @@ 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; |
+ |
+ incoming->GetAppIdList(&new_app_ids); |
+ |
+ 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. |
+ found->GetAppIdList(&old_app_ids); |
+ incoming->GetAppIdList(&new_app_ids); |
FreeSyncedNotificationAppInfoByName(name); |
+ |
+ // Pre-reserve enough space in the output vectors because set_difference |
+ // uses assignment to array elements, not push_back. |
dewittj
2014/03/17 21:43:43
Consider using std::back_inserter here, like this:
Pete Williamson
2014/03/21 01:22:31
Done. Good catch, I'd forgotten about back_insert
|
+ size_t max_added_size = new_app_ids.size(); |
+ size_t max_removed_size = old_app_ids.size(); |
+ for (size_t ii = 0; ii < max_added_size; ++ii) { |
+ added_app_ids.push_back(std::string()); |
+ } |
+ for (size_t jj = 0; jj < max_removed_size; ++jj) { |
+ removed_app_ids.push_back(std::string()); |
+ } |
+ |
+ // 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(), |
+ removed_app_ids.begin()); |
+ |
+ // 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(), |
+ added_app_ids.begin()); |
+ } |
+ |
+ // Put these lists into the app_info object. |
+ incoming->SetAddedAppIds(added_app_ids); |
+ incoming->SetRemovedAppIds(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_->SetAddedAppIds(added_app_ids); |
+ chrome_notifier_service_->SetRemovedAppIds(removed_app_ids); |
+ } |
} |
// Static Method. Convert from a server protobuf to our internal format. |
@@ -186,7 +248,7 @@ 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. |
@@ -222,6 +284,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 +329,20 @@ void SyncedNotificationAppInfoService::FreeSyncedNotificationAppInfoByName( |
} |
} |
+std::vector<std::string> |
+SyncedNotificationAppInfoService::GetAllSendingServiceNames() { |
+ std::vector<std::string> names; |
+ ScopedVector<SyncedNotificationAppInfo>::iterator it = |
+ sending_service_infos_.begin(); |
+ |
+ for (; it != sending_service_infos_.end(); ++it) { |
+ SyncedNotificationAppInfo* app_info = *it; |
+ names.push_back(app_info->settings_display_name()); |
+ } |
+ |
+ return names; |
+} |
+ |
// Add a new app info to our data structure. This takes ownership |
// of the passed in pointer. |
void SyncedNotificationAppInfoService::Add( |