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

Unified Diff: chrome/browser/extensions/extension_processes_api.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: Build fix. 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/extensions/extension_processes_api.cc
diff --git a/chrome/browser/extensions/extension_processes_api.cc b/chrome/browser/extensions/extension_processes_api.cc
index 4607c508b3b878c55e62bbf6d2899b2184be5293..37ccb5a64c7e9e77cfb5037c2738736d9bceb9b6 100644
--- a/chrome/browser/extensions/extension_processes_api.cc
+++ b/chrome/browser/extensions/extension_processes_api.cc
@@ -311,7 +311,7 @@ void ExtensionProcessesEventRouter::OnItemsAdded(int start, int length) {
index = model_->GetGroupIndexForResource(start);
}
- ListValue args;
+ ListValue* args = new ListValue();
DictionaryValue* process = CreateProcessFromModel(
model_->GetUniqueChildProcessId(index), model_, index, false);
DCHECK(process != NULL);
@@ -319,11 +319,9 @@ void ExtensionProcessesEventRouter::OnItemsAdded(int start, int length) {
if (process == NULL)
return;
- args.Append(process);
+ args->Append(process);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- NotifyProfiles(keys::kOnCreated, json_args);
+ NotifyProfiles(keys::kOnCreated, args);
#endif // defined(ENABLE_TASK_MANAGER)
}
@@ -368,11 +366,9 @@ void ExtensionProcessesEventRouter::OnItemsChanged(int start, int length) {
processes->Set(base::IntToString(id), it.GetCurrentValue());
}
- ListValue args;
- args.Append(processes);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- NotifyProfiles(keys::kOnUpdated, json_args);
+ ListValue* args = new ListValue();
+ args->Append(processes);
+ NotifyProfiles(keys::kOnUpdated, args);
}
if (updated_memory) {
@@ -389,11 +385,9 @@ void ExtensionProcessesEventRouter::OnItemsChanged(int start, int length) {
processes->Set(base::IntToString(id), it.GetCurrentValue());
}
- ListValue args;
- args.Append(processes);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- NotifyProfiles(keys::kOnUpdatedWithMemory, json_args);
+ ListValue* args = new ListValue();
+ args->Append(processes);
+ NotifyProfiles(keys::kOnUpdatedWithMemory, args);
}
#endif // defined(ENABLE_TASK_MANAGER)
}
@@ -410,21 +404,19 @@ void ExtensionProcessesEventRouter::OnItemsToBeRemoved(int start, int length) {
return;
// The callback function parameters.
- ListValue args;
+ ListValue* args = new ListValue();
// First arg: The id of the process that was closed.
- args.Append(Value::CreateIntegerValue(
+ args->Append(Value::CreateIntegerValue(
model_->GetUniqueChildProcessId(start)));
// Second arg: The exit type for the process.
- args.Append(Value::CreateIntegerValue(0));
+ args->Append(Value::CreateIntegerValue(0));
// Third arg: The exit code for the process.
- args.Append(Value::CreateIntegerValue(0));
+ args->Append(Value::CreateIntegerValue(0));
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- NotifyProfiles(keys::kOnExited, json_args);
+ NotifyProfiles(keys::kOnExited, args);
#endif // defined(ENABLE_TASK_MANAGER)
}
@@ -452,12 +444,10 @@ void ExtensionProcessesEventRouter::ProcessHangEvent(
if (process == NULL)
return;
- ListValue args;
- args.Append(process);
+ ListValue* args = new ListValue();
+ args->Append(process);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- NotifyProfiles(keys::kOnUnresponsive, json_args);
+ NotifyProfiles(keys::kOnUnresponsive, args);
#endif // defined(ENABLE_TASK_MANAGER)
}
@@ -466,39 +456,38 @@ void ExtensionProcessesEventRouter::ProcessClosedEvent(
content::RenderProcessHost::RendererClosedDetails* details) {
#if defined(ENABLE_TASK_MANAGER)
// The callback function parameters.
- ListValue args;
+ ListValue* args = new ListValue();
// First arg: The id of the process that was closed.
- args.Append(Value::CreateIntegerValue(rph->GetID()));
+ args->Append(Value::CreateIntegerValue(rph->GetID()));
// Second arg: The exit type for the process.
- args.Append(Value::CreateIntegerValue(details->status));
+ args->Append(Value::CreateIntegerValue(details->status));
// Third arg: The exit code for the process.
- args.Append(Value::CreateIntegerValue(details->exit_code));
+ args->Append(Value::CreateIntegerValue(details->exit_code));
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- NotifyProfiles(keys::kOnExited, json_args);
+ NotifyProfiles(keys::kOnExited, args);
#endif // defined(ENABLE_TASK_MANAGER)
}
void ExtensionProcessesEventRouter::DispatchEvent(
Profile* profile,
const char* event_name,
- const std::string& json_args) {
+ ListValue* event_args) {
if (profile && profile->GetExtensionEventRouter()) {
profile->GetExtensionEventRouter()->DispatchEventToRenderers(
- event_name, json_args, NULL, GURL());
+ event_name, event_args, NULL, GURL());
}
}
void ExtensionProcessesEventRouter::NotifyProfiles(const char* event_name,
- std::string json_args) {
+ ListValue* event_args) {
+ scoped_ptr<ListValue> delete_event_args(event_args);
for (ProfileSet::iterator it = profiles_.begin();
it != profiles_.end(); it++) {
Profile* profile = *it;
- DispatchEvent(profile, event_name, json_args);
+ DispatchEvent(profile, event_name, event_args->DeepCopy());
}
}

Powered by Google App Engine
This is Rietveld 408576698