| 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 "chrome/browser/extensions/api/profile_keyed_api_factory.h" | |
| 13 #include "chrome/browser/sync/glue/synced_device_tracker.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" | 14 #include "extensions/browser/event_router.h" |
| 15 | 15 |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class BrowserContext; | 19 class BrowserContext; |
| 20 class NotificationDetails; | 20 class NotificationDetails; |
| 21 class NotificationObserver; | 21 class NotificationObserver; |
| 22 class NotificationRegistrar; | 22 class NotificationRegistrar; |
| 23 } // namespace content | 23 } // namespace content |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 class ProfileKeyedAPI; | 26 class BrowserContextKeyedAPI; |
| 27 | 27 |
| 28 struct EventListenerInfo; | 28 struct EventListenerInfo; |
| 29 | 29 |
| 30 // An object of this class is created for each extension that has registered | 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 | 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 | 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. | 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 | 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 | 35 // public ids for devices(public ids for a device, is not the same for |
| 36 // all extensions). | 36 // all extensions). |
| 37 class SignedInDevicesChangeObserver | 37 class SignedInDevicesChangeObserver |
| 38 : public browser_sync::SyncedDeviceTracker::Observer { | 38 : public browser_sync::SyncedDeviceTracker::Observer { |
| 39 public: | 39 public: |
| 40 SignedInDevicesChangeObserver(const std::string& extension_id, | 40 SignedInDevicesChangeObserver(const std::string& extension_id, |
| 41 Profile* profile); | 41 Profile* profile); |
| 42 virtual ~SignedInDevicesChangeObserver(); | 42 virtual ~SignedInDevicesChangeObserver(); |
| 43 | 43 |
| 44 virtual void OnDeviceInfoChange() OVERRIDE; | 44 virtual void OnDeviceInfoChange() OVERRIDE; |
| 45 | 45 |
| 46 const std::string& extension_id() { | 46 const std::string& extension_id() { |
| 47 return extension_id_; | 47 return extension_id_; |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 std::string extension_id_; | 51 std::string extension_id_; |
| 52 Profile* const profile_; | 52 Profile* const profile_; |
| 53 content::NotificationRegistrar registrar_; | 53 content::NotificationRegistrar registrar_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 class SignedInDevicesManager | 56 class SignedInDevicesManager : public BrowserContextKeyedAPI, |
| 57 : public ProfileKeyedAPI, | 57 public content::NotificationObserver, |
| 58 public content::NotificationObserver, | 58 public EventRouter::Observer { |
| 59 public EventRouter::Observer { | |
| 60 public: | 59 public: |
| 61 // Default constructor used for testing. | 60 // Default constructor used for testing. |
| 62 SignedInDevicesManager(); | 61 SignedInDevicesManager(); |
| 63 explicit SignedInDevicesManager(content::BrowserContext* context); | 62 explicit SignedInDevicesManager(content::BrowserContext* context); |
| 64 virtual ~SignedInDevicesManager(); | 63 virtual ~SignedInDevicesManager(); |
| 65 | 64 |
| 66 // ProfileKeyedAPI implementation. | 65 // BrowserContextKeyedAPI implementation. |
| 67 static ProfileKeyedAPIFactory<SignedInDevicesManager>* GetFactoryInstance(); | 66 static BrowserContextKeyedAPIFactory<SignedInDevicesManager>* |
| 67 GetFactoryInstance(); |
| 68 | 68 |
| 69 // NotificationObserver: | 69 // NotificationObserver: |
| 70 virtual void Observe(int type, | 70 virtual void Observe(int type, |
| 71 const content::NotificationSource& source, | 71 const content::NotificationSource& source, |
| 72 const content::NotificationDetails& details) OVERRIDE; | 72 const content::NotificationDetails& details) OVERRIDE; |
| 73 | 73 |
| 74 // EventRouter::Observer: | 74 // EventRouter::Observer: |
| 75 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; | 75 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
| 76 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; | 76 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 friend class ProfileKeyedAPIFactory<SignedInDevicesManager>; | 79 friend class BrowserContextKeyedAPIFactory<SignedInDevicesManager>; |
| 80 | 80 |
| 81 // ProfileKeyedAPI implementation. | 81 // BrowserContextKeyedAPI implementation. |
| 82 static const char* service_name() { | 82 static const char* service_name() { |
| 83 return "SignedInDevicesManager"; | 83 return "SignedInDevicesManager"; |
| 84 } | 84 } |
| 85 static const bool kServiceHasOwnInstanceInIncognito = true; | 85 static const bool kServiceHasOwnInstanceInIncognito = true; |
| 86 | 86 |
| 87 void RemoveChangeObserverForExtension(const std::string& extension_id); | 87 void RemoveChangeObserverForExtension(const std::string& extension_id); |
| 88 | 88 |
| 89 Profile* const profile_; | 89 Profile* const profile_; |
| 90 content::NotificationRegistrar registrar_; | 90 content::NotificationRegistrar registrar_; |
| 91 ScopedVector<SignedInDevicesChangeObserver> change_observers_; | 91 ScopedVector<SignedInDevicesChangeObserver> change_observers_; |
| 92 | 92 |
| 93 FRIEND_TEST_ALL_PREFIXES(SignedInDevicesManager, UpdateListener); | 93 FRIEND_TEST_ALL_PREFIXES(SignedInDevicesManager, UpdateListener); |
| 94 | 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(SignedInDevicesManager); | 95 DISALLOW_COPY_AND_ASSIGN(SignedInDevicesManager); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 } // namespace extensions | 98 } // namespace extensions |
| 99 | 99 |
| 100 #endif // CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MAN
AGER_H__ | 100 #endif // CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_SIGNED_IN_DEVICES_MAN
AGER_H__ |
| OLD | NEW |