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

Side by Side Diff: chrome/browser/speech/extension_api/tts_engine_extension_api.cc

Issue 2236703002: [Extensions] Convert some SyncExtensionFunctions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nulltpr Created 4 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/speech/extension_api/tts_engine_extension_api.h" 5 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 extensions::ExtensionSystem::Get(profile)->extension_service(); 256 extensions::ExtensionSystem::Get(profile)->extension_service();
257 DCHECK(extension_service); 257 DCHECK(extension_service);
258 extension_service->component_loader() 258 extension_service->component_loader()
259 ->AddChromeOsSpeechSynthesisExtension(); 259 ->AddChromeOsSpeechSynthesisExtension();
260 return true; 260 return true;
261 #else 261 #else
262 return false; 262 return false;
263 #endif 263 #endif
264 } 264 }
265 265
266 bool ExtensionTtsEngineSendTtsEventFunction::RunSync() { 266 ExtensionFunction::ResponseAction
267 int utterance_id; 267 ExtensionTtsEngineSendTtsEventFunction::Run() {
268 int utterance_id = 0;
268 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &utterance_id)); 269 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &utterance_id));
269 270
270 base::DictionaryValue* event; 271 base::DictionaryValue* event = nullptr;
271 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &event)); 272 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &event));
272 273
273 std::string event_type; 274 std::string event_type;
274 EXTENSION_FUNCTION_VALIDATE( 275 EXTENSION_FUNCTION_VALIDATE(
275 event->GetString(constants::kEventTypeKey, &event_type)); 276 event->GetString(constants::kEventTypeKey, &event_type));
276 277
277 int char_index = 0; 278 int char_index = 0;
278 if (event->HasKey(constants::kCharIndexKey)) { 279 if (event->HasKey(constants::kCharIndexKey)) {
279 EXTENSION_FUNCTION_VALIDATE( 280 EXTENSION_FUNCTION_VALIDATE(
280 event->GetInteger(constants::kCharIndexKey, &char_index)); 281 event->GetInteger(constants::kCharIndexKey, &char_index));
281 } 282 }
282 283
283 // Make sure the extension has included this event type in its manifest. 284 // Make sure the extension has included this event type in its manifest.
284 bool event_type_allowed = false; 285 bool event_type_allowed = false;
285 const std::vector<extensions::TtsVoice>* tts_voices = 286 const std::vector<extensions::TtsVoice>* tts_voices =
286 extensions::TtsVoice::GetTtsVoices(extension()); 287 extensions::TtsVoice::GetTtsVoices(extension());
287 if (!tts_voices) { 288 if (!tts_voices)
288 error_ = constants::kErrorUndeclaredEventType; 289 return RespondNow(Error(constants::kErrorUndeclaredEventType));
289 return false;
290 }
291 290
292 for (size_t i = 0; i < tts_voices->size(); i++) { 291 for (size_t i = 0; i < tts_voices->size(); i++) {
293 const extensions::TtsVoice& voice = tts_voices->at(i); 292 const extensions::TtsVoice& voice = tts_voices->at(i);
294 if (voice.event_types.find(event_type) != voice.event_types.end()) { 293 if (voice.event_types.find(event_type) != voice.event_types.end()) {
295 event_type_allowed = true; 294 event_type_allowed = true;
296 break; 295 break;
297 } 296 }
298 } 297 }
299 if (!event_type_allowed) { 298 if (!event_type_allowed)
300 error_ = constants::kErrorUndeclaredEventType; 299 return RespondNow(Error(constants::kErrorUndeclaredEventType));
301 return false;
302 }
303 300
304 TtsController* controller = TtsController::GetInstance(); 301 TtsController* controller = TtsController::GetInstance();
305 if (event_type == constants::kEventTypeStart) { 302 if (event_type == constants::kEventTypeStart) {
306 controller->OnTtsEvent( 303 controller->OnTtsEvent(
307 utterance_id, TTS_EVENT_START, char_index, std::string()); 304 utterance_id, TTS_EVENT_START, char_index, std::string());
308 } else if (event_type == constants::kEventTypeEnd) { 305 } else if (event_type == constants::kEventTypeEnd) {
309 controller->OnTtsEvent( 306 controller->OnTtsEvent(
310 utterance_id, TTS_EVENT_END, char_index, std::string()); 307 utterance_id, TTS_EVENT_END, char_index, std::string());
311 } else if (event_type == constants::kEventTypeWord) { 308 } else if (event_type == constants::kEventTypeWord) {
312 controller->OnTtsEvent( 309 controller->OnTtsEvent(
(...skipping 12 matching lines...) Expand all
325 } else if (event_type == constants::kEventTypePause) { 322 } else if (event_type == constants::kEventTypePause) {
326 controller->OnTtsEvent( 323 controller->OnTtsEvent(
327 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); 324 utterance_id, TTS_EVENT_PAUSE, char_index, std::string());
328 } else if (event_type == constants::kEventTypeResume) { 325 } else if (event_type == constants::kEventTypeResume) {
329 controller->OnTtsEvent( 326 controller->OnTtsEvent(
330 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); 327 utterance_id, TTS_EVENT_RESUME, char_index, std::string());
331 } else { 328 } else {
332 EXTENSION_FUNCTION_VALIDATE(false); 329 EXTENSION_FUNCTION_VALIDATE(false);
333 } 330 }
334 331
335 return true; 332 return RespondNow(NoArguments());
336 } 333 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698