blob: 28c64db8e36ba661715a40a4eb3e1383a03b27f7 [file] [log] [blame]
tengs953ae682015-07-11 02:19:471// 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
khorimotof7a6aff2017-01-19 22:50:475#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H_
6#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H_
tengs953ae682015-07-11 02:19:477
8#include "base/macros.h"
9#include "base/memory/weak_ptr.h"
10#include "base/observer_list.h"
khorimoto999e934c2016-11-18 20:10:4211#include "components/cryptauth/cryptauth_gcm_manager.h"
mvanouwerkerkf8633deb2015-07-13 11:04:0612#include "components/gcm_driver/common/gcm_messages.h"
tengs953ae682015-07-11 02:19:4713#include "components/gcm_driver/gcm_app_handler.h"
14#include "components/gcm_driver/gcm_client.h"
tengs953ae682015-07-11 02:19:4715
16class PrefService;
17
18namespace gcm {
19class GCMDriver;
20};
21
khorimoto999e934c2016-11-18 20:10:4222namespace cryptauth {
tengs953ae682015-07-11 02:19:4723
24// Implementation of CryptAuthGCMManager.
25class 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.
tengs757fd842015-07-28 16:52:0634 CryptAuthGCMManagerImpl(gcm::GCMDriver* gcm_driver,
tengs953ae682015-07-11 02:19:4735 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;
johnme93ec7932016-11-17 14:26:5849 void OnStoreReset() override;
tengs953ae682015-07-11 02:19:4750 void OnMessage(const std::string& app_id,
mvanouwerkerkf8633deb2015-07-13 11:04:0651 const gcm::IncomingMessage& message) override;
tengs953ae682015-07-11 02:19:4752 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
khorimoto999e934c2016-11-18 20:10:4279} // namespace cryptauth
tengs953ae682015-07-11 02:19:4780
khorimotof7a6aff2017-01-19 22:50:4781#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H_