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

Side by Side Diff: chrome/common/extensions/manifest_handler.cc

Issue 11446034: SupportsUserData and manifest handlers for Extension; use them for the Omnibox API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + manifestdata Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/manifest_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/manifest_handler.h"
6
7 #include <map>
8
9 #include "base/lazy_instance.h"
10 #include "base/memory/linked_ptr.h"
11
12 namespace extensions {
13
14 namespace {
15
16 class ManifestHandlerRegistry {
17 public:
18 void RegisterManifestHandler(const std::string& key,
19 ManifestHandler* handler);
20 ManifestHandler* GetManifestHandler(const std::string& key);
21 std::vector<std::string> GetManifestHandlerKeys();
22
23 private:
24 friend struct base::DefaultLazyInstanceTraits<ManifestHandlerRegistry>;
25 typedef std::map<std::string, linked_ptr<ManifestHandler> >
26 ManifestHandlerMap;
27
28 ManifestHandlerMap handlers_;
29 };
30
31 void ManifestHandlerRegistry::RegisterManifestHandler(
32 const std::string& key, ManifestHandler* handler) {
33 handlers_[key] = make_linked_ptr(handler);
34 }
35
36 ManifestHandler* ManifestHandlerRegistry::GetManifestHandler(
37 const std::string& key) {
38 ManifestHandlerMap::iterator iter = handlers_.find(key);
39 if (iter != handlers_.end())
40 return iter->second.get();
41 // TODO(yoz): The NOTREACHED only makes sense as long as
42 // GetManifestHandlerKeys is how we're getting the available
43 // manifest handlers.
44 NOTREACHED();
45 return NULL;
46 }
47
48 std::vector<std::string> ManifestHandlerRegistry::GetManifestHandlerKeys() {
49 std::vector<std::string> keys;
50 for (ManifestHandlerMap::iterator iter = handlers_.begin();
51 iter != handlers_.end(); ++iter) {
52 keys.push_back(iter->first);
53 }
54 return keys;
55 }
56
57 static base::LazyInstance<ManifestHandlerRegistry> g_registry =
58 LAZY_INSTANCE_INITIALIZER;
59
60 } // namespace
61
62 ManifestHandler::ManifestHandler() {
63 }
64
65 ManifestHandler::~ManifestHandler() {
66 }
67
68 // static
69 void ManifestHandler::Register(const std::string& key,
70 ManifestHandler* handler) {
71 g_registry.Get().RegisterManifestHandler(key, handler);
72 }
73
74 // static
75 ManifestHandler* ManifestHandler::Get(const std::string& key) {
76 return g_registry.Get().GetManifestHandler(key);
77 }
78
79 // static
80 std::vector<std::string> ManifestHandler::GetKeys() {
81 return g_registry.Get().GetManifestHandlerKeys();
82 }
83
84 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698