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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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/consumer_id_factory.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/memory/linked_ptr.h"
9
10 namespace {
11 using RequestContentScriptKeyToIDMap =
12 std::map<RequestContentScriptKey, linked_ptr<ConsumerID>>;
13
14 // A map of ConsumerIDs for the given RequestContentScript ids.
15 // Different types of input ids will define their own maps to store the
16 // mappings from ids to ConsumerIDs.
17 static base::LazyInstance<RequestContentScriptKeyToIDMap>
18 request_content_script_key_to_id_map_ = LAZY_INSTANCE_INITIALIZER;
19
20 int current_instance_id_ = ConsumerID::kDefaultInstanceID;
21
22 // Get next available instance ID.
23 static int GetNextID() {
24 return ++current_instance_id_;
25 }
26
27 } // namespace
28
29 // static
30 const ConsumerID& ConsumerIDFactory::Create(
31 const RequestContentScriptKey& key,
32 ConsumerID::HostType host_type,
33 ConsumerID::InstanceType instance_type) {
34 RequestContentScriptKeyToIDMap::iterator it =
35 request_content_script_key_to_id_map_.Get().find(key);
36 if (it != request_content_script_key_to_id_map_.Get().end())
37 return *(it->second.get());
38
39 linked_ptr<ConsumerID> consumer_id(new ConsumerID(
40 host_type, key.host_id, instance_type, GetNextID()));
41 request_content_script_key_to_id_map_.Get()[key] = consumer_id;
42 return *(consumer_id.get());
43 }
44
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698