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

Side by Side Diff: extensions/common/features/feature_provider.cc

Issue 1768103002: Use scoped_ptr instead of linked_ptr from /e/c/features/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/features/feature_provider.h" 5 #include "extensions/common/features/feature_provider.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/memory/linked_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "extensions/common/extensions_client.h" 15 #include "extensions/common/extensions_client.h"
16 #include "extensions/common/features/feature_util.h" 16 #include "extensions/common/features/feature_util.h"
17 #include "extensions/common/switches.h" 17 #include "extensions/common/switches.h"
18 18
19 namespace extensions { 19 namespace extensions {
20 20
21 namespace { 21 namespace {
22 22
23 class Static { 23 class Static {
24 public: 24 public:
25 FeatureProvider* GetFeatures(const std::string& name) const { 25 FeatureProvider* GetFeatures(const std::string& name) const {
26 FeatureProviderMap::const_iterator it = feature_providers_.find(name); 26 auto it = feature_providers_.find(name);
27 if (it == feature_providers_.end()) 27 if (it == feature_providers_.end())
28 CRASH_WITH_MINIDUMP("FeatureProvider \"" + name + "\" not found"); 28 CRASH_WITH_MINIDUMP("FeatureProvider \"" + name + "\" not found");
29 return it->second.get(); 29 return it->second.get();
30 } 30 }
31 31
32 private: 32 private:
33 friend struct base::DefaultLazyInstanceTraits<Static>; 33 friend struct base::DefaultLazyInstanceTraits<Static>;
34 34
35 Static() { 35 Static() {
36 TRACE_EVENT0("startup", "extensions::FeatureProvider::Static"); 36 TRACE_EVENT0("startup", "extensions::FeatureProvider::Static");
37 base::Time begin_time = base::Time::Now(); 37 base::Time begin_time = base::Time::Now();
38 38
39 ExtensionsClient* client = ExtensionsClient::Get(); 39 ExtensionsClient* client = ExtensionsClient::Get();
40 feature_providers_["api"] = 40 feature_providers_["api"] = client->CreateFeatureProvider("api");
41 make_linked_ptr(client->CreateFeatureProvider("api").release()); 41 feature_providers_["manifest"] = client->CreateFeatureProvider("manifest");
42 feature_providers_["manifest"] =
43 make_linked_ptr(client->CreateFeatureProvider("manifest").release());
44 feature_providers_["permission"] = 42 feature_providers_["permission"] =
45 make_linked_ptr(client->CreateFeatureProvider("permission").release()); 43 client->CreateFeatureProvider("permission");
46 feature_providers_["behavior"] = 44 feature_providers_["behavior"] = client->CreateFeatureProvider("behavior");
47 make_linked_ptr(client->CreateFeatureProvider("behavior").release());
48 45
49 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 46 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
50 std::string process_type = 47 std::string process_type =
51 command_line->GetSwitchValueASCII(::switches::kProcessType); 48 command_line->GetSwitchValueASCII(::switches::kProcessType);
52 49
53 // Measure time only for browser process. This method gets called by the 50 // Measure time only for browser process. This method gets called by the
54 // browser process on startup, as well as on renderer and extension 51 // browser process on startup, as well as on renderer and extension
55 // processes throughout the execution of the browser. We are more 52 // processes throughout the execution of the browser. We are more
56 // interested in how long this takes as a startup cost, so we are 53 // interested in how long this takes as a startup cost, so we are
57 // just measuring the time in the browser process. 54 // just measuring the time in the browser process.
58 if (process_type == std::string()) { 55 if (process_type == std::string()) {
59 UMA_HISTOGRAM_TIMES("Extensions.FeatureProviderStaticInitTime", 56 UMA_HISTOGRAM_TIMES("Extensions.FeatureProviderStaticInitTime",
60 base::Time::Now() - begin_time); 57 base::Time::Now() - begin_time);
61 } 58 }
62 } 59 }
63 60
64 typedef std::map<std::string, linked_ptr<FeatureProvider> > 61 std::map<std::string, scoped_ptr<FeatureProvider>> feature_providers_;
65 FeatureProviderMap;
66
67 FeatureProviderMap feature_providers_;
68 }; 62 };
69 63
70 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; 64 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
71 65
72 const Feature* GetFeatureFromProviderByName(const std::string& provider_name, 66 const Feature* GetFeatureFromProviderByName(const std::string& provider_name,
73 const std::string& feature_name) { 67 const std::string& feature_name) {
74 const Feature* feature = 68 const Feature* feature =
75 FeatureProvider::GetByName(provider_name)->GetFeature(feature_name); 69 FeatureProvider::GetByName(provider_name)->GetFeature(feature_name);
76 if (!feature) { 70 if (!feature) {
77 CRASH_WITH_MINIDUMP("Feature \"" + feature_name + "\" not found in " + 71 CRASH_WITH_MINIDUMP("Feature \"" + feature_name + "\" not found in " +
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const Feature* FeatureProvider::GetPermissionFeature(const std::string& name) { 115 const Feature* FeatureProvider::GetPermissionFeature(const std::string& name) {
122 return GetFeatureFromProviderByName("permission", name); 116 return GetFeatureFromProviderByName("permission", name);
123 } 117 }
124 118
125 // static 119 // static
126 const Feature* FeatureProvider::GetBehaviorFeature(const std::string& name) { 120 const Feature* FeatureProvider::GetBehaviorFeature(const std::string& name) {
127 return GetFeatureFromProviderByName("behavior", name); 121 return GetFeatureFromProviderByName("behavior", name);
128 } 122 }
129 123
130 } // namespace extensions 124 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698