OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/push_messaging/invalidation_handler.h" |
| 6 |
| 7 #include <utility> |
| 8 #include "base/stringprintf.h" |
| 9 #include "chrome/browser/extensions/api/push_messaging/invalidation_handler_obse
rver.h" |
| 10 |
| 11 namespace extensions { |
| 12 |
| 13 namespace { |
| 14 // TODO(dcheng): Use the chrome components source ID. |
| 15 const int kSourceId = 0xBAD; |
| 16 const int kNumberOfSubchannels = 4; |
| 17 |
| 18 // TODO(dcheng): The current Chrome component ID format is as follows: |
| 19 // <1 byte> - format type |
| 20 // The following bytes are dependent on the format type. We assume format type |
| 21 // "U" for the purpose of this comment: |
| 22 // <8 byte> - GAIA ID - invisible to client as it is munged server-side. |
| 23 // <2 byte> - project ID (I use AM for Apps Messaging) |
| 24 // <4 byte> - used for the subchannel for apps messaging. |
| 25 // <everything else> - extension ID for apps messaging. |
| 26 syncer::ObjectIdSet ExtensionIdToObjectIds(const std::string& extension_id) { |
| 27 syncer::ObjectIdSet object_ids; |
| 28 for (int i = 0; i < kNumberOfSubchannels; ++i) { |
| 29 std::string id = base::StringPrintf( |
| 30 "%c%s%04d%s", |
| 31 'U', // TODO(dcheng): We need to define a new format type. |
| 32 "AM", // Project ID |
| 33 i, // Subchannel ID |
| 34 extension_id.c_str()); |
| 35 object_ids.insert(invalidation::ObjectId(kSourceId, id)); |
| 36 } |
| 37 return object_ids; |
| 38 } |
| 39 } // namespace |
| 40 |
| 41 InvalidationHandler::InvalidationHandler(InvalidationHandlerObserver* observer) |
| 42 : observer_(observer) { |
| 43 DCHECK(observer); |
| 44 // The constructor will eventually take a ProfileSyncService to register |
| 45 // against. |
| 46 } |
| 47 |
| 48 InvalidationHandler::~InvalidationHandler() { |
| 49 // Eventually, we'll want to unregister from the profile sync service here. |
| 50 // ... or assert that we're not registered. |
| 51 } |
| 52 |
| 53 void InvalidationHandler::RegisterExtension(const std::string& id) { |
| 54 const syncer::ObjectIdSet& ids = ExtensionIdToObjectIds(id); |
| 55 for (syncer::ObjectIdSet::const_iterator it = ids.begin(); |
| 56 it != ids.end(); ++it) { |
| 57 registered_entries_.insert(std::make_pair(*it, InvalidationRecord())); |
| 58 } |
| 59 // TODO(dcheng): Update registrations here once akalin's patch has landed. |
| 60 } |
| 61 |
| 62 void InvalidationHandler::UnregisterExtension(const std::string& id) { |
| 63 const syncer::ObjectIdSet& ids = ExtensionIdToObjectIds(id); |
| 64 // TODO(dcheng): Cancel things that are in flight. |
| 65 for (syncer::ObjectIdSet::const_iterator it = ids.begin(); |
| 66 it != ids.end(); ++it) { |
| 67 registered_entries_.erase(*it); |
| 68 } |
| 69 // TODO(dcheng): Update registrations here once akalin's patch has landed. |
| 70 } |
| 71 |
| 72 void InvalidationHandler::OnIncomingNotification( |
| 73 const syncer::ObjectIdPayloadMap& id_payloads, |
| 74 syncer::IncomingNotificationSource source) { |
| 75 // Map it. |
| 76 // Dispatch it. |
| 77 // Record it. |
| 78 } |
| 79 |
| 80 void InvalidationHandler::OnNotificationsEnabled() { |
| 81 } |
| 82 |
| 83 void InvalidationHandler::OnNotificationsDisabled( |
| 84 syncer::NotificationsDisabledReason reason) { |
| 85 } |
| 86 |
| 87 } // namespace extensions |
OLD | NEW |