File: fcm_topic_subscriber_impl.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (91 lines) | stat: -rw-r--r-- 3,360 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_CARRIER_LOCK_FCM_TOPIC_SUBSCRIBER_IMPL_H_
#define CHROMEOS_ASH_COMPONENTS_CARRIER_LOCK_FCM_TOPIC_SUBSCRIBER_IMPL_H_

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/ash/components/carrier_lock/fcm_topic_subscriber.h"
#include "chromeos/ash/components/carrier_lock/topic_subscription_request.h"
#include "components/gcm_driver/gcm_app_handler.h"
#include "components/gcm_driver/instance_id/instance_id.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"

namespace gcm {
class GCMDriver;
}

namespace instance_id {
class InstanceIDDriver;
}

namespace ash::carrier_lock {

// This class handles the registration to Firebase Cloud Messaging service and
// subscription to specified public topic for receiving asynchronous
// notifications when the Carrier Lock configuration changes.
class COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_CARRIER_LOCK)
    FcmTopicSubscriberImpl : public FcmTopicSubscriber,
                             public gcm::GCMAppHandler {
 public:
  FcmTopicSubscriberImpl(gcm::GCMDriver* gcm_driver,
                         std::string app_id,
                         std::string sender_id,
                         scoped_refptr<network::SharedURLLoaderFactory>);
  ~FcmTopicSubscriberImpl() override;
  FcmTopicSubscriberImpl() = delete;

  // FcmTopicSubscriber
  bool Initialize(NotificationCallback notification) override;
  void RequestToken(Callback callback) override;
  void SubscribeTopic(const std::string& topic,
                      Callback callback) override;
  std::string const token() override;

 private:
  friend class FcmTopicSubscriberTest;

  void Subscribe(Result request_token_result);
  void OnGetToken(const std::string& token,
                  instance_id::InstanceID::Result result);
  void OnGetGcmStatistics(const gcm::GCMClient::GCMStatistics& statistics);

  void ReturnError(Result);
  void ReturnSuccess();

  // GCMAppHandler
  void ShutdownHandler() override;
  void OnStoreReset() override;
  void OnMessage(const std::string& app_id,
                 const gcm::IncomingMessage& message) override;
  void OnMessagesDeleted(const std::string& app_id) override;
  void OnSendError(
      const std::string& app_id,
      const gcm::GCMClient::SendErrorDetails& send_error_details) override;
  void OnSendAcknowledged(const std::string& app_id,
                          const std::string& message_id) override;
  bool CanHandle(const std::string& app_id) const override;

  raw_ptr<gcm::GCMDriver> gcm_driver_;
  std::unique_ptr<instance_id::InstanceIDDriver> instance_id_driver_;
  std::unique_ptr<TopicSubscriptionRequest> subscription_request_;
  scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;

  uint64_t android_id_ = 0;
  uint64_t android_secret_ = 0;
  std::string app_id_;
  std::string sender_id_;
  std::string token_;
  std::string topic_;
  Callback request_callback_;
  Callback subscribe_callback_;
  NotificationCallback notification_callback_;

  base::WeakPtrFactory<FcmTopicSubscriberImpl> weakptr_factory_{this};
};

}  // namespace ash::carrier_lock

#endif  // CHROMEOS_ASH_COMPONENTS_CARRIER_LOCK_FCM_TOPIC_SUBSCRIBER_IMPL_H_