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 |