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

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

Issue 1835863002: Added check for behavior feature existense (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make Get*Feature return |nullptr| instead crash if feature is missing Created 4 years, 8 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
« no previous file with comments | « extensions/common/features/feature_provider.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
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/scoped_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.h"
16 #include "extensions/common/features/feature_util.h" 17 #include "extensions/common/features/feature_util.h"
17 #include "extensions/common/switches.h" 18 #include "extensions/common/switches.h"
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 namespace { 22 namespace {
22 23
23 class Static { 24 class Static {
24 public: 25 public:
25 FeatureProvider* GetFeatures(const std::string& name) const { 26 FeatureProvider* GetFeatures(const std::string& name) const {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 61
61 std::map<std::string, scoped_ptr<FeatureProvider>> feature_providers_; 62 std::map<std::string, scoped_ptr<FeatureProvider>> feature_providers_;
62 }; 63 };
63 64
64 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; 65 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
65 66
66 const Feature* GetFeatureFromProviderByName(const std::string& provider_name, 67 const Feature* GetFeatureFromProviderByName(const std::string& provider_name,
67 const std::string& feature_name) { 68 const std::string& feature_name) {
68 const Feature* feature = 69 const Feature* feature =
69 FeatureProvider::GetByName(provider_name)->GetFeature(feature_name); 70 FeatureProvider::GetByName(provider_name)->GetFeature(feature_name);
70 if (!feature) { 71 // We should always refer to existing features, but we can't CHECK here
71 CRASH_WITH_MINIDUMP("Feature \"" + feature_name + "\" not found in " + 72 // due to flaky JSONReader fails, see: crbug.com/176381, crbug.com/602936
72 "FeatureProvider \"" + provider_name + "\""); 73 DCHECK(feature) << "Feature \"" << feature_name << "\" not found in "
73 } 74 << "FeatureProvider \"" << provider_name << "\"";
74 return feature; 75 return feature;
75 } 76 }
76 77
77 } // namespace 78 } // namespace
78 79
79 // static 80 // static
80 const FeatureProvider* FeatureProvider::GetByName(const std::string& name) { 81 const FeatureProvider* FeatureProvider::GetByName(const std::string& name) {
81 return g_static.Get().GetFeatures(name); 82 return g_static.Get().GetFeatures(name);
82 } 83 }
83 84
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const Feature* FeatureProvider::GetPermissionFeature(const std::string& name) { 116 const Feature* FeatureProvider::GetPermissionFeature(const std::string& name) {
116 return GetFeatureFromProviderByName("permission", name); 117 return GetFeatureFromProviderByName("permission", name);
117 } 118 }
118 119
119 // static 120 // static
120 const Feature* FeatureProvider::GetBehaviorFeature(const std::string& name) { 121 const Feature* FeatureProvider::GetBehaviorFeature(const std::string& name) {
121 return GetFeatureFromProviderByName("behavior", name); 122 return GetFeatureFromProviderByName("behavior", name);
122 } 123 }
123 124
124 } // namespace extensions 125 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/feature_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698