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

Unified Diff: chrome/browser/extensions/api/identity/identity_event_router.cc

Issue 27283002: Identity API: Add chrome.identity.onSignInChanged routing and IDL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: AccountInfo documentation Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698