BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / get_actions.cc
blob0f33b271a4cc3a5b5ddb6f43710857addf80ec07
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"
7 #include <algorithm>
8 #include <string>
10 #include "chrome/common/extensions/api/file_system_provider.h"
11 #include "chrome/common/extensions/api/file_system_provider_internal.h"
13 namespace chromeos {
14 namespace file_system_provider {
15 namespace operations {
16 namespace {
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();
24 DCHECK(params);
26 Actions result;
27 for (const auto& idl_action : params->actions) {
28 Action action;
29 action.id = idl_action->id;
30 action.title = idl_action->title.get() ? *idl_action->title : std::string();
31 result.push_back(action);
34 return result;
37 } // namespace
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),
46 callback_(callback) {
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();
60 return SendEvent(
61 request_id,
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(
65 options));
68 void GetActions::OnSuccess(int /* request_id */,
69 scoped_ptr<RequestValue> result,
70 bool has_more) {
71 callback_.Run(ConvertRequestValueToActions(result.Pass()),
72 base::File::FILE_OK);
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