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

Unified Diff: chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.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: CR fixes per DewittJ 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_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..d1a84e2d1ce037ac2ba337764214fff36e07d0a1 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;
+
SyncedNotificationAppInfoService::SyncedNotificationAppInfoService(
Profile* profile)
- : profile_(profile) {}
+ : profile_(profile), chrome_notifier_service_(NULL) {}
SyncedNotificationAppInfoService::~SyncedNotificationAppInfoService() {}
@@ -156,19 +160,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());
dewittj 2014/03/20 18:00:28 is it better to maintain a sorted order within Syn
Pete Williamson 2014/03/25 00:08:37 Adding a new app info is incredibly rare, as is re
+ 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->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 +237,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 +273,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 +318,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(

Powered by Google App Engine
This is Rietveld 408576698