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

Unified Diff: extensions/browser/api/app_runtime/app_runtime_api.cc

Issue 657023008: Add a new field "source" in launchData of chrome.app.runtime.onLaunched() to trace launch source. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/api/app_runtime/app_runtime_api.h ('k') | extensions/common/api/app_runtime.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/api/app_runtime/app_runtime_api.cc
diff --git a/extensions/browser/api/app_runtime/app_runtime_api.cc b/extensions/browser/api/app_runtime/app_runtime_api.cc
index 0704478dbeac084aa2b03cad4219f9a95a06c2a7..8712c4b356b0efa1a357da45562e89d06632f9e0 100644
--- a/extensions/browser/api/app_runtime/app_runtime_api.cc
+++ b/extensions/browser/api/app_runtime/app_runtime_api.cc
@@ -4,6 +4,7 @@
#include "extensions/browser/api/app_runtime/app_runtime_api.h"
+#include "base/metrics/histogram.h"
#include "base/time/time.h"
#include "base/values.h"
#include "extensions/browser/event_router.h"
@@ -12,6 +13,8 @@
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/granted_file_entry.h"
#include "extensions/common/api/app_runtime.h"
+#include "extensions/common/constants.h"
+#include "extensions/common/feature_switch.h"
#include "url/gurl.h"
using content::BrowserContext;
@@ -57,6 +60,43 @@ void DispatchOnLaunchedEventImpl(const std::string& extension_id,
->SetLastLaunchTime(extension_id, base::Time::Now());
}
+app_runtime::LaunchSource getLaunchSourceEnum(
+ extensions::AppLaunchSource source) {
+ switch (source) {
+ case extensions::SOURCE_APP_LAUNCHER:
+ return app_runtime::LAUNCH_SOURCE_APP_LAUNCHER;
+ case extensions::SOURCE_NEW_TAB_PAGE:
+ return app_runtime::LAUNCH_SOURCE_NEW_TAB_PAGE;
+ case extensions::SOURCE_RELOAD:
+ return app_runtime::LAUNCH_SOURCE_RELOAD;
+ case extensions::SOURCE_RESTART:
+ return app_runtime::LAUNCH_SOURCE_RESTART;
+ case extensions::SOURCE_LOAD_AND_LAUNCH:
+ return app_runtime::LAUNCH_SOURCE_LOAD_AND_LAUNCH;
+ case extensions::SOURCE_COMMAND_LINE:
+ return app_runtime::LAUNCH_SOURCE_COMMAND_LINE;
+ case extensions::SOURCE_FILE_HANDLER:
+ return app_runtime::LAUNCH_SOURCE_FILE_HANDLER;
+ case extensions::SOURCE_URL_HANDLER:
+ return app_runtime::LAUNCH_SOURCE_URL_HANDLER;
+
+ case extensions::SOURCE_SYSTEM_TRAY:
+ return app_runtime::LAUNCH_SOURCE_SYSTEM_TRAY;
+ case extensions::SOURCE_ABOUT_PAGE:
+ return app_runtime::LAUNCH_SOURCE_ABOUT_PAGE;
+ case extensions::SOURCE_KEYBOARD:
+ return app_runtime::LAUNCH_SOURCE_KEYBOARD;
+
+ default:
+ return app_runtime::LAUNCH_SOURCE_NONE;
+ }
+}
+
+void ReportMetrics(app_runtime::LaunchSource source) {
+ UMA_HISTOGRAM_ENUMERATION(
+ "Extensions.AppLaunchSource", source, NUM_APP_LAUNCH_SOURCES);
+}
+
} // namespace
// static
@@ -71,9 +111,15 @@ void AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent(
// static
void AppRuntimeEventRouter::DispatchOnLaunchedEvent(
BrowserContext* context,
- const Extension* extension) {
- scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue());
- DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context);
+ const Extension* extension,
+ extensions::AppLaunchSource source) {
+ app_runtime::LaunchData launch_data;
+ if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) {
+ launch_data.source = getLaunchSourceEnum(source);
+ ReportMetrics(launch_data.source);
+ }
+ DispatchOnLaunchedEventImpl(
+ extension->id(), launch_data.ToValue().Pass(), context);
}
// static
@@ -97,20 +143,34 @@ void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries(
const std::vector<GrantedFileEntry>& file_entries) {
// TODO(sergeygs): Use the same way of creating an event (using the generated
// boilerplate) as below in DispatchOnLaunchedEventWithUrl.
- scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue);
+ base::DictionaryValue* launch_data = new base::DictionaryValue();
launch_data->SetString("id", handler_id);
- scoped_ptr<base::ListValue> items(new base::ListValue);
+
+ if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) {
+ launch_data->SetString(
+ "source",
+ app_runtime::ToString(app_runtime::LAUNCH_SOURCE_FILE_HANDLER));
+ ReportMetrics(app_runtime::LAUNCH_SOURCE_FILE_HANDLER);
+ }
+
+ base::ListValue* items = new base::ListValue();
DCHECK(file_entries.size() == mime_types.size());
for (size_t i = 0; i < file_entries.size(); ++i) {
- scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue);
- launch_item->SetString("fileSystemId", file_entries[i].filesystem_id);
- launch_item->SetString("baseName", file_entries[i].registered_name);
- launch_item->SetString("mimeType", mime_types[i]);
- launch_item->SetString("entryId", file_entries[i].id);
- items->Append(launch_item.release());
+ base::DictionaryValue* launch_item = new base::DictionaryValue();
+
+ base::DictionaryValue* raw_entry = new base::DictionaryValue();
+ raw_entry->SetString("fileSystemId", file_entries[i].filesystem_id);
+ raw_entry->SetString("baseName", file_entries[i].registered_name);
+ raw_entry->SetString("entryId", file_entries[i].id);
+
+ launch_item->Set("rawEntry", raw_entry);
+ launch_item->SetString("type", mime_types[i]);
+
+ items->Append(launch_item);
}
- launch_data->Set("items", items.release());
- DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context);
+ launch_data->Set("items", items);
+ DispatchOnLaunchedEventImpl(
+ extension->id(), scoped_ptr<base::DictionaryValue>(launch_data), context);
}
// static
@@ -124,6 +184,10 @@ void AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl(
launch_data.id.reset(new std::string(handler_id));
launch_data.url.reset(new std::string(url.spec()));
launch_data.referrer_url.reset(new std::string(referrer_url.spec()));
+ if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) {
+ launch_data.source = app_runtime::LAUNCH_SOURCE_URL_HANDLER;
+ ReportMetrics(app_runtime::LAUNCH_SOURCE_URL_HANDLER);
+ }
DispatchOnLaunchedEventImpl(
extension->id(), launch_data.ToValue().Pass(), context);
}
« no previous file with comments | « extensions/browser/api/app_runtime/app_runtime_api.h ('k') | extensions/common/api/app_runtime.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698