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