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

Unified Diff: third_party/cacheinvalidation/src/google/cacheinvalidation/impl/simple-registration-store.cc

Issue 1162033004: Pull cacheinvalidations code directory into chromium repo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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: third_party/cacheinvalidation/src/google/cacheinvalidation/impl/simple-registration-store.cc
diff --git a/third_party/cacheinvalidation/src/google/cacheinvalidation/impl/simple-registration-store.cc b/third_party/cacheinvalidation/src/google/cacheinvalidation/impl/simple-registration-store.cc
new file mode 100644
index 0000000000000000000000000000000000000000..98d284ace8d329cbd331ded7135dcca3a63fa8bb
--- /dev/null
+++ b/third_party/cacheinvalidation/src/google/cacheinvalidation/impl/simple-registration-store.cc
@@ -0,0 +1,107 @@
+// Copyright 2012 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Simple, map-based implementation of DigestStore.
+
+#include "google/cacheinvalidation/impl/simple-registration-store.h"
+
+#include "google/cacheinvalidation/impl/object-id-digest-utils.h"
+
+namespace invalidation {
+
+bool SimpleRegistrationStore::Add(const ObjectIdP& oid) {
+ const string digest = ObjectIdDigestUtils::GetDigest(oid, digest_function_);
+ bool will_add = (registrations_.find(digest) == registrations_.end());
+ if (will_add) {
+ registrations_[digest] = oid;
+ RecomputeDigest();
+ }
+ return will_add;
+}
+
+void SimpleRegistrationStore::Add(const vector<ObjectIdP>& oids,
+ vector<ObjectIdP>* oids_to_send) {
+ for (size_t i = 0; i < oids.size(); ++i) {
+ const ObjectIdP& oid = oids[i];
+ const string digest = ObjectIdDigestUtils::GetDigest(oid, digest_function_);
+ bool will_add = (registrations_.find(digest) == registrations_.end());
+ if (will_add) {
+ registrations_[digest] = oid;
+ oids_to_send->push_back(oid);
+ }
+ }
+ if (!oids_to_send->empty()) {
+ // Only recompute the digest if we made changes.
+ RecomputeDigest();
+ }
+}
+
+bool SimpleRegistrationStore::Remove(const ObjectIdP& oid) {
+ const string digest = ObjectIdDigestUtils::GetDigest(oid, digest_function_);
+ bool will_remove = (registrations_.find(digest) != registrations_.end());
+ if (will_remove) {
+ registrations_.erase(digest);
+ RecomputeDigest();
+ }
+ return will_remove;
+}
+
+void SimpleRegistrationStore::Remove(const vector<ObjectIdP>& oids,
+ vector<ObjectIdP>* oids_to_send) {
+ for (size_t i = 0; i < oids.size(); ++i) {
+ const ObjectIdP& oid = oids[i];
+ const string digest = ObjectIdDigestUtils::GetDigest(oid, digest_function_);
+ bool will_remove = (registrations_.find(digest) != registrations_.end());
+ if (will_remove) {
+ registrations_.erase(digest);
+ oids_to_send->push_back(oid);
+ }
+ }
+ if (!oids_to_send->empty()) {
+ // Only recompute the digest if we made changes.
+ RecomputeDigest();
+ }
+}
+
+void SimpleRegistrationStore::RemoveAll(vector<ObjectIdP>* oids) {
+ for (map<string, ObjectIdP>::const_iterator iter = registrations_.begin();
+ iter != registrations_.end(); ++iter) {
+ oids->push_back(iter->second);
+ }
+ registrations_.clear();
+ RecomputeDigest();
+}
+
+bool SimpleRegistrationStore::Contains(const ObjectIdP& oid) {
+ return registrations_.find(
+ ObjectIdDigestUtils::GetDigest(oid, digest_function_)) !=
+ registrations_.end();
+}
+
+void SimpleRegistrationStore::GetElements(
+ const string& oid_digest_prefix, int prefix_len,
+ vector<ObjectIdP>* result) {
+ // We always return all the registrations and let the Ticl sort it out.
+ for (map<string, ObjectIdP>::iterator iter = registrations_.begin();
+ iter != registrations_.end(); ++iter) {
+ result->push_back(iter->second);
+ }
+}
+
+void SimpleRegistrationStore::RecomputeDigest() {
+ digest_ = ObjectIdDigestUtils::GetDigest(
+ registrations_, digest_function_);
+}
+
+} // namespace invalidation

Powered by Google App Engine
This is Rietveld 408576698