1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/file_system_provider/operations/get_actions.h"
10 #include "chrome/common/extensions/api/file_system_provider.h"
11 #include "chrome/common/extensions/api/file_system_provider_internal.h"
14 namespace file_system_provider
{
15 namespace operations
{
18 // Convert the request |value| into a list of actions.
19 Actions
ConvertRequestValueToActions(scoped_ptr
<RequestValue
> value
) {
20 using extensions::api::file_system_provider_internal::
21 GetActionsRequestedSuccess::Params
;
23 const Params
* params
= value
->get_actions_success_params();
27 for (const auto& idl_action
: params
->actions
) {
29 action
.id
= idl_action
->id
;
30 action
.title
= idl_action
->title
.get() ? *idl_action
->title
: std::string();
31 result
.push_back(action
);
39 GetActions::GetActions(
40 extensions::EventRouter
* event_router
,
41 const ProvidedFileSystemInfo
& file_system_info
,
42 const base::FilePath
& entry_path
,
43 const ProvidedFileSystemInterface::GetActionsCallback
& callback
)
44 : Operation(event_router
, file_system_info
),
45 entry_path_(entry_path
),
49 GetActions::~GetActions() {
52 bool GetActions::Execute(int request_id
) {
53 using extensions::api::file_system_provider::GetActionsRequestedOptions
;
55 GetActionsRequestedOptions options
;
56 options
.file_system_id
= file_system_info_
.file_system_id();
57 options
.request_id
= request_id
;
58 options
.entry_path
= entry_path_
.AsUTF8Unsafe();
62 extensions::events::FILE_SYSTEM_PROVIDER_ON_GET_ACTIONS_REQUESTED
,
63 extensions::api::file_system_provider::OnGetActionsRequested::kEventName
,
64 extensions::api::file_system_provider::OnGetActionsRequested::Create(
68 void GetActions::OnSuccess(int /* request_id */,
69 scoped_ptr
<RequestValue
> result
,
71 callback_
.Run(ConvertRequestValueToActions(result
.Pass()),
75 void GetActions::OnError(int /* request_id */,
76 scoped_ptr
<RequestValue
> /* result */,
77 base::File::Error error
) {
78 callback_
.Run(Actions(), error
);
81 } // namespace operations
82 } // namespace file_system_provider
83 } // namespace chromeos