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

Unified Diff: chrome/browser/extensions/consumer_id_factory.cc

Issue 822453002: Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce ConsumerIDFactory Created 5 years, 11 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/consumer_id_factory.cc
diff --git a/chrome/browser/extensions/consumer_id_factory.cc b/chrome/browser/extensions/consumer_id_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3c68fe23e6782f9c4f56f822bbeb1152bbfee56a
--- /dev/null
+++ b/chrome/browser/extensions/consumer_id_factory.cc
@@ -0,0 +1,44 @@
+// Copyright 2014 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/consumer_id_factory.h"
+
+#include "base/lazy_instance.h"
+#include "base/memory/linked_ptr.h"
+
+namespace {
+using RequestContentScriptKeyToIDMap =
+ std::map<RequestContentScriptKey, linked_ptr<ConsumerID>>;
+
+// A map of ConsumerIDs for the given RequestContentScript ids.
+// Different types of input ids will define their own maps to store the
+// mappings from ids to ConsumerIDs.
+static base::LazyInstance<RequestContentScriptKeyToIDMap>
+ request_content_script_key_to_id_map_ = LAZY_INSTANCE_INITIALIZER;
+
+int current_instance_id_ = ConsumerID::kDefaultInstanceID;
+
+// Get next available instance ID.
+static int GetNextID() {
+ return ++current_instance_id_;
+}
+
+} // namespace
+
+// static
+const ConsumerID& ConsumerIDFactory::Create(
+ const RequestContentScriptKey& key,
+ ConsumerID::HostType host_type,
+ ConsumerID::InstanceType instance_type) {
+ RequestContentScriptKeyToIDMap::iterator it =
+ request_content_script_key_to_id_map_.Get().find(key);
+ if (it != request_content_script_key_to_id_map_.Get().end())
+ return *(it->second.get());
+
+ linked_ptr<ConsumerID> consumer_id(new ConsumerID(
+ host_type, key.host_id, instance_type, GetNextID()));
+ request_content_script_key_to_id_map_.Get()[key] = consumer_id;
+ return *(consumer_id.get());
+}
+

Powered by Google App Engine
This is Rietveld 408576698