| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ |
| 6 #define CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | 6 #define CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/threading/non_thread_safe.h" | 9 #include "base/threading/non_thread_safe.h" |
| 10 #include "chrome/browser/invalidation/invalidation_frontend.h" | 10 #include "chrome/browser/invalidation/invalidation_service.h" |
| 11 #include "chrome/browser/invalidation/invalidator_storage.h" | 11 #include "chrome/browser/invalidation/invalidator_storage.h" |
| 12 #include "chrome/browser/signin/signin_global_error.h" | 12 #include "chrome/browser/signin/signin_global_error.h" |
| 13 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 13 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "sync/notifier/invalidation_handler.h" | 16 #include "sync/notifier/invalidation_handler.h" |
| 17 #include "sync/notifier/invalidator_registrar.h" | 17 #include "sync/notifier/invalidator_registrar.h" |
| 18 | 18 |
| 19 class Profile; | 19 class Profile; |
| 20 class SigninManagerBase; | 20 class SigninManagerBase; |
| 21 class TokenService; | 21 class TokenService; |
| 22 | 22 |
| 23 namespace syncer { | 23 namespace syncer { |
| 24 class Invalidator; | 24 class Invalidator; |
| 25 } | 25 } |
| 26 | 26 |
| 27 //TODO: Remove this dependency. See crbug.com/243482. |
| 28 namespace extensions { |
| 29 class PushMessagingApiTest; |
| 30 } |
| 31 |
| 27 namespace invalidation { | 32 namespace invalidation { |
| 28 | 33 |
| 29 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. | 34 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. |
| 30 // It provides invalidations for desktop platforms (Win, Mac, Linux). | 35 // It provides invalidations for desktop platforms (Win, Mac, Linux). |
| 31 class TiclInvalidationService | 36 class TiclInvalidationService |
| 32 : public base::NonThreadSafe, | 37 : public base::NonThreadSafe, |
| 33 public BrowserContextKeyedService, | 38 public InvalidationService, |
| 34 public InvalidationFrontend, | |
| 35 public content::NotificationObserver, | 39 public content::NotificationObserver, |
| 36 public syncer::InvalidationHandler { | 40 public syncer::InvalidationHandler { |
| 37 public: | 41 public: |
| 38 TiclInvalidationService(SigninManagerBase* signin, | 42 TiclInvalidationService(SigninManagerBase* signin, |
| 39 TokenService* token_service, | 43 TokenService* token_service, |
| 40 Profile* profile); | 44 Profile* profile); |
| 41 virtual ~TiclInvalidationService(); | 45 virtual ~TiclInvalidationService(); |
| 42 | 46 |
| 43 void Init(); | 47 void Init(); |
| 44 | 48 |
| 45 // InvalidationFrontend implementation. | 49 // InvalidationService implementation. |
| 46 // It is an error to have registered handlers when Shutdown() is called. | 50 // It is an error to have registered handlers when Shutdown() is called. |
| 47 virtual void RegisterInvalidationHandler( | 51 virtual void RegisterInvalidationHandler( |
| 48 syncer::InvalidationHandler* handler) OVERRIDE; | 52 syncer::InvalidationHandler* handler) OVERRIDE; |
| 49 virtual void UpdateRegisteredInvalidationIds( | 53 virtual void UpdateRegisteredInvalidationIds( |
| 50 syncer::InvalidationHandler* handler, | 54 syncer::InvalidationHandler* handler, |
| 51 const syncer::ObjectIdSet& ids) OVERRIDE; | 55 const syncer::ObjectIdSet& ids) OVERRIDE; |
| 52 virtual void UnregisterInvalidationHandler( | 56 virtual void UnregisterInvalidationHandler( |
| 53 syncer::InvalidationHandler* handler) OVERRIDE; | 57 syncer::InvalidationHandler* handler) OVERRIDE; |
| 54 virtual void AcknowledgeInvalidation( | 58 virtual void AcknowledgeInvalidation( |
| 55 const invalidation::ObjectId& id, | 59 const invalidation::ObjectId& id, |
| 56 const syncer::AckHandle& ack_handle) OVERRIDE; | 60 const syncer::AckHandle& ack_handle) OVERRIDE; |
| 57 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | 61 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; |
| 58 virtual std::string GetInvalidatorClientId() const; | 62 virtual std::string GetInvalidatorClientId() const OVERRIDE; |
| 59 | 63 |
| 60 // content::NotificationObserver implementation. | 64 // content::NotificationObserver implementation. |
| 61 virtual void Observe(int type, | 65 virtual void Observe(int type, |
| 62 const content::NotificationSource& source, | 66 const content::NotificationSource& source, |
| 63 const content::NotificationDetails& details) OVERRIDE; | 67 const content::NotificationDetails& details) OVERRIDE; |
| 64 | 68 |
| 65 // syncer::InvalidationHandler implementation. | 69 // syncer::InvalidationHandler implementation. |
| 66 virtual void OnInvalidatorStateChange( | 70 virtual void OnInvalidatorStateChange( |
| 67 syncer::InvalidatorState state) OVERRIDE; | 71 syncer::InvalidatorState state) OVERRIDE; |
| 68 virtual void OnIncomingInvalidation( | 72 virtual void OnIncomingInvalidation( |
| 69 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 73 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
| 70 | 74 |
| 71 // Overrides BrowserContextKeyedService method. | 75 // Overrides BrowserContextKeyedService method. |
| 72 virtual void Shutdown() OVERRIDE; | 76 virtual void Shutdown() OVERRIDE; |
| 73 | 77 |
| 74 protected: | 78 protected: |
| 75 // Initializes with an injected invalidator. | 79 // Initializes with an injected invalidator. |
| 76 void InitForTest(syncer::Invalidator* invalidator); | 80 void InitForTest(syncer::Invalidator* invalidator); |
| 77 | 81 |
| 78 friend class TiclInvalidationServiceTestDelegate; | 82 friend class TiclInvalidationServiceTestDelegate; |
| 83 friend class extensions::PushMessagingApiTest; |
| 79 | 84 |
| 80 private: | 85 private: |
| 81 bool IsReadyToStart(); | 86 bool IsReadyToStart(); |
| 82 bool IsStarted(); | 87 bool IsStarted(); |
| 83 | 88 |
| 84 void Start(); | 89 void Start(); |
| 85 void UpdateToken(); | 90 void UpdateToken(); |
| 86 void StopInvalidator(); | 91 void StopInvalidator(); |
| 87 void Logout(); | 92 void Logout(); |
| 88 | 93 |
| 89 Profile *const profile_; | 94 Profile *const profile_; |
| 90 SigninManagerBase *const signin_manager_; | 95 SigninManagerBase *const signin_manager_; |
| 91 TokenService *const token_service_; | 96 TokenService *const token_service_; |
| 92 | 97 |
| 93 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | 98 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; |
| 94 scoped_ptr<InvalidatorStorage> invalidator_storage_; | 99 scoped_ptr<InvalidatorStorage> invalidator_storage_; |
| 95 scoped_ptr<syncer::Invalidator> invalidator_; | 100 scoped_ptr<syncer::Invalidator> invalidator_; |
| 96 | 101 |
| 97 content::NotificationRegistrar notification_registrar_; | 102 content::NotificationRegistrar notification_registrar_; |
| 98 | 103 |
| 99 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); | 104 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); |
| 100 }; | 105 }; |
| 101 | 106 |
| 102 } | 107 } |
| 103 | 108 |
| 104 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | 109 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ |
| OLD | NEW |