Update mojo sdk to rev c02a28868825edfa57ab77947b8cb15e741c5598
[chromium-blink-merge.git] / components / proximity_auth / cryptauth / cryptauth_gcm_manager_impl.h
blob6bf93f05a273bd8be1f33fa4d9babfd8a5571a7a
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.
5 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H
6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H
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"
16 class PrefService;
18 namespace gcm {
19 class GCMDriver;
22 namespace proximity_auth {
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);
37 ~CryptAuthGCMManagerImpl() override;
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;
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;
57 // Called when GCM registration completes.
58 void OnRegistrationCompleted(const std::string& registration_id,
59 gcm::GCMClient::Result result);
61 // Handles the communications with GCM. Not owned.
62 gcm::GCMDriver* gcm_driver_;
64 // Manages preferences across process restarts. Not owned.
65 PrefService* pref_service_;
67 // Whether a GCM registration is currently being processed.
68 bool registration_in_progress_;
70 // List of observers.
71 base::ObserverList<Observer> observers_;
73 base::WeakPtrFactory<CryptAuthGCMManagerImpl> weak_ptr_factory_;
75 DISALLOW_COPY_AND_ASSIGN(CryptAuthGCMManagerImpl);
78 } // namespace proximity_auth
80 #endif // COMPONENTS_PROXIMITY_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H