Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/api/identity/identity_event_router.h" | |
| 6 | |
| 7 #include <set> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/stl_util.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chrome/browser/extensions/event_router.h" | |
| 13 #include "chrome/browser/extensions/extension_service.h" | |
| 14 #include "chrome/browser/extensions/extension_system.h" | |
| 15 #include "chrome/common/extensions/api/identity.h" | |
| 16 | |
| 17 namespace extensions { | |
| 18 | |
| 19 IdentityEventRouter::IdentityEventRouter(Profile* profile) | |
| 20 : profile_(profile) {} | |
| 21 | |
| 22 IdentityEventRouter::~IdentityEventRouter() {} | |
| 23 | |
| 24 void IdentityEventRouter::DispatchSignInEvent(const std::string& id, | |
| 25 const std::string& email, | |
| 26 bool is_signed_in) { | |
| 27 extensions::ExtensionSystem* extension_system = | |
| 28 ExtensionSystem::Get(profile_); | |
| 29 const EventListenerMap::ListenerList& listeners = | |
| 30 extension_system->event_router()->listeners() | |
| 31 .GetEventListenersByName(api::identity::OnSignInChanged::kEventName); | |
| 32 | |
| 33 ExtensionService* service = extension_system->extension_service(); | |
| 34 EventRouter* event_router = extension_system->event_router(); | |
| 35 | |
| 36 scoped_ptr<std::string> info_email(new std::string(email)); | |
| 37 api::identity::AccountInfo account_info; | |
| 38 account_info.id = id; | |
| 39 | |
| 40 std::set<std::string> already_dispatched; | |
| 41 | |
| 42 for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); | |
| 43 it != listeners.end(); ++it) { | |
| 44 const std::string& extension_id = (*it)->extension_id; | |
| 45 const Extension* extension = service->extensions()->GetByID(extension_id); | |
| 46 | |
| 47 if (ContainsKey(already_dispatched, extension_id)) | |
| 48 continue; | |
| 49 | |
| 50 already_dispatched.insert(extension_id); | |
| 51 | |
| 52 // Add the email address to AccountInfo only for extensions that | |
| 53 // have APIPermission::kIdentityEmail. | |
| 54 if (extension->HasAPIPermission(APIPermission::kIdentityEmail)) | |
| 55 account_info.email.reset(info_email.get()); | |
|
not at google - send to devlin
2013/10/16 20:36:01
seems just as valid to use &email here and not hav
Michael Courage
2013/10/16 21:18:53
Done.
| |
| 56 | |
| 57 scoped_ptr<base::ListValue> args = | |
| 58 api::identity::OnSignInChanged::Create(account_info, is_signed_in); | |
| 59 scoped_ptr<Event> event(new Event( | |
| 60 api::identity::OnSignInChanged::kEventName, args.Pass(), profile_)); | |
| 61 event_router->DispatchEventToExtension(extension_id, event.Pass()); | |
| 62 | |
| 63 ignore_result(account_info.email.release()); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 } // namespace extensions | |
| OLD | NEW |