| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MANAGE
R_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MANAGE
R_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MANAGE
R_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MANAGE
R_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/scoped_observer.h" |
| 12 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 13 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
| 13 #include "extensions/browser/browser_context_keyed_api_factory.h" | 14 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 14 #include "extensions/browser/event_router.h" | 15 #include "extensions/browser/event_router.h" |
| 16 #include "extensions/browser/extension_registry_observer.h" |
| 15 | 17 |
| 16 class Profile; | 18 class Profile; |
| 17 | 19 |
| 18 namespace content { | 20 namespace content { |
| 19 class BrowserContext; | 21 class BrowserContext; |
| 20 class NotificationDetails; | 22 class NotificationDetails; |
| 21 class NotificationObserver; | 23 class NotificationObserver; |
| 22 class NotificationRegistrar; | 24 class NotificationRegistrar; |
| 23 } // namespace content | 25 } // namespace content |
| 24 | 26 |
| 25 namespace extensions { | 27 namespace extensions { |
| 26 class BrowserContextKeyedAPI; | 28 class BrowserContextKeyedAPI; |
| 29 class ExtensionRegistry; |
| 27 | 30 |
| 28 struct EventListenerInfo; | 31 struct EventListenerInfo; |
| 29 | 32 |
| 30 // An object of this class is created for each extension that has registered | 33 // 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 | 34 // to be notified for device info change. The objects listen for notification |
| 32 // from sync on device info change. On receiving the notification the | 35 // from sync on device info change. On receiving the notification the |
| 33 // new list of devices is constructed and passed back to the extension. | 36 // 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 | 37 // 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 | 38 // public ids for devices(public ids for a device, is not the same for |
| 36 // all extensions). | 39 // all extensions). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 return extension_id_; | 50 return extension_id_; |
| 48 } | 51 } |
| 49 | 52 |
| 50 private: | 53 private: |
| 51 std::string extension_id_; | 54 std::string extension_id_; |
| 52 Profile* const profile_; | 55 Profile* const profile_; |
| 53 content::NotificationRegistrar registrar_; | 56 content::NotificationRegistrar registrar_; |
| 54 }; | 57 }; |
| 55 | 58 |
| 56 class SignedInDevicesManager : public BrowserContextKeyedAPI, | 59 class SignedInDevicesManager : public BrowserContextKeyedAPI, |
| 57 public content::NotificationObserver, | 60 public ExtensionRegistryObserver, |
| 58 public EventRouter::Observer { | 61 public EventRouter::Observer { |
| 59 public: | 62 public: |
| 60 // Default constructor used for testing. | 63 // Default constructor used for testing. |
| 61 SignedInDevicesManager(); | 64 SignedInDevicesManager(); |
| 62 explicit SignedInDevicesManager(content::BrowserContext* context); | 65 explicit SignedInDevicesManager(content::BrowserContext* context); |
| 63 virtual ~SignedInDevicesManager(); | 66 virtual ~SignedInDevicesManager(); |
| 64 | 67 |
| 65 // BrowserContextKeyedAPI implementation. | 68 // BrowserContextKeyedAPI implementation. |
| 66 static BrowserContextKeyedAPIFactory<SignedInDevicesManager>* | 69 static BrowserContextKeyedAPIFactory<SignedInDevicesManager>* |
| 67 GetFactoryInstance(); | 70 GetFactoryInstance(); |
| 68 | 71 |
| 69 // NotificationObserver: | 72 // ExtensionRegistryObserver implementation. |
| 70 virtual void Observe(int type, | 73 virtual void OnExtensionUnloaded( |
| 71 const content::NotificationSource& source, | 74 content::BrowserContext* browser_context, |
| 72 const content::NotificationDetails& details) OVERRIDE; | 75 const Extension* extension, |
| 76 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 73 | 77 |
| 74 // EventRouter::Observer: | 78 // EventRouter::Observer: |
| 75 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; | 79 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
| 76 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; | 80 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; |
| 77 | 81 |
| 78 private: | 82 private: |
| 79 friend class BrowserContextKeyedAPIFactory<SignedInDevicesManager>; | 83 friend class BrowserContextKeyedAPIFactory<SignedInDevicesManager>; |
| 80 | 84 |
| 81 // BrowserContextKeyedAPI implementation. | 85 // BrowserContextKeyedAPI implementation. |
| 82 static const char* service_name() { | 86 static const char* service_name() { |
| 83 return "SignedInDevicesManager"; | 87 return "SignedInDevicesManager"; |
| 84 } | 88 } |
| 85 static const bool kServiceHasOwnInstanceInIncognito = true; | 89 static const bool kServiceHasOwnInstanceInIncognito = true; |
| 86 | 90 |
| 87 void RemoveChangeObserverForExtension(const std::string& extension_id); | 91 void RemoveChangeObserverForExtension(const std::string& extension_id); |
| 88 | 92 |
| 89 Profile* const profile_; | 93 Profile* const profile_; |
| 90 content::NotificationRegistrar registrar_; | |
| 91 ScopedVector<SignedInDevicesChangeObserver> change_observers_; | 94 ScopedVector<SignedInDevicesChangeObserver> change_observers_; |
| 92 | 95 |
| 96 // Listen to extension unloaded notification. |
| 97 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 98 extension_registry_observer_; |
| 99 |
| 93 FRIEND_TEST_ALL_PREFIXES(SignedInDevicesManager, UpdateListener); | 100 FRIEND_TEST_ALL_PREFIXES(SignedInDevicesManager, UpdateListener); |
| 94 | 101 |
| 95 DISALLOW_COPY_AND_ASSIGN(SignedInDevicesManager); | 102 DISALLOW_COPY_AND_ASSIGN(SignedInDevicesManager); |
| 96 }; | 103 }; |
| 97 | 104 |
| 98 } // namespace extensions | 105 } // namespace extensions |
| 99 | 106 |
| 100 #endif // CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MAN
AGER_H__ | 107 #endif // CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MAN
AGER_H__ |
| OLD | NEW |