OLD | NEW |
---|---|
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/extensions/extension_function.h" | 5 #include "chrome/browser/extensions/extension_function.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 9 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 void ExtensionFunction::OnQuotaExceeded() { | 86 void ExtensionFunction::OnQuotaExceeded() { |
87 error_ = QuotaLimitHeuristic::kGenericOverQuotaError; | 87 error_ = QuotaLimitHeuristic::kGenericOverQuotaError; |
88 SendResponse(false); | 88 SendResponse(false); |
89 } | 89 } |
90 | 90 |
91 void ExtensionFunction::SetArgs(const base::ListValue* args) { | 91 void ExtensionFunction::SetArgs(const base::ListValue* args) { |
92 DCHECK(!args_.get()); // Should only be called once. | 92 DCHECK(!args_.get()); // Should only be called once. |
93 args_.reset(args->DeepCopy()); | 93 args_.reset(args->DeepCopy()); |
94 } | 94 } |
95 | 95 |
96 const Value* ExtensionFunction::GetResultValue() { | 96 void ExtensionFunction::SetResult(base::Value* result) { |
97 return result_.get(); | 97 results_.reset(new base::ListValue()); |
98 results_->Append(result); | |
99 } | |
100 | |
101 const ListValue* ExtensionFunction::GetResultList() { | |
102 return results_.get(); | |
98 } | 103 } |
99 | 104 |
100 const std::string ExtensionFunction::GetError() { | 105 const std::string ExtensionFunction::GetError() { |
101 return error_; | 106 return error_; |
102 } | 107 } |
103 | 108 |
104 void ExtensionFunction::SetError(const std::string& error) { | 109 void ExtensionFunction::SetError(const std::string& error) { |
105 error_ = error; | 110 error_ = error; |
106 } | 111 } |
107 | 112 |
(...skipping 14 matching lines...) Expand all Loading... | |
122 void ExtensionFunction::SendResponseImpl(base::ProcessHandle process, | 127 void ExtensionFunction::SendResponseImpl(base::ProcessHandle process, |
123 IPC::Sender* ipc_sender, | 128 IPC::Sender* ipc_sender, |
124 int routing_id, | 129 int routing_id, |
125 bool success) { | 130 bool success) { |
126 DCHECK(ipc_sender); | 131 DCHECK(ipc_sender); |
127 if (bad_message_) { | 132 if (bad_message_) { |
128 HandleBadMessage(process); | 133 HandleBadMessage(process); |
129 return; | 134 return; |
130 } | 135 } |
131 | 136 |
132 // Value objects can't be directly serialized in our IPC code, so we wrap the | 137 // If results were never set, we send an empty argument list. |
133 // result_ Value with a ListValue (also transferring ownership of result_). | 138 if (!results_.get()) |
134 base::ListValue result_wrapper; | 139 results_.reset(new ListValue()); |
135 if (result_.get()) | |
136 result_wrapper.Append(result_.release()); | |
137 | 140 |
138 ipc_sender->Send(new ExtensionMsg_Response( | 141 ipc_sender->Send(new ExtensionMsg_Response( |
139 routing_id, request_id_, success, result_wrapper, GetError())); | 142 routing_id, request_id_, success, *results_.release(), GetError())); |
koz (OOO until 15th September)
2012/07/13 04:48:16
Is this a memory leak?
I think a better way to do
Matt Tytel
2012/07/13 05:14:39
:( Yes that is.
As for the scoped_ptr business, t
not at google - send to devlin
2012/07/13 05:20:05
In the JSC case it's also reasonable to do
void S
| |
140 } | 143 } |
141 | 144 |
142 void ExtensionFunction::HandleBadMessage(base::ProcessHandle process) { | 145 void ExtensionFunction::HandleBadMessage(base::ProcessHandle process) { |
143 LOG(ERROR) << "bad extension message " << name_ << " : terminating renderer."; | 146 LOG(ERROR) << "bad extension message " << name_ << " : terminating renderer."; |
144 if (content::RenderProcessHost::run_renderer_in_process()) { | 147 if (content::RenderProcessHost::run_renderer_in_process()) { |
145 // In single process mode it is better if we don't suicide but just crash. | 148 // In single process mode it is better if we don't suicide but just crash. |
146 CHECK(false); | 149 CHECK(false); |
147 } else { | 150 } else { |
148 NOTREACHED(); | 151 NOTREACHED(); |
149 content::RecordAction(UserMetricsAction("BadMessageTerminate_EFD")); | 152 content::RecordAction(UserMetricsAction("BadMessageTerminate_EFD")); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 | 298 |
296 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { | 299 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { |
297 } | 300 } |
298 | 301 |
299 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { | 302 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { |
300 } | 303 } |
301 | 304 |
302 void SyncIOThreadExtensionFunction::Run() { | 305 void SyncIOThreadExtensionFunction::Run() { |
303 SendResponse(RunImpl()); | 306 SendResponse(RunImpl()); |
304 } | 307 } |
OLD | NEW |