| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" | 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler_delegate.h" | 12 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler_delegate.h" |
| 13 #include "components/crx_file/id_util.h" |
| 13 #include "components/invalidation/invalidation_service.h" | 14 #include "components/invalidation/invalidation_service.h" |
| 14 #include "components/invalidation/object_id_invalidation_map.h" | 15 #include "components/invalidation/object_id_invalidation_map.h" |
| 15 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 16 #include "google/cacheinvalidation/types.pb.h" | 17 #include "google/cacheinvalidation/types.pb.h" |
| 17 | 18 |
| 18 namespace extensions { | 19 namespace extensions { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const int kNumberOfSubchannels = 4; | 23 const int kNumberOfSubchannels = 4; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 53 std::vector<std::string> components; | 54 std::vector<std::string> components; |
| 54 base::SplitStringDontTrim(name, '/', &components); | 55 base::SplitStringDontTrim(name, '/', &components); |
| 55 if (components.size() < 3) { | 56 if (components.size() < 3) { |
| 56 DLOG(WARNING) << "Invalid format type from object name " << name; | 57 DLOG(WARNING) << "Invalid format type from object name " << name; |
| 57 return false; | 58 return false; |
| 58 } | 59 } |
| 59 if (components[0] != "U") { | 60 if (components[0] != "U") { |
| 60 DLOG(WARNING) << "Invalid format type from object name " << name; | 61 DLOG(WARNING) << "Invalid format type from object name " << name; |
| 61 return false; | 62 return false; |
| 62 } | 63 } |
| 63 if (!Extension::IdIsValid(components[1])) { | 64 if (!crx_file::id_util::IdIsValid(components[1])) { |
| 64 DLOG(WARNING) << "Invalid extension ID from object name " << name; | 65 DLOG(WARNING) << "Invalid extension ID from object name " << name; |
| 65 return false; | 66 return false; |
| 66 } | 67 } |
| 67 *extension_id = components[1]; | 68 *extension_id = components[1]; |
| 68 if (!base::StringToInt(components[2], subchannel)) { | 69 if (!base::StringToInt(components[2], subchannel)) { |
| 69 DLOG(WARNING) << "Subchannel not a number from object name " << name; | 70 DLOG(WARNING) << "Subchannel not a number from object name " << name; |
| 70 return false; | 71 return false; |
| 71 } | 72 } |
| 72 if (*subchannel < 0 || *subchannel >= kNumberOfSubchannels) { | 73 if (*subchannel < 0 || *subchannel >= kNumberOfSubchannels) { |
| 73 DLOG(WARNING) << "Subchannel out of range from object name " << name; | 74 DLOG(WARNING) << "Subchannel out of range from object name " << name; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 96 const std::string& extension_id) { | 97 const std::string& extension_id) { |
| 97 DCHECK(thread_checker_.CalledOnValidThread()); | 98 DCHECK(thread_checker_.CalledOnValidThread()); |
| 98 const syncer::ObjectIdSet& suppressed_ids = | 99 const syncer::ObjectIdSet& suppressed_ids = |
| 99 ExtensionIdToObjectIds(extension_id); | 100 ExtensionIdToObjectIds(extension_id); |
| 100 suppressed_ids_.insert(suppressed_ids.begin(), suppressed_ids.end()); | 101 suppressed_ids_.insert(suppressed_ids.begin(), suppressed_ids.end()); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void PushMessagingInvalidationHandler::RegisterExtension( | 104 void PushMessagingInvalidationHandler::RegisterExtension( |
| 104 const std::string& extension_id) { | 105 const std::string& extension_id) { |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); | 106 DCHECK(thread_checker_.CalledOnValidThread()); |
| 106 DCHECK(Extension::IdIsValid(extension_id)); | 107 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 107 registered_extensions_.insert(extension_id); | 108 registered_extensions_.insert(extension_id); |
| 108 UpdateRegistrations(); | 109 UpdateRegistrations(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void PushMessagingInvalidationHandler::UnregisterExtension( | 112 void PushMessagingInvalidationHandler::UnregisterExtension( |
| 112 const std::string& extension_id) { | 113 const std::string& extension_id) { |
| 113 DCHECK(thread_checker_.CalledOnValidThread()); | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
| 114 DCHECK(Extension::IdIsValid(extension_id)); | 115 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 115 registered_extensions_.erase(extension_id); | 116 registered_extensions_.erase(extension_id); |
| 116 UpdateRegistrations(); | 117 UpdateRegistrations(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void PushMessagingInvalidationHandler::OnInvalidatorStateChange( | 120 void PushMessagingInvalidationHandler::OnInvalidatorStateChange( |
| 120 syncer::InvalidatorState state) { | 121 syncer::InvalidatorState state) { |
| 121 DCHECK(thread_checker_.CalledOnValidThread()); | 122 DCHECK(thread_checker_.CalledOnValidThread()); |
| 122 // Nothing to do. | 123 // Nothing to do. |
| 123 } | 124 } |
| 124 | 125 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 for (std::set<std::string>::const_iterator it = | 190 for (std::set<std::string>::const_iterator it = |
| 190 registered_extensions_.begin(); it != registered_extensions_.end(); | 191 registered_extensions_.begin(); it != registered_extensions_.end(); |
| 191 ++it) { | 192 ++it) { |
| 192 const syncer::ObjectIdSet& object_ids = ExtensionIdToObjectIds(*it); | 193 const syncer::ObjectIdSet& object_ids = ExtensionIdToObjectIds(*it); |
| 193 ids.insert(object_ids.begin(), object_ids.end()); | 194 ids.insert(object_ids.begin(), object_ids.end()); |
| 194 } | 195 } |
| 195 service_->UpdateRegisteredInvalidationIds(this, ids); | 196 service_->UpdateRegisteredInvalidationIds(this, ids); |
| 196 } | 197 } |
| 197 | 198 |
| 198 } // namespace extensions | 199 } // namespace extensions |
| OLD | NEW |