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

Unified Diff: chrome/browser/speech/speech_input_extension_manager.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/speech/speech_input_extension_manager.cc
diff --git a/chrome/browser/speech/speech_input_extension_manager.cc b/chrome/browser/speech/speech_input_extension_manager.cc
index 93c4a80a184c7d1d9b6e6a78846066eaef20e59b..fba7b9e0edf907fb7e4c94a0be658023607c1a9d 100644
--- a/chrome/browser/speech/speech_input_extension_manager.cc
+++ b/chrome/browser/speech/speech_input_extension_manager.cc
@@ -283,9 +283,9 @@ void SpeechInputExtensionManager::SetRecognitionResultOnUIThread(
const std::string& extension_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- ListValue args;
+ ListValue* args = new ListValue();
DictionaryValue* js_event = new DictionaryValue();
- args.Append(js_event);
+ args->Append(js_event);
ListValue* js_hypothesis_array = new ListValue();
js_event->Set(kHypothesesKey, js_hypothesis_array);
@@ -302,10 +302,7 @@ void SpeechInputExtensionManager::SetRecognitionResultOnUIThread(
hypothesis.confidence);
}
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- VLOG(1) << "Results: " << json_args;
- DispatchEventToExtension(extension_id, kOnResultEvent, json_args);
+ DispatchEventToExtension(extension_id, kOnResultEvent, args);
}
void SpeechInputExtensionManager::OnRecognitionStart(int session_id) {
@@ -433,27 +430,25 @@ void SpeechInputExtensionManager::OnSoundStart(int session_id) {
DCHECK_EQ(session_id, speech_recognition_session_id_);
VLOG(1) << "OnSoundStart";
- std::string json_args;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&SpeechInputExtensionManager::DispatchEventToExtension,
this, extension_id_in_use_, std::string(kOnSoundStartEvent),
- json_args));
+ new ListValue()));
miket_OOO 2012/07/10 22:33:19 Would NULL work here? (I honestly don't know, but
}
void SpeechInputExtensionManager::OnSoundEnd(int session_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
VLOG(1) << "OnSoundEnd";
- std::string json_args;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&SpeechInputExtensionManager::DispatchEventToExtension,
this, extension_id_in_use_, std::string(kOnSoundEndEvent),
- json_args));
+ new ListValue()));
}
void SpeechInputExtensionManager::DispatchEventToExtension(
const std::string& extension_id, const std::string& event,
- const std::string& json_args) {
+ ListValue* event_args) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::AutoLock auto_lock(state_lock_);
@@ -461,16 +456,8 @@ void SpeechInputExtensionManager::DispatchEventToExtension(
return;
if (profile_ && profile_->GetExtensionEventRouter()) {
- std::string final_args;
- if (json_args.empty()) {
- ListValue args;
- base::JSONWriter::Write(&args, &final_args);
- } else {
- final_args = json_args;
- }
-
profile_->GetExtensionEventRouter()->DispatchEventToExtension(
- extension_id, event, final_args, profile_, GURL());
+ extension_id, event, event_args, profile_, GURL());
}
}
@@ -497,14 +484,11 @@ void SpeechInputExtensionManager::DispatchError(
// Used for errors that are also reported via the onError event.
if (dispatch_event) {
- ListValue args;
+ ListValue* args = new ListValue();
DictionaryValue* js_error = new DictionaryValue();
- args.Append(js_error);
+ args->Append(js_error);
js_error->SetString(kErrorCodeKey, error);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- DispatchEventToExtension(extension_id,
- kOnErrorEvent, json_args);
+ DispatchEventToExtension(extension_id, kOnErrorEvent, args);
}
}

Powered by Google App Engine
This is Rietveld 408576698