Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 BB// Copyright 2013 The Chromium Authors. All rights reserved. |
|
robliao
2015/03/13 19:21:19
Remove the BB
rkaplow
2015/03/13 19:42:48
Done.
| |
| 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | |
| 10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 11 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/metrics/histogram_macros.h" | |
| 14 #include "base/trace_event/trace_event.h" | |
| 15 #include "content/public/common/content_switches.h" | |
| 12 #include "extensions/common/extensions_client.h" | 16 #include "extensions/common/extensions_client.h" |
| 17 #include "extensions/common/switches.h" | |
| 13 | 18 |
| 14 namespace extensions { | 19 namespace extensions { |
| 15 | 20 |
| 16 namespace { | 21 namespace { |
| 17 | 22 |
| 18 class Static { | 23 class Static { |
| 19 public: | 24 public: |
| 20 FeatureProvider* GetFeatures(const std::string& name) const { | 25 FeatureProvider* GetFeatures(const std::string& name) const { |
| 21 FeatureProviderMap::const_iterator it = feature_providers_.find(name); | 26 FeatureProviderMap::const_iterator it = feature_providers_.find(name); |
| 22 CHECK(it != feature_providers_.end()); | 27 CHECK(it != feature_providers_.end()); |
| 23 return it->second.get(); | 28 return it->second.get(); |
| 24 } | 29 } |
| 25 | 30 |
| 26 private: | 31 private: |
| 27 friend struct base::DefaultLazyInstanceTraits<Static>; | 32 friend struct base::DefaultLazyInstanceTraits<Static>; |
| 28 | 33 |
| 29 Static() { | 34 Static() { |
| 35 TRACE_EVENT0("startup", "extensions::FeatureProvider::Static"); | |
|
not at google - send to devlin
2015/03/13 19:08:05
What does "startup" mean?
rkaplow
2015/03/13 19:19:15
It's a "category" used in the tracing tool, like a
not at google - send to devlin
2015/03/13 19:25:20
Ok, thanks. I guess it does happen on startup, tho
rkaplow
2015/03/13 19:42:48
Right. I don't think there's a big downside, I thi
| |
| 36 base::Time begin_time = base::Time::Now(); | |
| 37 | |
| 30 ExtensionsClient* client = ExtensionsClient::Get(); | 38 ExtensionsClient* client = ExtensionsClient::Get(); |
| 31 feature_providers_["api"] = | 39 feature_providers_["api"] = |
| 32 make_linked_ptr(client->CreateFeatureProvider("api").release()); | 40 make_linked_ptr(client->CreateFeatureProvider("api").release()); |
| 33 feature_providers_["manifest"] = | 41 feature_providers_["manifest"] = |
| 34 make_linked_ptr(client->CreateFeatureProvider("manifest").release()); | 42 make_linked_ptr(client->CreateFeatureProvider("manifest").release()); |
| 35 feature_providers_["permission"] = | 43 feature_providers_["permission"] = |
| 36 make_linked_ptr(client->CreateFeatureProvider("permission").release()); | 44 make_linked_ptr(client->CreateFeatureProvider("permission").release()); |
| 37 feature_providers_["behavior"] = | 45 feature_providers_["behavior"] = |
| 38 make_linked_ptr(client->CreateFeatureProvider("behavior").release()); | 46 make_linked_ptr(client->CreateFeatureProvider("behavior").release()); |
| 39 } | 47 |
| 48 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 49 std::string process_type = | |
| 50 command_line->GetSwitchValueASCII(::switches::kProcessType); | |
| 51 | |
| 52 // Measure time only for browser process. | |
|
not at google - send to devlin
2015/03/13 19:08:05
Why only browser process, does UMA only work from
rkaplow
2015/03/13 19:19:15
No, it doesn't, and that's actually the problem.
T
not at google - send to devlin
2015/03/13 19:25:20
Ok, thanks. Yes it needs to get read on every ever
rkaplow
2015/03/13 19:42:48
Done.
| |
| 53 if (process_type == "") { | |
| 54 UMA_HISTOGRAM_TIMES("Extensions.FeatureProviderStaticInitTime", | |
| 55 base::Time::Now() - begin_time); | |
| 56 } | |
| 57 } | |
| 40 | 58 |
| 41 typedef std::map<std::string, linked_ptr<FeatureProvider> > | 59 typedef std::map<std::string, linked_ptr<FeatureProvider> > |
| 42 FeatureProviderMap; | 60 FeatureProviderMap; |
| 43 | 61 |
| 44 FeatureProviderMap feature_providers_; | 62 FeatureProviderMap feature_providers_; |
| 45 }; | 63 }; |
| 46 | 64 |
| 47 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; | 65 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; |
| 48 | 66 |
| 49 const Feature* GetFeatureFromProviderByName(const std::string& provider_name, | 67 const Feature* GetFeatureFromProviderByName(const std::string& provider_name, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 const Feature* FeatureProvider::GetPermissionFeature(const std::string& name) { | 116 const Feature* FeatureProvider::GetPermissionFeature(const std::string& name) { |
| 99 return GetFeatureFromProviderByName("permission", name); | 117 return GetFeatureFromProviderByName("permission", name); |
| 100 } | 118 } |
| 101 | 119 |
| 102 // static | 120 // static |
| 103 const Feature* FeatureProvider::GetBehaviorFeature(const std::string& name) { | 121 const Feature* FeatureProvider::GetBehaviorFeature(const std::string& name) { |
| 104 return GetFeatureFromProviderByName("behavior", name); | 122 return GetFeatureFromProviderByName("behavior", name); |
| 105 } | 123 } |
| 106 | 124 |
| 107 } // namespace extensions | 125 } // namespace extensions |
| OLD | NEW |