Chromium Code Reviews| Index: chrome/browser/extensions/api/identity/identity_event_router.cc |
| diff --git a/chrome/browser/extensions/api/identity/identity_event_router.cc b/chrome/browser/extensions/api/identity/identity_event_router.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2581123b829a4f2c49c023472f51029cbf682261 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/identity/identity_event_router.cc |
| @@ -0,0 +1,67 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/identity/identity_event_router.h" |
| + |
| +#include <set> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/stl_util.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/extensions/event_router.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/extensions/extension_system.h" |
| +#include "chrome/common/extensions/api/identity.h" |
| + |
| +namespace extensions { |
| + |
| +IdentityEventRouter::IdentityEventRouter(Profile* profile) |
| + : profile_(profile) {} |
| + |
| +IdentityEventRouter::~IdentityEventRouter() {} |
| + |
| +void IdentityEventRouter::DispatchSignInEvent(const std::string& id, |
| + const std::string& email, |
| + bool is_signed_in) { |
| + extensions::ExtensionSystem* extension_system = |
| + ExtensionSystem::Get(profile_); |
| + const EventListenerMap::ListenerList& listeners = |
| + extension_system->event_router()->listeners() |
| + .GetEventListenersByName(api::identity::OnSignInChanged::kEventName); |
| + |
| + ExtensionService* service = extension_system->extension_service(); |
| + EventRouter* event_router = extension_system->event_router(); |
| + |
| + scoped_ptr<std::string> info_email(new std::string(email)); |
| + api::identity::AccountInfo account_info; |
| + account_info.id = id; |
| + |
| + std::set<std::string> already_dispatched; |
| + |
| + for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); |
| + it != listeners.end(); ++it) { |
| + const std::string& extension_id = (*it)->extension_id; |
| + const Extension* extension = service->extensions()->GetByID(extension_id); |
| + |
| + if (ContainsKey(already_dispatched, extension_id)) |
| + continue; |
| + |
| + already_dispatched.insert(extension_id); |
| + |
| + // Add the email address to AccountInfo only for extensions that |
| + // have APIPermission::kIdentityEmail. |
| + if (extension->HasAPIPermission(APIPermission::kIdentityEmail)) |
| + 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.
|
| + |
| + scoped_ptr<base::ListValue> args = |
| + api::identity::OnSignInChanged::Create(account_info, is_signed_in); |
| + scoped_ptr<Event> event(new Event( |
| + api::identity::OnSignInChanged::kEventName, args.Pass(), profile_)); |
| + event_router->DispatchEventToExtension(extension_id, event.Pass()); |
| + |
| + ignore_result(account_info.email.release()); |
| + } |
| +} |
| + |
| +} // namespace extensions |