1 // Copyright 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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MANAGER_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MANAGER_H__
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_vector.h"
12 #include "chrome/browser/sync/glue/synced_device_tracker.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 #include "extensions/browser/event_router.h"
20 class NotificationDetails;
21 class NotificationObserver;
22 class NotificationRegistrar;
23 } // namespace content
25 namespace extensions {
26 class BrowserContextKeyedAPI;
28 struct EventListenerInfo;
30 // An object of this class is created for each extension that has registered
31 // to be notified for device info change. The objects listen for notification
32 // from sync on device info change. On receiving the notification the
33 // new list of devices is constructed and passed back to the extension.
34 // The extension id is part of this object as it is needed to fill in the
35 // public ids for devices(public ids for a device, is not the same for
37 class SignedInDevicesChangeObserver
38 : public browser_sync::SyncedDeviceTracker::Observer {
40 SignedInDevicesChangeObserver(const std::string& extension_id,
42 virtual ~SignedInDevicesChangeObserver();
44 virtual void OnDeviceInfoChange() OVERRIDE;
46 const std::string& extension_id() {
51 std::string extension_id_;
52 Profile* const profile_;
53 content::NotificationRegistrar registrar_;
56 class SignedInDevicesManager : public BrowserContextKeyedAPI,
57 public content::NotificationObserver,
58 public EventRouter::Observer {
60 // Default constructor used for testing.
61 SignedInDevicesManager();
62 explicit SignedInDevicesManager(content::BrowserContext* context);
63 virtual ~SignedInDevicesManager();
65 // BrowserContextKeyedAPI implementation.
66 static BrowserContextKeyedAPIFactory<SignedInDevicesManager>*
69 // NotificationObserver:
70 virtual void Observe(int type,
71 const content::NotificationSource& source,
72 const content::NotificationDetails& details) OVERRIDE;
74 // EventRouter::Observer:
75 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
76 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE;
79 friend class BrowserContextKeyedAPIFactory<SignedInDevicesManager>;
81 // BrowserContextKeyedAPI implementation.
82 static const char* service_name() {
83 return "SignedInDevicesManager";
85 static const bool kServiceHasOwnInstanceInIncognito = true;
87 void RemoveChangeObserverForExtension(const std::string& extension_id);
89 Profile* const profile_;
90 content::NotificationRegistrar registrar_;
91 ScopedVector<SignedInDevicesChangeObserver> change_observers_;
93 FRIEND_TEST_ALL_PREFIXES(SignedInDevicesManager, UpdateListener);
95 DISALLOW_COPY_AND_ASSIGN(SignedInDevicesManager);
98 } // namespace extensions
100 #endif // CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MANAGER_H__