| 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/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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 std::string ApiResourceEventNotifier::ApiResourceEventTypeToString( | 38 std::string ApiResourceEventNotifier::ApiResourceEventTypeToString( |
| 39 ApiResourceEventType event_type) { | 39 ApiResourceEventType event_type) { |
| 40 NOTREACHED(); | 40 NOTREACHED(); |
| 41 return std::string(); | 41 return std::string(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 ApiResourceEventNotifier::~ApiResourceEventNotifier() {} | 44 ApiResourceEventNotifier::~ApiResourceEventNotifier() {} |
| 45 | 45 |
| 46 void ApiResourceEventNotifier::DispatchEvent(const std::string &extension, | 46 void ApiResourceEventNotifier::DispatchEvent( |
| 47 DictionaryValue* event) { | 47 const std::string& event_name, DictionaryValue* args) { |
| 48 BrowserThread::PostTask( | 48 BrowserThread::PostTask( |
| 49 BrowserThread::UI, FROM_HERE, | 49 BrowserThread::UI, FROM_HERE, |
| 50 base::Bind( | 50 base::Bind( |
| 51 &ApiResourceEventNotifier::DispatchEventOnUIThread, this, extension, | 51 &ApiResourceEventNotifier::DispatchEventOnUIThread, this, |
| 52 event)); | 52 event_name, args)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void ApiResourceEventNotifier::DispatchEventOnUIThread( | 55 void ApiResourceEventNotifier::DispatchEventOnUIThread( |
| 56 const std::string &extension, DictionaryValue* event) { | 56 const std::string& event_name, DictionaryValue* args) { |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 58 | 58 |
| 59 scoped_ptr<ListValue> arguments(new ListValue()); | 59 scoped_ptr<ListValue> arguments(new ListValue()); |
| 60 arguments->Set(0, event); | 60 arguments->Set(0, args); |
| 61 router_->DispatchEventToExtension(src_extension_id_, extension, | 61 scoped_ptr<Event> event(new Event(event_name, arguments.Pass())); |
| 62 arguments.Pass(), profile_, src_url_); | 62 event->restrict_to_profile = profile_; |
| 63 event->event_url = src_url_; |
| 64 router_->DispatchEventToExtension(src_extension_id_, event.Pass()); |
| 63 } | 65 } |
| 64 | 66 |
| 65 DictionaryValue* ApiResourceEventNotifier::CreateApiResourceEvent( | 67 DictionaryValue* ApiResourceEventNotifier::CreateApiResourceEvent( |
| 66 ApiResourceEventType event_type) { | 68 ApiResourceEventType event_type) { |
| 67 DictionaryValue* event = new DictionaryValue(); | 69 DictionaryValue* event = new DictionaryValue(); |
| 68 event->SetString(kEventTypeKey, ApiResourceEventTypeToString(event_type)); | 70 event->SetString(kEventTypeKey, ApiResourceEventTypeToString(event_type)); |
| 69 event->SetInteger(kSrcIdKey, src_id_); | 71 event->SetInteger(kSrcIdKey, src_id_); |
| 70 | 72 |
| 71 // TODO(miket): Signal that it's OK to clean up onEvent listeners. This is | 73 // TODO(miket): Signal that it's OK to clean up onEvent listeners. This is |
| 72 // the framework we'll use, but we need to start using it. | 74 // the framework we'll use, but we need to start using it. |
| 73 event->SetBoolean(kIsFinalEventKey, false); | 75 event->SetBoolean(kIsFinalEventKey, false); |
| 74 | 76 |
| 75 // The caller owns the created event, which typically is then given to a | 77 // The caller owns the created event, which typically is then given to a |
| 76 // ListValue to dispose of. | 78 // ListValue to dispose of. |
| 77 return event; | 79 return event; |
| 78 } | 80 } |
| 79 | 81 |
| 80 } // namespace extensions | 82 } // namespace extensions |
| OLD | NEW |