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 "base/values.h" | |
8 #include "chrome/browser/extensions/event_router.h" | |
9 #include "chrome/browser/extensions/extension_service.h" | |
10 #include "chrome/browser/extensions/extension_system.h" | |
11 #include "chrome/common/extensions/api/identity.h" | |
12 | |
13 namespace extensions { | |
14 | |
15 IdentityEventRouter::IdentityEventRouter(Profile* profile) | |
16 : profile_(profile) {} | |
17 | |
18 IdentityEventRouter::~IdentityEventRouter() {} | |
19 | |
20 void IdentityEventRouter::DispatchSignInEvent(const std::string& id, | |
21 const std::string& email, | |
22 bool is_signed_in) { | |
23 const EventListenerMap::ListenerList& listeners = | |
24 extensions::ExtensionSystem::Get(profile_)->event_router()->listeners() | |
25 .GetEventListenersByName(api::identity::OnSignInChanged::kEventName); | |
26 | |
27 ExtensionService* service = | |
28 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.
| |
29 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router(); | |
30 | |
31 api::identity::AccountInfo account_info; | |
32 account_info.id = id; | |
33 | |
34 api::identity::AccountInfo account_info_email; | |
35 account_info_email.id = id; | |
36 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.
| |
37 | |
38 for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); | |
39 it != listeners.end(); | |
40 ++it) { | |
41 | |
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.
| |
42 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.
| |
43 const Extension* extension = service->extensions()->GetByID(extension_id); | |
44 | |
45 // Add the email address to AccountInfo only for extensions that | |
46 // have APIPermission::kIdentityEmail. | |
47 scoped_ptr<base::ListValue> args; | |
48 if (extension->HasAPIPermission(APIPermission::kIdentityEmail)) { | |
49 args = api::identity::OnSignInChanged::Create(account_info_email, | |
50 is_signed_in); | |
51 } else { | |
52 args = api::identity::OnSignInChanged::Create(account_info, | |
53 is_signed_in); | |
54 } | |
55 | |
56 scoped_ptr<Event> event( | |
57 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.
| |
58 event->restrict_to_profile = profile_; | |
59 event_router->DispatchEventToExtension(extension_id, event.Pass()); | |
60 } | |
61 } | |
62 | |
63 } // namespace extensions | |
OLD | NEW |