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

Side by Side Diff: chrome/browser/extensions/api/api_resource_event_notifier.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/extensions/api/api_resource_event_notifier.h" 5 #include "chrome/browser/extensions/api/api_resource_event_notifier.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/event_router.h" 10 #include "chrome/browser/extensions/event_router.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 BrowserThread::UI, FROM_HERE, 88 BrowserThread::UI, FROM_HERE,
89 base::Bind( 89 base::Bind(
90 &ApiResourceEventNotifier::DispatchEventOnUIThread, this, extension, 90 &ApiResourceEventNotifier::DispatchEventOnUIThread, this, extension,
91 event)); 91 event));
92 } 92 }
93 93
94 void ApiResourceEventNotifier::DispatchEventOnUIThread( 94 void ApiResourceEventNotifier::DispatchEventOnUIThread(
95 const std::string &extension, DictionaryValue* event) { 95 const std::string &extension, DictionaryValue* event) {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
97 97
98 ListValue args; 98 scoped_ptr<ListValue> arguments(new ListValue());
99 args.Set(0, event); 99 arguments->Set(0, event);
100 router_->DispatchEventToExtension(src_extension_id_, extension, args, 100 router_->DispatchEventToExtension(src_extension_id_, extension,
101 profile_, src_url_); 101 arguments.Pass(), profile_, src_url_);
102 } 102 }
103 103
104 DictionaryValue* ApiResourceEventNotifier::CreateApiResourceEvent( 104 DictionaryValue* ApiResourceEventNotifier::CreateApiResourceEvent(
105 ApiResourceEventType event_type) { 105 ApiResourceEventType event_type) {
106 DictionaryValue* event = new DictionaryValue(); 106 DictionaryValue* event = new DictionaryValue();
107 event->SetString(kEventTypeKey, ApiResourceEventTypeToString(event_type)); 107 event->SetString(kEventTypeKey, ApiResourceEventTypeToString(event_type));
108 event->SetInteger(kSrcIdKey, src_id_); 108 event->SetInteger(kSrcIdKey, src_id_);
109 109
110 // TODO(miket): Signal that it's OK to clean up onEvent listeners. This is 110 // TODO(miket): Signal that it's OK to clean up onEvent listeners. This is
111 // the framework we'll use, but we need to start using it. 111 // the framework we'll use, but we need to start using it.
(...skipping 10 matching lines...) Expand all
122 int result_code) { 122 int result_code) {
123 if (src_id_ < 0) 123 if (src_id_ < 0)
124 return; 124 return;
125 125
126 DictionaryValue* event = CreateApiResourceEvent(event_type); 126 DictionaryValue* event = CreateApiResourceEvent(event_type);
127 event->SetInteger(kResultCodeKey, result_code); 127 event->SetInteger(kResultCodeKey, result_code);
128 DispatchEvent(extension, event); 128 DispatchEvent(extension, event);
129 } 129 }
130 130
131 } // namespace extensions 131 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/alarms/alarm_manager.cc ('k') | chrome/browser/extensions/api/app/app_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698