Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: components/gcm_driver/registration_info.h

Issue 1137463003: Support getting and deleting token for Instance ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add new files Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_GCM_DRIVER_REGISTRATION_INFO_H_
6 #define COMPONENTS_GCM_DRIVER_REGISTRATION_INFO_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
15
16 namespace gcm {
17
18 // Encapsulates the information needed to register with the server.
19 struct RegistrationInfo {
20 enum RegistrationType {
21 GCM_REGISTRATION,
22 INSTANCE_ID_TOKEN
23 };
24
25 // Returns the appropriate RegistrationInfo instance based on the serialized
26 // key and value.
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);
32
33 RegistrationInfo();
34 virtual ~RegistrationInfo();
35
36 // Returns the type of the registration info.
37 virtual RegistrationType GetType() const = 0;
38
39 // For persisting to the store. Depending on the type, part of the
40 // registration info are written as key. The remaining of the registration
fgorski 2015/05/13 18:32:40 is written as key. or change part to parts
jianli 2015/05/13 22:42:56 Done.
41 // info plus the registration ID are writtem as value.
fgorski 2015/05/13 18:32:40 written
jianli 2015/05/13 22:42:56 Done.
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 no interest to it.
fgorski 2015/05/13 18:32:40 I don't understand the comment.
46 virtual bool Deserialize(const std::string& serialzied_key,
47 const std::string& serialzied_value,
48 std::string* registration_id) = 0;
49
50 // Every registration is associated with an application.
51 std::string app_id;
52 };
53
54 // For GCM registration.
55 struct GCMRegistrationInfo : public RegistrationInfo {
56 GCMRegistrationInfo();
57 ~GCMRegistrationInfo() override;
58
59 // Converts from the base type;
60 static const GCMRegistrationInfo* FromRegistrationInfo(
61 const RegistrationInfo* registration_info);
62 static GCMRegistrationInfo* FromRegistrationInfo(
63 RegistrationInfo* registration_info);
64
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;
73
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;
77 };
78
79 // For InstanceID token retrieval.
80 struct InstanceIDTokenInfo : public RegistrationInfo {
81 InstanceIDTokenInfo();
82 ~InstanceIDTokenInfo() override;
83
84 // Converts from the base type;
85 static const InstanceIDTokenInfo* FromRegistrationInfo(
86 const RegistrationInfo* registration_info);
87 static InstanceIDTokenInfo* FromRegistrationInfo(
88 RegistrationInfo* registration_info);
89
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;
98
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
101 // API Console.
102 std::string authorized_entity;
103
104 // Authorized actions that the authorized entity can take.
105 // E.g. for sending GCM messages, 'GCM' scope should be used.
106 std::string scope;
107
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;
111 };
112
113 struct RegistrationInfoComparer {
114 bool operator()(const linked_ptr<RegistrationInfo>& a,
115 const linked_ptr<RegistrationInfo>& b) const;
116 };
117
118 // Collection of registration info.
119 // Map from RegistrationInfo instance to registration ID.
120 typedef std::map<linked_ptr<RegistrationInfo>,
121 std::string,
122 RegistrationInfoComparer> RegistrationInfoMap;
123
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);
127
128 } // namespace gcm
129
130 #endif // COMPONENTS_GCM_DRIVER_REGISTRATION_INFO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698