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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/get_actions.cc

Issue 1151763007: Add the boilerplate for actions to File System Provider API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased + fixed a comment. Created 5 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/chromeos/file_system_provider/operations/get_actions.h"
6
7 #include <algorithm>
8 #include <string>
9
10 #include "chrome/common/extensions/api/file_system_provider.h"
11 #include "chrome/common/extensions/api/file_system_provider_internal.h"
12
13 namespace chromeos {
14 namespace file_system_provider {
15 namespace operations {
16 namespace {
17
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;
22
23 const Params* params = value->get_actions_success_params();
24 DCHECK(params);
25
26 Actions result;
27
28 for (const auto& idl_action : params->actions) {
29 Action action;
30 action.id = idl_action->id;
31 switch (idl_action->type) {
32 case extensions::api::file_system_provider::ACTION_TYPE_SHARE:
33 action.type = ACTION_TYPE_SHARE;
34 break;
35 case extensions::api::file_system_provider::ACTION_TYPE_PIN_TOGGLE:
36 action.type = ACTION_TYPE_PIN_TOGGLE;
37 break;
38 case extensions::api::file_system_provider::ACTION_TYPE_CUSTOM:
39 action.type = ACTION_TYPE_CUSTOM;
40 break;
41 case extensions::api::file_system_provider::ACTION_TYPE_NONE:
42 NOTREACHED();
43 }
44 action.title = idl_action->title.get() ? *idl_action->title : std::string();
45 result.push_back(action);
46 }
47
48 return result;
49 }
50
51 } // namespace
52
53 GetActions::GetActions(
54 extensions::EventRouter* event_router,
55 const ProvidedFileSystemInfo& file_system_info,
56 const base::FilePath& entry_path,
57 const ProvidedFileSystemInterface::GetActionsCallback& callback)
58 : Operation(event_router, file_system_info),
59 entry_path_(entry_path),
60 callback_(callback) {
61 }
62
63 GetActions::~GetActions() {
64 }
65
66 bool GetActions::Execute(int request_id) {
67 using extensions::api::file_system_provider::GetActionsRequestedOptions;
68
69 GetActionsRequestedOptions options;
70 options.file_system_id = file_system_info_.file_system_id();
71 options.request_id = request_id;
72 options.entry_path = entry_path_.AsUTF8Unsafe();
73
74 return SendEvent(
75 request_id,
76 extensions::api::file_system_provider::OnGetActionsRequested::kEventName,
77 extensions::api::file_system_provider::OnGetActionsRequested::Create(
78 options));
79 }
80
81 void GetActions::OnSuccess(int /* request_id */,
82 scoped_ptr<RequestValue> result,
83 bool has_more) {
84 callback_.Run(ConvertRequestValueToActions(result.Pass()),
85 base::File::FILE_OK);
86 }
87
88 void GetActions::OnError(int /* request_id */,
89 scoped_ptr<RequestValue> /* result */,
90 base::File::Error error) {
91 callback_.Run(Actions(), error);
92 }
93
94 } // namespace operations
95 } // namespace file_system_provider
96 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698