ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_system_provider / provider_function.cc
blob3ad1db8c16845d52fcde49e76d458a70ea4905ec
1 // Copyright 2014 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/extensions/file_system_provider/file_system_provider_api.h"
7 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
8 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
9 #include "chrome/browser/chromeos/file_system_provider/request_value.h"
10 #include "chrome/browser/chromeos/file_system_provider/service.h"
11 #include "chrome/common/extensions/api/file_system_provider_internal.h"
13 using chromeos::file_system_provider::ProvidedFileSystemInterface;
14 using chromeos::file_system_provider::RequestManager;
15 using chromeos::file_system_provider::RequestValue;
16 using chromeos::file_system_provider::Service;
18 namespace {
20 // Converts a base::File::Error into the IDL error format.
21 extensions::api::file_system_provider::ProviderError FileErrorToProviderError(
22 base::File::Error error) {
23 switch (error) {
24 case base::File::FILE_OK:
25 return extensions::api::file_system_provider::PROVIDER_ERROR_OK;
26 case base::File::FILE_ERROR_FAILED:
27 return extensions::api::file_system_provider::PROVIDER_ERROR_FAILED;
28 case base::File::FILE_ERROR_IN_USE:
29 return extensions::api::file_system_provider::PROVIDER_ERROR_IN_USE;
30 case base::File::FILE_ERROR_EXISTS:
31 return extensions::api::file_system_provider::PROVIDER_ERROR_EXISTS;
32 case base::File::FILE_ERROR_NOT_FOUND:
33 return extensions::api::file_system_provider::PROVIDER_ERROR_NOT_FOUND;
34 case base::File::FILE_ERROR_ACCESS_DENIED:
35 return extensions::api::file_system_provider::
36 PROVIDER_ERROR_ACCESS_DENIED;
37 case base::File::FILE_ERROR_TOO_MANY_OPENED:
38 return extensions::api::file_system_provider::
39 PROVIDER_ERROR_TOO_MANY_OPENED;
40 case base::File::FILE_ERROR_NO_MEMORY:
41 return extensions::api::file_system_provider::PROVIDER_ERROR_NO_MEMORY;
42 case base::File::FILE_ERROR_NO_SPACE:
43 return extensions::api::file_system_provider::PROVIDER_ERROR_NO_SPACE;
44 case base::File::FILE_ERROR_NOT_A_DIRECTORY:
45 return extensions::api::file_system_provider::
46 PROVIDER_ERROR_NOT_A_DIRECTORY;
47 case base::File::FILE_ERROR_INVALID_OPERATION:
48 return extensions::api::file_system_provider::
49 PROVIDER_ERROR_INVALID_OPERATION;
50 case base::File::FILE_ERROR_SECURITY:
51 return extensions::api::file_system_provider::PROVIDER_ERROR_SECURITY;
52 case base::File::FILE_ERROR_ABORT:
53 return extensions::api::file_system_provider::PROVIDER_ERROR_ABORT;
54 case base::File::FILE_ERROR_NOT_A_FILE:
55 return extensions::api::file_system_provider::PROVIDER_ERROR_NOT_A_FILE;
56 case base::File::FILE_ERROR_NOT_EMPTY:
57 return extensions::api::file_system_provider::PROVIDER_ERROR_NOT_EMPTY;
58 case base::File::FILE_ERROR_INVALID_URL:
59 return extensions::api::file_system_provider::PROVIDER_ERROR_INVALID_URL;
60 case base::File::FILE_ERROR_IO:
61 return extensions::api::file_system_provider::PROVIDER_ERROR_IO;
62 case base::File::FILE_ERROR_MAX:
63 NOTREACHED();
66 return extensions::api::file_system_provider::PROVIDER_ERROR_FAILED;
69 } // namespace
71 namespace extensions {
73 base::File::Error ProviderErrorToFileError(
74 api::file_system_provider::ProviderError error) {
75 switch (error) {
76 case api::file_system_provider::PROVIDER_ERROR_OK:
77 return base::File::FILE_OK;
78 case api::file_system_provider::PROVIDER_ERROR_FAILED:
79 return base::File::FILE_ERROR_FAILED;
80 case api::file_system_provider::PROVIDER_ERROR_IN_USE:
81 return base::File::FILE_ERROR_IN_USE;
82 case api::file_system_provider::PROVIDER_ERROR_EXISTS:
83 return base::File::FILE_ERROR_EXISTS;
84 case api::file_system_provider::PROVIDER_ERROR_NOT_FOUND:
85 return base::File::FILE_ERROR_NOT_FOUND;
86 case api::file_system_provider::PROVIDER_ERROR_ACCESS_DENIED:
87 return base::File::FILE_ERROR_ACCESS_DENIED;
88 case api::file_system_provider::PROVIDER_ERROR_TOO_MANY_OPENED:
89 return base::File::FILE_ERROR_TOO_MANY_OPENED;
90 case api::file_system_provider::PROVIDER_ERROR_NO_MEMORY:
91 return base::File::FILE_ERROR_NO_MEMORY;
92 case api::file_system_provider::PROVIDER_ERROR_NO_SPACE:
93 return base::File::FILE_ERROR_NO_SPACE;
94 case api::file_system_provider::PROVIDER_ERROR_NOT_A_DIRECTORY:
95 return base::File::FILE_ERROR_NOT_A_DIRECTORY;
96 case api::file_system_provider::PROVIDER_ERROR_INVALID_OPERATION:
97 return base::File::FILE_ERROR_INVALID_OPERATION;
98 case api::file_system_provider::PROVIDER_ERROR_SECURITY:
99 return base::File::FILE_ERROR_SECURITY;
100 case api::file_system_provider::PROVIDER_ERROR_ABORT:
101 return base::File::FILE_ERROR_ABORT;
102 case api::file_system_provider::PROVIDER_ERROR_NOT_A_FILE:
103 return base::File::FILE_ERROR_NOT_A_FILE;
104 case api::file_system_provider::PROVIDER_ERROR_NOT_EMPTY:
105 return base::File::FILE_ERROR_NOT_EMPTY;
106 case api::file_system_provider::PROVIDER_ERROR_INVALID_URL:
107 return base::File::FILE_ERROR_INVALID_URL;
108 case api::file_system_provider::PROVIDER_ERROR_IO:
109 return base::File::FILE_ERROR_IO;
110 case api::file_system_provider::PROVIDER_ERROR_NONE:
111 NOTREACHED();
114 return base::File::FILE_ERROR_FAILED;
117 std::string FileErrorToString(base::File::Error error) {
118 return extensions::api::file_system_provider::ToString(
119 FileErrorToProviderError(error));
122 FileSystemProviderInternalFunction::FileSystemProviderInternalFunction()
123 : request_id_(0), request_manager_(NULL) {
126 bool FileSystemProviderInternalFunction::RejectRequest(
127 scoped_ptr<chromeos::file_system_provider::RequestValue> value,
128 base::File::Error error) {
129 const base::File::Error result =
130 request_manager_->RejectRequest(request_id_, value.Pass(), error);
131 if (result != base::File::FILE_OK) {
132 SetError(FileErrorToString(result));
133 return false;
136 return true;
139 bool FileSystemProviderInternalFunction::FulfillRequest(
140 scoped_ptr<RequestValue> value,
141 bool has_more) {
142 const base::File::Error result =
143 request_manager_->FulfillRequest(request_id_, value.Pass(), has_more);
144 if (result != base::File::FILE_OK) {
145 SetError(FileErrorToString(result));
146 return false;
149 return true;
152 bool FileSystemProviderInternalFunction::RunSync() {
153 DCHECK(args_);
154 if (!Parse())
155 return false;
157 return RunWhenValid();
160 bool FileSystemProviderInternalFunction::Parse() {
161 std::string file_system_id;
163 if (!args_->GetString(0, &file_system_id) ||
164 !args_->GetInteger(1, &request_id_)) {
165 bad_message_ = true;
166 return false;
169 Service* service = Service::Get(GetProfile());
170 if (!service) {
171 return false;
174 ProvidedFileSystemInterface* file_system =
175 service->GetProvidedFileSystem(extension_id(), file_system_id);
176 if (!file_system) {
177 SetError(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND));
178 return false;
181 request_manager_ = file_system->GetRequestManager();
182 return true;
185 } // namespace extensions