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/common/gcm_messages.h" | |
12 #include "components/gcm_driver/gcm_app_handler.h" | |
13 #include "components/gcm_driver/gcm_client.h" | |
14 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" | |
15 | |
16 class PrefService; | |
17 | |
18 namespace gcm { | |
19 class GCMDriver; | |
20 }; | |
21 | |
22 namespace proximity_auth { | |
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. | |
34 CryptAuthGCMManagerImpl(gcm::GCMDriver* gcm_driver, | |
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; | |
49 void OnMessage(const std::string& app_id, | |
50 const gcm::IncomingMessage& message) override; | |
51 void OnMessagesDeleted(const std::string& app_id) override; | |
52 void OnSendError(const std::string& app_id, | |
53 const gcm::GCMClient::SendErrorDetails& details) override; | |
54 void OnSendAcknowledged(const std::string& app_id, | |
55 const std::string& message_id) override; | |
56 | |
57 // Called when GCM registration completes. | |
58 void OnRegistrationCompleted(const std::string& registration_id, | |
59 gcm::GCMClient::Result result); | |
60 | |
61 // Handles the communications with GCM. Not owned. | |
62 gcm::GCMDriver* gcm_driver_; | |
63 | |
64 // Manages preferences across process restarts. Not owned. | |
65 PrefService* pref_service_; | |
66 | |
67 // Whether a GCM registration is currently being processed. | |
68 bool registration_in_progress_; | |
69 | |
70 // List of observers. | |
71 base::ObserverList<Observer> observers_; | |
72 | |
73 base::WeakPtrFactory<CryptAuthGCMManagerImpl> weak_ptr_factory_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(CryptAuthGCMManagerImpl); | |
76 }; | |
77 | |
78 } // namespace proximity_auth | |
79 | |
80 #endif // COMPONENTS_PROXIMITY_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H | |
OLD | NEW |