OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/observer_list.h" |
| 11 #include "components/gcm_driver/gcm_app_handler.h" |
| 12 #include "components/gcm_driver/gcm_client.h" |
| 13 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" |
| 14 |
| 15 class PrefService; |
| 16 |
| 17 namespace gcm { |
| 18 class GCMDriver; |
| 19 }; |
| 20 |
| 21 namespace proximity_auth { |
| 22 |
| 23 // Implementation of CryptAuthGCMManager. |
| 24 class CryptAuthGCMManagerImpl : public CryptAuthGCMManager, |
| 25 public gcm::GCMAppHandler { |
| 26 public: |
| 27 // Creates the manager: |
| 28 // |gcm_driver|: Handles the actual GCM communications. The driver is not |
| 29 // owned and must outlive this instance. |
| 30 // |pref_service|: Contains preferences across browser restarts, and should |
| 31 // have been registered through RegisterPrefs(). The service is not owned |
| 32 // and must outlive this instance. |
| 33 CryptAuthGCMManagerImpl(gcm::GCMDriver* gcm_deriver, |
| 34 PrefService* pref_service); |
| 35 |
| 36 ~CryptAuthGCMManagerImpl() override; |
| 37 |
| 38 // CryptAuthGCMManager: |
| 39 void StartListening() override; |
| 40 void RegisterWithGCM() override; |
| 41 std::string GetRegistrationId() override; |
| 42 void AddObserver(Observer* observer) override; |
| 43 void RemoveObserver(Observer* observer) override; |
| 44 |
| 45 private: |
| 46 // GCMAppHandler: |
| 47 void ShutdownHandler() override; |
| 48 void OnMessage(const std::string& app_id, |
| 49 const gcm::GCMClient::IncomingMessage& message) override; |
| 50 void OnMessagesDeleted(const std::string& app_id) override; |
| 51 void OnSendError(const std::string& app_id, |
| 52 const gcm::GCMClient::SendErrorDetails& details) override; |
| 53 void OnSendAcknowledged(const std::string& app_id, |
| 54 const std::string& message_id) override; |
| 55 |
| 56 // Called when GCM registration completes. |
| 57 void OnRegistrationCompleted(const std::string& registration_id, |
| 58 gcm::GCMClient::Result result); |
| 59 |
| 60 // Handles the communications with GCM. Not owned. |
| 61 gcm::GCMDriver* gcm_driver_; |
| 62 |
| 63 // Manages preferences across process restarts. Not owned. |
| 64 PrefService* pref_service_; |
| 65 |
| 66 // Whether a GCM registration is currently being processed. |
| 67 bool registration_in_progress_; |
| 68 |
| 69 // List of observers. |
| 70 base::ObserverList<Observer> observers_; |
| 71 |
| 72 base::WeakPtrFactory<CryptAuthGCMManagerImpl> weak_ptr_factory_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(CryptAuthGCMManagerImpl); |
| 75 }; |
| 76 |
| 77 } // namespace proximity_auth |
| 78 |
| 79 #endif // COMPONENTS_PROXIMITY_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H |
OLD | NEW |