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

Side by Side Diff: chrome/browser/history/history_extension_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: Fixing memory leak in a test. Created 8 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 | 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/history/history_extension_api.h" 5 #include "chrome/browser/history/history_extension_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 NOTREACHED(); 152 NOTREACHED();
153 } 153 }
154 } 154 }
155 155
156 void HistoryExtensionEventRouter::HistoryUrlVisited( 156 void HistoryExtensionEventRouter::HistoryUrlVisited(
157 Profile* profile, 157 Profile* profile,
158 const history::URLVisitedDetails* details) { 158 const history::URLVisitedDetails* details) {
159 scoped_ptr<HistoryItem> history_item = GetHistoryItem(details->row); 159 scoped_ptr<HistoryItem> history_item = GetHistoryItem(details->row);
160 scoped_ptr<ListValue> args = OnVisited::Create(*history_item); 160 scoped_ptr<ListValue> args = OnVisited::Create(*history_item);
161 161
162 std::string json_args; 162 DispatchEvent(profile, kOnVisited, args.Pass());
163 base::JSONWriter::Write(args.get(), &json_args);
164 DispatchEvent(profile, kOnVisited, json_args);
165 } 163 }
166 164
167 void HistoryExtensionEventRouter::HistoryUrlsRemoved( 165 void HistoryExtensionEventRouter::HistoryUrlsRemoved(
168 Profile* profile, 166 Profile* profile,
169 const history::URLsDeletedDetails* details) { 167 const history::URLsDeletedDetails* details) {
170 OnVisitRemoved::Removed removed; 168 OnVisitRemoved::Removed removed;
171 removed.all_history = details->all_history; 169 removed.all_history = details->all_history;
172 170
173 std::vector<std::string>* urls = new std::vector<std::string>(); 171 std::vector<std::string>* urls = new std::vector<std::string>();
174 for (history::URLRows::const_iterator iterator = details->rows.begin(); 172 for (history::URLRows::const_iterator iterator = details->rows.begin();
175 iterator != details->rows.end(); ++iterator) { 173 iterator != details->rows.end(); ++iterator) {
176 urls->push_back(iterator->url().spec()); 174 urls->push_back(iterator->url().spec());
177 } 175 }
178 removed.urls.reset(urls); 176 removed.urls.reset(urls);
179 177
180 scoped_ptr<ListValue> args = OnVisitRemoved::Create(removed); 178 scoped_ptr<ListValue> args = OnVisitRemoved::Create(removed);
181 std::string json_args; 179 DispatchEvent(profile, kOnVisitRemoved, args.Pass());
182 base::JSONWriter::Write(args.get(), &json_args);
183 DispatchEvent(profile, kOnVisitRemoved, json_args);
184 } 180 }
185 181
186 void HistoryExtensionEventRouter::DispatchEvent(Profile* profile, 182 void HistoryExtensionEventRouter::DispatchEvent(
187 const char* event_name, 183 Profile* profile,
188 const std::string& json_args) { 184 const char* event_name,
185 scoped_ptr<ListValue> event_args) {
189 if (profile && profile->GetExtensionEventRouter()) { 186 if (profile && profile->GetExtensionEventRouter()) {
190 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 187 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
191 event_name, json_args, profile, GURL(), 188 event_name, event_args.Pass(), profile, GURL(),
192 extensions::EventFilteringInfo()); 189 extensions::EventFilteringInfo());
193 } 190 }
194 } 191 }
195 192
196 void HistoryFunction::Run() { 193 void HistoryFunction::Run() {
197 if (!RunImpl()) { 194 if (!RunImpl()) {
198 SendResponse(false); 195 SendResponse(false);
199 } 196 }
200 } 197 }
201 198
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 &cancelable_consumer_, 396 &cancelable_consumer_,
400 base::Bind(&DeleteAllHistoryFunction::DeleteComplete, 397 base::Bind(&DeleteAllHistoryFunction::DeleteComplete,
401 base::Unretained(this))); 398 base::Unretained(this)));
402 399
403 return true; 400 return true;
404 } 401 }
405 402
406 void DeleteAllHistoryFunction::DeleteComplete() { 403 void DeleteAllHistoryFunction::DeleteComplete() {
407 SendAsyncResponse(); 404 SendAsyncResponse();
408 } 405 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history_extension_api.h ('k') | chrome/browser/speech/extension_api/tts_engine_extension_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698