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

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

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and review changes. Created 8 years, 5 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 | Annotate | Revision Log
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_extension_api_controller.h" 5 #include "chrome/browser/speech/extension_api/tts_extension_api_controller.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/float_util.h" 10 #include "base/float_util.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 if (desired_event_types_.size() > 0 && 102 if (desired_event_types_.size() > 0 &&
103 desired_event_types_.find(event_type_string) == 103 desired_event_types_.find(event_type_string) ==
104 desired_event_types_.end()) { 104 desired_event_types_.end()) {
105 return; 105 return;
106 } 106 }
107 107
108 if (src_id_ < 0) 108 if (src_id_ < 0)
109 return; 109 return;
110 110
111 ListValue args;
112 DictionaryValue* event = new DictionaryValue(); 111 DictionaryValue* event = new DictionaryValue();
113 if (char_index != kInvalidCharIndex) 112 if (char_index != kInvalidCharIndex)
114 event->SetInteger(constants::kCharIndexKey, char_index); 113 event->SetInteger(constants::kCharIndexKey, char_index);
115 event->SetString(constants::kEventTypeKey, event_type_string); 114 event->SetString(constants::kEventTypeKey, event_type_string);
116 if (event_type == TTS_EVENT_ERROR) { 115 if (event_type == TTS_EVENT_ERROR) {
117 event->SetString(constants::kErrorMessageKey, error_message); 116 event->SetString(constants::kErrorMessageKey, error_message);
118 } 117 }
119 event->SetInteger(constants::kSrcIdKey, src_id_); 118 event->SetInteger(constants::kSrcIdKey, src_id_);
120 event->SetBoolean(constants::kIsFinalEventKey, finished_); 119 event->SetBoolean(constants::kIsFinalEventKey, finished_);
121 args.Set(0, event); 120
122 std::string json_args; 121 ListValue* arguments = new ListValue();
123 base::JSONWriter::Write(&args, &json_args); 122 arguments->Set(0, event);
124 123
125 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 124 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
126 src_extension_id_, 125 src_extension_id_,
127 events::kOnEvent, 126 events::kOnEvent,
128 json_args, 127 arguments,
129 profile_, 128 profile_,
130 src_url_); 129 src_url_);
131 } 130 }
132 131
133 void Utterance::Finish() { 132 void Utterance::Finish() {
134 finished_ = true; 133 finished_ = true;
135 } 134 }
136 135
137 void Utterance::set_options(const Value* options) { 136 void Utterance::set_options(const Value* options) {
138 options_.reset(options->DeepCopy()); 137 options_.reset(options->DeepCopy());
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 326
328 int ExtensionTtsController::QueueSize() { 327 int ExtensionTtsController::QueueSize() {
329 return static_cast<int>(utterance_queue_.size()); 328 return static_cast<int>(utterance_queue_.size());
330 } 329 }
331 330
332 ExtensionTtsPlatformImpl* ExtensionTtsController::GetPlatformImpl() { 331 ExtensionTtsPlatformImpl* ExtensionTtsController::GetPlatformImpl() {
333 if (!platform_impl_) 332 if (!platform_impl_)
334 platform_impl_ = ExtensionTtsPlatformImpl::GetInstance(); 333 platform_impl_ = ExtensionTtsPlatformImpl::GetInstance();
335 return platform_impl_; 334 return platform_impl_;
336 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698