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_GCM_DRIVER_REGISTRATION_INFO_H_
6 #define COMPONENTS_GCM_DRIVER_REGISTRATION_INFO_H_
12 #include "base/basictypes.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
18 // Encapsulates the information needed to register with the server.
19 struct RegistrationInfo
{
20 enum RegistrationType
{
25 // Returns the appropriate RegistrationInfo instance based on the serialized
27 // |registration_id| can be NULL if no interest to it.
28 static scoped_ptr
<RegistrationInfo
> BuildFromString(
29 const std::string
& serialzied_key
,
30 const std::string
& serialzied_value
,
31 std::string
* registration_id
);
34 virtual ~RegistrationInfo();
36 // Returns the type of the registration info.
37 virtual RegistrationType
GetType() const = 0;
39 // For persisting to the store. Depending on the type, part of the
40 // registration info is written as key. The remaining of the registration
41 // info plus the registration ID are written as value.
42 virtual std::string
GetSerializedKey() const = 0;
43 virtual std::string
GetSerializedValue(
44 const std::string
& registration_id
) const = 0;
45 // |registration_id| can be NULL if it is of no interest to the caller.
46 virtual bool Deserialize(const std::string
& serialzied_key
,
47 const std::string
& serialzied_value
,
48 std::string
* registration_id
) = 0;
50 // Every registration is associated with an application.
54 // For GCM registration.
55 struct GCMRegistrationInfo
: public RegistrationInfo
{
56 GCMRegistrationInfo();
57 ~GCMRegistrationInfo() override
;
59 // Converts from the base type;
60 static const GCMRegistrationInfo
* FromRegistrationInfo(
61 const RegistrationInfo
* registration_info
);
62 static GCMRegistrationInfo
* FromRegistrationInfo(
63 RegistrationInfo
* registration_info
);
65 // RegistrationInfo overrides:
66 RegistrationType
GetType() const override
;
67 std::string
GetSerializedKey() const override
;
68 std::string
GetSerializedValue(
69 const std::string
& registration_id
) const override
;
70 bool Deserialize(const std::string
& serialzied_key
,
71 const std::string
& serialzied_value
,
72 std::string
* registration_id
) override
;
74 // List of IDs of the servers that are allowed to send the messages to the
75 // application. These IDs are assigned by the Google API Console.
76 std::vector
<std::string
> sender_ids
;
79 // For InstanceID token retrieval.
80 struct InstanceIDTokenInfo
: public RegistrationInfo
{
81 InstanceIDTokenInfo();
82 ~InstanceIDTokenInfo() override
;
84 // Converts from the base type;
85 static const InstanceIDTokenInfo
* FromRegistrationInfo(
86 const RegistrationInfo
* registration_info
);
87 static InstanceIDTokenInfo
* FromRegistrationInfo(
88 RegistrationInfo
* registration_info
);
90 // RegistrationInfo overrides:
91 RegistrationType
GetType() const override
;
92 std::string
GetSerializedKey() const override
;
93 std::string
GetSerializedValue(
94 const std::string
& registration_id
) const override
;
95 bool Deserialize(const std::string
& serialzied_key
,
96 const std::string
& serialzied_value
,
97 std::string
* registration_id
) override
;
99 // Entity that is authorized to access resources associated with the Instance
100 // ID. It can be another Instance ID or a project ID assigned by the Google
102 std::string authorized_entity
;
104 // Authorized actions that the authorized entity can take.
105 // E.g. for sending GCM messages, 'GCM' scope should be used.
108 // Allows including a small number of string key/value pairs that will be
109 // associated with the token and may be used in processing the request.
110 std::map
<std::string
, std::string
> options
;
113 struct RegistrationInfoComparer
{
114 bool operator()(const linked_ptr
<RegistrationInfo
>& a
,
115 const linked_ptr
<RegistrationInfo
>& b
) const;
118 // Collection of registration info.
119 // Map from RegistrationInfo instance to registration ID.
120 typedef std::map
<linked_ptr
<RegistrationInfo
>,
122 RegistrationInfoComparer
> RegistrationInfoMap
;
124 // Returns true if a GCM registration for |app_id| exists in |map|.
125 bool ExistsGCMRegistrationInMap(const RegistrationInfoMap
& map
,
126 const std::string
& app_id
);
130 #endif // COMPONENTS_GCM_DRIVER_REGISTRATION_INFO_H_