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

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: remove unintended IdentityAPI changes 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..b552099cfa942c368bcdca6b21b16a272411a743
--- /dev/null
+++ b/chrome/browser/extensions/api/identity/identity_event_router.cc
@@ -0,0 +1,63 @@
+// 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 "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) {
+ const EventListenerMap::ListenerList& listeners =
+ extensions::ExtensionSystem::Get(profile_)->event_router()->listeners()
+ .GetEventListenersByName(api::identity::OnSignInChanged::kEventName);
+
+ ExtensionService* service =
+ ExtensionSystem::Get(profile_)->extension_service();
not at google - send to devlin 2013/10/16 16:49:37 ExtensionSystem::Get(profile_) being used twice. S
Michael Courage 2013/10/16 20:24:52 Done.
+ EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router();
+
+ api::identity::AccountInfo account_info;
+ account_info.id = id;
+
+ api::identity::AccountInfo account_info_email;
+ account_info_email.id = id;
+ account_info_email.email = scoped_ptr<std::string>(new std::string(email));
not at google - send to devlin 2013/10/16 16:49:37 could you just have a single AccountInfo object an
Michael Courage 2013/10/16 20:24:52 Done.
+
+ for (EventListenerMap::ListenerList::const_iterator it = listeners.begin();
+ it != listeners.end();
+ ++it) {
+
not at google - send to devlin 2013/10/16 16:49:37 nit if you want: "it != listeners.end(); ++it" (no
Michael Courage 2013/10/16 20:24:52 Done.
+ const std::string extension_id = (*it)->extension_id;
not at google - send to devlin 2013/10/16 16:49:37 const std::string& ?
Michael Courage 2013/10/16 20:24:52 Done.
+ const Extension* extension = service->extensions()->GetByID(extension_id);
+
+ // Add the email address to AccountInfo only for extensions that
+ // have APIPermission::kIdentityEmail.
+ scoped_ptr<base::ListValue> args;
+ if (extension->HasAPIPermission(APIPermission::kIdentityEmail)) {
+ args = api::identity::OnSignInChanged::Create(account_info_email,
+ is_signed_in);
+ } else {
+ args = api::identity::OnSignInChanged::Create(account_info,
+ is_signed_in);
+ }
+
+ scoped_ptr<Event> event(
+ new Event(api::identity::OnSignInChanged::kEventName, args.Pass()));
not at google - send to devlin 2013/10/16 16:49:37 I think there's an event constructor that will let
Michael Courage 2013/10/16 20:24:52 Done.
+ event->restrict_to_profile = profile_;
+ event_router->DispatchEventToExtension(extension_id, event.Pass());
+ }
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698