Chromium Code Reviews| 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 2b225df2f2f35628f5559423d10840d59fafbd0b..91a12b77b22f85f3a8f550257d67f46fdafd1182 100644 |
| --- a/extensions/browser/api/app_runtime/app_runtime_api.cc |
| +++ b/extensions/browser/api/app_runtime/app_runtime_api.cc |
| @@ -8,6 +8,7 @@ |
| #include <utility> |
| +#include "base/memory/ptr_util.h" |
| #include "base/metrics/histogram.h" |
| #include "base/time/time.h" |
| #include "base/values.h" |
| @@ -29,6 +30,25 @@ namespace app_runtime = api::app_runtime; |
| namespace { |
| +// Converts an ActionType instance to an app_runtime::ActionType instance. |
| +app_runtime::ActionType MapActionType(ActionType action_type) { |
| + switch (action_type) { |
| + case ActionType::NEW_NOTE: |
| + return app_runtime::ActionType::ACTION_TYPE_NEW_NOTE; |
| + } |
| + |
| + NOTREACHED(); |
|
Daniel Erat
2016/08/11 20:37:06
nit: also log the bad type, e.g.
NOTREACHED() <
jdufault
2016/08/12 18:56:55
Done, but I had to add a cast since action_type is
|
| + return app_runtime::ActionType::ACTION_TYPE_NONE; |
|
Daniel Erat
2016/08/11 20:37:06
random question: does this _NONE enum value get au
Devlin
2016/08/11 20:51:21
Yep.
|
| +} |
| + |
| +// Converts an ActionData instance to an app_runtime::ActionData instance. |
| +std::unique_ptr<app_runtime::ActionData> BuildActionData( |
| + ActionData action_data) { |
| + auto data = base::WrapUnique(new app_runtime::ActionData()); |
| + data->action_type = MapActionType(action_data.action_type); |
| + return data; |
| +} |
| + |
| void DispatchOnEmbedRequestedEventImpl( |
| const std::string& extension_id, |
| std::unique_ptr<base::DictionaryValue> app_embedding_request_data, |
| @@ -137,13 +157,18 @@ void AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( |
| void AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| BrowserContext* context, |
| const Extension* extension, |
| - extensions::AppLaunchSource source) { |
| + extensions::AppLaunchSource source, |
| + base::Optional<ActionData> action_data) { |
| app_runtime::LaunchData launch_data; |
| app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source); |
| if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
| launch_data.source = source_enum; |
| } |
| + |
| + if (action_data) |
| + launch_data.action_data = BuildActionData(action_data.value()); |
| + |
| DispatchOnLaunchedEventImpl(extension->id(), source_enum, |
| launch_data.ToValue(), context); |
| } |
| @@ -165,20 +190,27 @@ void AppRuntimeEventRouter::DispatchOnRestartedEvent( |
| void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( |
| BrowserContext* context, |
| const Extension* extension, |
| + extensions::AppLaunchSource source, |
| const std::string& handler_id, |
| const std::vector<EntryInfo>& entries, |
| - const std::vector<GrantedFileEntry>& file_entries) { |
| + const std::vector<GrantedFileEntry>& file_entries, |
| + base::Optional<ActionData> action_data) { |
| + app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source); |
|
Devlin
2016/08/11 20:51:21
getLaunchSourceEnum -> GetLaunchSourceEnum
I know
jdufault
2016/08/12 18:56:55
Done.
|
| + |
| // TODO(sergeygs): Use the same way of creating an event (using the generated |
| // boilerplate) as below in DispatchOnLaunchedEventWithUrl. |
| std::unique_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); |
| launch_data->SetString("id", handler_id); |
| - app_runtime::LaunchSource source_enum = |
| - app_runtime::LAUNCH_SOURCE_FILE_HANDLER; |
| if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
|
Daniel Erat
2016/08/11 20:37:06
nit: move this up just below the line that initial
jdufault
2016/08/12 18:56:55
source_enum is used below as well (DispatchOnLaunc
|
| launch_data->SetString("source", app_runtime::ToString(source_enum)); |
| } |
| + if (action_data) { |
| + launch_data->Set("action_data", |
|
Devlin
2016/08/11 20:51:21
this should be actionData.
If we used app_runtime
jdufault
2016/08/12 18:56:55
Done.
Devlin
2016/08/16 00:20:09
We should document the fields of the launch item,
jdufault
2016/08/16 21:30:57
Done.
|
| + BuildActionData(action_data.value())->ToValue()); |
| + } |
| + |
| std::unique_ptr<base::ListValue> items(new base::ListValue); |
| DCHECK(file_entries.size() == entries.size()); |
| for (size_t i = 0; i < file_entries.size(); ++i) { |