Index: extensions/browser/api/declarative/declarative_api.cc |
diff --git a/extensions/browser/api/declarative/declarative_api.cc b/extensions/browser/api/declarative/declarative_api.cc |
index 8049813f6c18121e5084c8aa23cc54f4a13e53e0..8a879579d4dafd198c9b4bdf27615e69e837ba0d 100644 |
--- a/extensions/browser/api/declarative/declarative_api.cc |
+++ b/extensions/browser/api/declarative/declarative_api.cc |
@@ -9,7 +9,9 @@ |
#include "base/base64.h" |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
+#include "base/metrics/histogram_macros.h" |
#include "base/single_thread_task_runner.h" |
+#include "base/strings/string_util.h" |
#include "base/task_runner_util.h" |
#include "base/values.h" |
#include "content/public/browser/browser_thread.h" |
@@ -35,7 +37,55 @@ namespace extensions { |
namespace { |
-const char kDeclarativeEventPrefix[] = "declarative"; |
+constexpr char kDeclarativeEventPrefix[] = "declarative"; |
+constexpr char kDeclarativeContentEventPrefix[] = "declarativeContent."; |
+constexpr char kDeclarativeWebRequestEventPrefix[] = "declarativeWebRequest."; |
+constexpr char kDeclarativeWebRequestWebViewEventPrefix[] = |
+ "webViewInternal.declarativeWebRequest."; |
+ |
+// The type of Declarative API. To collect more granular metrics, a distinction |
+// is made when the declarative web request API is used from a webview. |
+enum class DeclarativeAPIType { |
+ kContent, |
+ kWebRequest, |
+ kWebRequestWebview, |
+ kUnknown, |
+}; |
+ |
+// Describes the possible types of declarative API function calls. |
+// These values are recorded as UMA. New enum values can be added, but existing |
+// enum values must never be renumbered or deleted and reused. |
+enum DeclarativeAPIFunctionType { |
+ kDeclarativeContentAddRules = 0, |
+ kDeclarativeContentRemoveRules = 1, |
+ kDeclarativeContentGetRules = 2, |
+ kDeclarativeWebRequestAddRules = 3, |
+ kDeclarativeWebRequestRemoveRules = 4, |
+ kDeclarativeWebRequestGetRules = 5, |
+ kDeclarativeWebRequestWebviewAddRules = 6, |
+ kDeclarativeWebRequestWebviewRemoveRules = 7, |
+ kDeclarativeWebRequestWebviewGetRules = 8, |
+ kDeclarativeApiFunctionCallTypeMax, |
+}; |
+ |
+DeclarativeAPIType GetDeclarativeAPIType(const std::string& event_name) { |
+ if (base::StartsWith(event_name, kDeclarativeContentEventPrefix, |
+ base::CompareCase::SENSITIVE)) |
+ return DeclarativeAPIType::kContent; |
+ if (base::StartsWith(event_name, kDeclarativeWebRequestEventPrefix, |
+ base::CompareCase::SENSITIVE)) |
+ return DeclarativeAPIType::kWebRequest; |
+ if (base::StartsWith(event_name, kDeclarativeWebRequestWebViewEventPrefix, |
+ base::CompareCase::SENSITIVE)) |
+ return DeclarativeAPIType::kWebRequestWebview; |
+ return DeclarativeAPIType::kUnknown; |
+} |
+ |
+void RecordUMAHelper(DeclarativeAPIFunctionType type) { |
+ DCHECK_LT(type, kDeclarativeApiFunctionCallTypeMax); |
+ UMA_HISTOGRAM_ENUMERATION("Extensions.DeclarativeAPIFunctionCalls", type, |
+ kDeclarativeApiFunctionCallTypeMax); |
+} |
void ConvertBinaryDictionaryValuesToBase64(base::DictionaryValue* dict); |
@@ -125,6 +175,8 @@ bool RulesFunction::RunAsync() { |
EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &web_view_instance_id)); |
int embedder_process_id = render_frame_host()->GetProcess()->GetID(); |
+ RecordUMA(event_name); |
+ |
bool from_web_view = web_view_instance_id != 0; |
// If we are not operating on a particular <webview>, then the key is 0. |
int rules_registry_id = RulesRegistryService::kDefaultRulesRegistryID; |
@@ -189,6 +241,26 @@ bool EventsEventAddRulesFunction::RunAsyncOnCorrectThread() { |
return error_.empty(); |
} |
+void EventsEventAddRulesFunction::RecordUMA( |
+ const std::string& event_name) const { |
+ DeclarativeAPIFunctionType type = kDeclarativeApiFunctionCallTypeMax; |
+ switch (GetDeclarativeAPIType(event_name)) { |
+ case DeclarativeAPIType::kContent: |
+ type = kDeclarativeContentAddRules; |
+ break; |
+ case DeclarativeAPIType::kWebRequest: |
+ type = kDeclarativeWebRequestAddRules; |
+ break; |
+ case DeclarativeAPIType::kWebRequestWebview: |
+ type = kDeclarativeWebRequestWebviewAddRules; |
+ break; |
+ case DeclarativeAPIType::kUnknown: |
+ NOTREACHED(); |
+ return; |
+ } |
+ RecordUMAHelper(type); |
+} |
+ |
bool EventsEventRemoveRulesFunction::RunAsyncOnCorrectThread() { |
std::unique_ptr<RemoveRules::Params> params( |
RemoveRules::Params::Create(*args_)); |
@@ -204,6 +276,26 @@ bool EventsEventRemoveRulesFunction::RunAsyncOnCorrectThread() { |
return error_.empty(); |
} |
+void EventsEventRemoveRulesFunction::RecordUMA( |
+ const std::string& event_name) const { |
+ DeclarativeAPIFunctionType type = kDeclarativeApiFunctionCallTypeMax; |
+ switch (GetDeclarativeAPIType(event_name)) { |
+ case DeclarativeAPIType::kContent: |
+ type = kDeclarativeContentRemoveRules; |
+ break; |
+ case DeclarativeAPIType::kWebRequest: |
+ type = kDeclarativeWebRequestRemoveRules; |
+ break; |
+ case DeclarativeAPIType::kWebRequestWebview: |
+ type = kDeclarativeWebRequestWebviewRemoveRules; |
+ break; |
+ case DeclarativeAPIType::kUnknown: |
+ NOTREACHED(); |
+ return; |
+ } |
+ RecordUMAHelper(type); |
+} |
+ |
bool EventsEventGetRulesFunction::RunAsyncOnCorrectThread() { |
std::unique_ptr<GetRules::Params> params(GetRules::Params::Create(*args_)); |
EXTENSION_FUNCTION_VALIDATE(params.get()); |
@@ -224,4 +316,24 @@ bool EventsEventGetRulesFunction::RunAsyncOnCorrectThread() { |
return true; |
} |
+void EventsEventGetRulesFunction::RecordUMA( |
+ const std::string& event_name) const { |
+ DeclarativeAPIFunctionType type = kDeclarativeApiFunctionCallTypeMax; |
+ switch (GetDeclarativeAPIType(event_name)) { |
+ case DeclarativeAPIType::kContent: |
+ type = kDeclarativeContentGetRules; |
+ break; |
+ case DeclarativeAPIType::kWebRequest: |
+ type = kDeclarativeWebRequestGetRules; |
+ break; |
+ case DeclarativeAPIType::kWebRequestWebview: |
+ type = kDeclarativeWebRequestWebviewGetRules; |
+ break; |
+ case DeclarativeAPIType::kUnknown: |
+ NOTREACHED(); |
+ return; |
+ } |
+ RecordUMAHelper(type); |
+} |
+ |
} // namespace extensions |