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

Unified Diff: chrome/browser/extensions/api/push_messaging/invalidation_handler.cc

Issue 10837013: Chrome Cloud Messaging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: InvalidationHandler + event Created 8 years, 5 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/extensions/api/push_messaging/invalidation_handler.cc
diff --git a/chrome/browser/extensions/api/push_messaging/invalidation_handler.cc b/chrome/browser/extensions/api/push_messaging/invalidation_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2dad58612cad9dcf99039bf6b2fc931448a7ea0b
--- /dev/null
+++ b/chrome/browser/extensions/api/push_messaging/invalidation_handler.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/push_messaging/invalidation_handler.h"
+
+#include <utility>
+#include "base/stringprintf.h"
+#include "chrome/browser/extensions/api/push_messaging/invalidation_handler_observer.h"
+
+namespace extensions {
+
+namespace {
+// TODO(dcheng): Use the chrome components source ID.
+const int kSourceId = 0xBAD;
+const int kNumberOfSubchannels = 4;
+
+// TODO(dcheng): The current Chrome component ID format is as follows:
+// <1 byte> - format type
+// The following bytes are dependent on the format type. We assume format type
+// "U" for the purpose of this comment:
+// <8 byte> - GAIA ID - invisible to client as it is munged server-side.
+// <2 byte> - project ID (I use AM for Apps Messaging)
+// <4 byte> - used for the subchannel for apps messaging.
+// <everything else> - extension ID for apps messaging.
+syncer::ObjectIdSet ExtensionIdToObjectIds(const std::string& extension_id) {
+ syncer::ObjectIdSet object_ids;
+ for (int i = 0; i < kNumberOfSubchannels; ++i) {
+ std::string id = base::StringPrintf(
+ "%c%s%04d%s",
+ 'U', // TODO(dcheng): We need to define a new format type.
+ "AM", // Project ID
+ i, // Subchannel ID
+ extension_id.c_str());
+ object_ids.insert(invalidation::ObjectId(kSourceId, id));
+ }
+ return object_ids;
+}
+} // namespace
+
+InvalidationHandler::InvalidationHandler(InvalidationHandlerObserver* observer)
+ : observer_(observer) {
+ DCHECK(observer);
+ // The constructor will eventually take a ProfileSyncService to register
+ // against.
+}
+
+InvalidationHandler::~InvalidationHandler() {
+ // Eventually, we'll want to unregister from the profile sync service here.
+ // ... or assert that we're not registered.
+}
+
+void InvalidationHandler::RegisterExtension(const std::string& id) {
+ const syncer::ObjectIdSet& ids = ExtensionIdToObjectIds(id);
+ for (syncer::ObjectIdSet::const_iterator it = ids.begin();
+ it != ids.end(); ++it) {
+ registered_entries_.insert(std::make_pair(*it, InvalidationRecord()));
+ }
+ // TODO(dcheng): Update registrations here once akalin's patch has landed.
+}
+
+void InvalidationHandler::UnregisterExtension(const std::string& id) {
+ const syncer::ObjectIdSet& ids = ExtensionIdToObjectIds(id);
+ // TODO(dcheng): Cancel things that are in flight.
+ for (syncer::ObjectIdSet::const_iterator it = ids.begin();
+ it != ids.end(); ++it) {
+ registered_entries_.erase(*it);
+ }
+ // TODO(dcheng): Update registrations here once akalin's patch has landed.
+}
+
+void InvalidationHandler::OnIncomingNotification(
+ const syncer::ObjectIdPayloadMap& id_payloads,
+ syncer::IncomingNotificationSource source) {
+ // Map it.
+ // Dispatch it.
+ // Record it.
+}
+
+void InvalidationHandler::OnNotificationsEnabled() {
+}
+
+void InvalidationHandler::OnNotificationsDisabled(
+ syncer::NotificationsDisabledReason reason) {
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698