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

Side by Side Diff: chrome/browser/chromeos/extensions/file_system_provider/provider_function.cc

Issue 2408483002: [Extensions] Convert some ChromeSyncExtensionFunctions (Closed)
Patch Set: lazyboy's Created 4 years, 2 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <utility> 5 #include <utility>
6 6
7 #include "chrome/browser/chromeos/extensions/file_system_provider/file_system_pr ovider_api.h" 7 #include "chrome/browser/chromeos/extensions/file_system_provider/file_system_pr ovider_api.h"
8 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 8 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
9 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" 9 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
10 #include "chrome/browser/chromeos/file_system_provider/request_value.h" 10 #include "chrome/browser/chromeos/file_system_provider/request_value.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 std::string FileErrorToString(base::File::Error error) { 118 std::string FileErrorToString(base::File::Error error) {
119 return extensions::api::file_system_provider::ToString( 119 return extensions::api::file_system_provider::ToString(
120 FileErrorToProviderError(error)); 120 FileErrorToProviderError(error));
121 } 121 }
122 122
123 FileSystemProviderInternalFunction::FileSystemProviderInternalFunction() 123 FileSystemProviderInternalFunction::FileSystemProviderInternalFunction()
124 : request_id_(0), request_manager_(NULL) { 124 : request_id_(0), request_manager_(NULL) {
125 } 125 }
126 126
127 bool FileSystemProviderInternalFunction::RejectRequest( 127 ExtensionFunction::ResponseAction
128 FileSystemProviderInternalFunction::RejectRequest(
128 std::unique_ptr<chromeos::file_system_provider::RequestValue> value, 129 std::unique_ptr<chromeos::file_system_provider::RequestValue> value,
129 base::File::Error error) { 130 base::File::Error error) {
130 const base::File::Error result = 131 const base::File::Error result =
131 request_manager_->RejectRequest(request_id_, std::move(value), error); 132 request_manager_->RejectRequest(request_id_, std::move(value), error);
132 if (result != base::File::FILE_OK) { 133 if (result != base::File::FILE_OK)
133 SetError(FileErrorToString(result)); 134 return RespondNow(Error(FileErrorToString(result)));
134 return false; 135 return RespondNow(NoArguments());
135 }
136
137 return true;
138 } 136 }
139 137
140 bool FileSystemProviderInternalFunction::FulfillRequest( 138 ExtensionFunction::ResponseAction
139 FileSystemProviderInternalFunction::FulfillRequest(
141 std::unique_ptr<RequestValue> value, 140 std::unique_ptr<RequestValue> value,
142 bool has_more) { 141 bool has_more) {
143 const base::File::Error result = 142 const base::File::Error result =
144 request_manager_->FulfillRequest(request_id_, std::move(value), has_more); 143 request_manager_->FulfillRequest(request_id_, std::move(value), has_more);
145 if (result != base::File::FILE_OK) { 144 if (result != base::File::FILE_OK)
146 SetError(FileErrorToString(result)); 145 return RespondNow(Error(FileErrorToString(result)));
147 return false; 146 return RespondNow(NoArguments());
148 }
149
150 return true;
151 } 147 }
152 148
153 bool FileSystemProviderInternalFunction::RunSync() { 149 bool FileSystemProviderInternalFunction::PreRunValidation(std::string* error) {
154 DCHECK(args_);
155 if (!Parse())
156 return false;
157
158 return RunWhenValid();
159 }
160
161 bool FileSystemProviderInternalFunction::Parse() {
162 std::string file_system_id; 150 std::string file_system_id;
163 151
164 if (!args_->GetString(0, &file_system_id) || 152 EXTENSION_FUNCTION_PRERUN_VALIDATE(args_->GetString(0, &file_system_id));
165 !args_->GetInteger(1, &request_id_)) { 153 EXTENSION_FUNCTION_PRERUN_VALIDATE(args_->GetInteger(1, &request_id_));
166 set_bad_message(true);
167 return false;
168 }
169 154
170 Service* service = Service::Get(GetProfile()); 155 Service* service = Service::Get(browser_context());
171 if (!service) { 156 if (!service) {
157 *error = "File system provider service not found.";
172 return false; 158 return false;
173 } 159 }
174 160
175 ProvidedFileSystemInterface* file_system = 161 ProvidedFileSystemInterface* file_system =
176 service->GetProvidedFileSystem(extension_id(), file_system_id); 162 service->GetProvidedFileSystem(extension_id(), file_system_id);
177 if (!file_system) { 163 if (!file_system) {
178 SetError(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND)); 164 *error = FileErrorToString(base::File::FILE_ERROR_NOT_FOUND);
179 return false; 165 return false;
180 } 166 }
181 167
182 request_manager_ = file_system->GetRequestManager(); 168 request_manager_ = file_system->GetRequestManager();
183 return true; 169 return true;
184 } 170 }
185 171
186 } // namespace extensions 172 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698