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()); |
+} |
+ |