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..e0d1c6db5ada55fe7f50e84c7d4956d374dd4d09 100644 |
--- a/extensions/browser/api/app_runtime/app_runtime_api.cc |
+++ b/extensions/browser/api/app_runtime/app_runtime_api.cc |
@@ -12,6 +12,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 +59,34 @@ 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_RESTART: |
+ return app_runtime::LAUNCH_SOURCE_RESTART; |
+ case extensions::SOURCE_RELOAD: |
+ return app_runtime::LAUNCH_SOURCE_RELOAD; |
+ 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_GETHELP_SYSTEM_TRAY: |
+ return app_runtime::LAUNCH_SOURCE_GETHELP_SYSTEM_TRAY; |
+ case extensions::SOURCE_GETHELP_ABOUT_PAGE: |
+ return app_runtime::LAUNCH_SOURCE_GETHELP_ABOUT_PAGE; |
+ case extensions::SOURCE_GETHELP_KEYBOARD: |
+ return app_runtime::LAUNCH_SOURCE_GETHELP_KEYBOARD; |
+ |
+ default: |
+ return app_runtime::LAUNCH_SOURCE_NONE; |
+ } |
+} |
+ |
} // namespace |
// static |
@@ -77,6 +107,19 @@ void AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
} |
// static |
+void AppRuntimeEventRouter::DispatchOnLaunchedEventWithSource( |
+ BrowserContext* context, |
+ const Extension* extension, |
+ extensions::AppLaunchSource source) { |
+ app_runtime::LaunchData launch_data; |
+ if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
+ launch_data.source = getLaunchSourceEnum(source); |
+ } |
+ DispatchOnLaunchedEventImpl( |
+ extension->id(), launch_data.ToValue().Pass(), context); |
+} |
+ |
+// static |
void AppRuntimeEventRouter::DispatchOnRestartedEvent( |
BrowserContext* context, |
const Extension* extension) { |
@@ -97,20 +140,31 @@ 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); |
+ launch_data->SetString( |
+ "source", app_runtime::ToString(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).Pass(), |
+ context); |
} |
// static |
@@ -124,6 +178,9 @@ 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; |
+ } |
DispatchOnLaunchedEventImpl( |
extension->id(), launch_data.ToValue().Pass(), context); |
} |