OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ |
6 #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ | 6 #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 | 16 |
16 namespace gcm { | 17 namespace gcm { |
17 class InstanceIDHandler; | 18 class GCMDriver; |
18 } // namespace gcm | 19 } // namespace gcm |
19 | 20 |
20 namespace instance_id { | 21 namespace instance_id { |
21 | 22 |
23 // Scope passed to getToken to obtain GCM registration tokens. | |
24 // Must match Java GoogleCloudMessaging.INSTANCE_ID_SCOPE. | |
Peter Beverloo
2016/05/11 16:05:00
Please document *why* you could pass this to getTo
johnme
2016/05/13 16:25:45
Done. Also moved comment to .cc file (for consiste
| |
25 extern const char kGCMScope[]; | |
26 | |
22 // Encapsulates Instance ID functionalities that need to be implemented for | 27 // Encapsulates Instance ID functionalities that need to be implemented for |
23 // different platforms. One instance is created per application. Life of | 28 // different platforms. One instance is created per application. Life of |
24 // Instance ID is managed by the InstanceIDDriver. | 29 // Instance ID is managed by the InstanceIDDriver. |
25 class InstanceID { | 30 class InstanceID { |
26 public: | 31 public: |
27 enum Result { | 32 enum Result { |
28 // Successful operation. | 33 // Successful operation. |
29 SUCCESS, | 34 SUCCESS, |
30 // Invalid parameter. | 35 // Invalid parameter. |
31 INVALID_PARAMETER, | 36 INVALID_PARAMETER, |
(...skipping 11 matching lines...) Expand all Loading... | |
43 | 48 |
44 // Asynchronous callbacks. Must not synchronously delete |this| (using | 49 // Asynchronous callbacks. Must not synchronously delete |this| (using |
45 // InstanceIDDriver::RemoveInstanceID). | 50 // InstanceIDDriver::RemoveInstanceID). |
46 typedef base::Callback<void(const std::string& app_id, | 51 typedef base::Callback<void(const std::string& app_id, |
47 bool update_id)> TokenRefreshCallback; | 52 bool update_id)> TokenRefreshCallback; |
48 typedef base::Callback<void(const std::string& id)> GetIDCallback; | 53 typedef base::Callback<void(const std::string& id)> GetIDCallback; |
49 typedef base::Callback<void(const base::Time& creation_time)> | 54 typedef base::Callback<void(const base::Time& creation_time)> |
50 GetCreationTimeCallback; | 55 GetCreationTimeCallback; |
51 typedef base::Callback<void(const std::string& token, | 56 typedef base::Callback<void(const std::string& token, |
52 Result result)> GetTokenCallback; | 57 Result result)> GetTokenCallback; |
58 typedef base::Callback<void(const std::string&, const std::string&)> | |
59 GetEncryptionInfoCallback; | |
53 typedef base::Callback<void(Result result)> DeleteTokenCallback; | 60 typedef base::Callback<void(Result result)> DeleteTokenCallback; |
54 typedef base::Callback<void(Result result)> DeleteIDCallback; | 61 typedef base::Callback<void(Result result)> DeleteIDCallback; |
55 | 62 |
56 static const int kInstanceIDByteLength = 8; | 63 static const int kInstanceIDByteLength = 8; |
57 | 64 |
58 // Creator. | 65 // Creator. |
59 // |app_id|: identifies the application that uses the Instance ID. | 66 // |app_id|: identifies the application that uses the Instance ID. |
60 // |handler|: provides the GCM functionality needed to support Instance ID. | 67 // |handler|: provides the GCM functionality needed to support Instance ID. |
61 // Must outlive this class. On Android, this can be null instead. | 68 // Must outlive this class. On Android, this can be null instead. |
62 static std::unique_ptr<InstanceID> Create(const std::string& app_id, | 69 static std::unique_ptr<InstanceID> Create(const std::string& app_id, |
63 gcm::InstanceIDHandler* handler); | 70 gcm::GCMDriver* gcm_driver); |
64 | 71 |
65 virtual ~InstanceID(); | 72 virtual ~InstanceID(); |
66 | 73 |
67 // Sets the callback that will be invoked when the token refresh event needs | 74 // Sets the callback that will be invoked when the token refresh event needs |
68 // to be triggered. | 75 // to be triggered. |
69 void SetTokenRefreshCallback(const TokenRefreshCallback& callback); | 76 void SetTokenRefreshCallback(const TokenRefreshCallback& callback); |
70 | 77 |
71 // Returns the Instance ID. | 78 // Returns the Instance ID. |
72 virtual void GetID(const GetIDCallback& callback) = 0; | 79 virtual void GetID(const GetIDCallback& callback) = 0; |
73 | 80 |
74 // Returns the time when the InstanceID has been generated. | 81 // Returns the time when the InstanceID has been generated. |
75 virtual void GetCreationTime(const GetCreationTimeCallback& callback) = 0; | 82 virtual void GetCreationTime(const GetCreationTimeCallback& callback) = 0; |
76 | 83 |
77 // Retrieves a token that allows the authorized entity to access the service | 84 // Retrieves a token that allows the authorized entity to access the service |
78 // defined as "scope". | 85 // defined as "scope". |
79 // |authorized_entity|: identifies the entity that is authorized to access | 86 // |authorized_entity|: identifies the entity that is authorized to access |
80 // resources associated with this Instance ID. It can be | 87 // resources associated with this Instance ID. It can be |
81 // another Instance ID or a project ID. | 88 // another Instance ID or a project ID. |
82 // |scope|: identifies authorized actions that the authorized entity can take. | 89 // |scope|: identifies authorized actions that the authorized entity can take. |
83 // E.g. for sending GCM messages, "GCM" scope should be used. | 90 // E.g. for sending GCM messages, "GCM" scope should be used. |
84 // |options|: allows including a small number of string key/value pairs that | 91 // |options|: allows including a small number of string key/value pairs that |
85 // will be associated with the token and may be used in processing | 92 // will be associated with the token and may be used in processing |
86 // the request. | 93 // the request. |
87 // |callback|: to be called once the asynchronous operation is done. | 94 // |callback|: to be called once the asynchronous operation is done. |
88 virtual void GetToken(const std::string& authorized_entity, | 95 virtual void GetToken(const std::string& authorized_entity, |
89 const std::string& scope, | 96 const std::string& scope, |
90 const std::map<std::string, std::string>& options, | 97 const std::map<std::string, std::string>& options, |
91 const GetTokenCallback& callback) = 0; | 98 const GetTokenCallback& callback) = 0; |
92 | 99 |
100 // Get the public encryption key and the authentication secret associated with | |
101 // a GCM-scoped token. If encryption info is not yet associated, it will be | |
102 // created. The |callback| will be invoked when it is available. Only use with | |
103 // InstanceID tokens; use GCMDriver::GetEncryptionInfo for GCM registrations. | |
Peter Beverloo
2016/05/11 16:05:00
This is a non-static method on the InstanceID clas
johnme
2016/05/13 16:25:45
Fair. I'll keep the reverse comment though, since
| |
104 void GetEncryptionInfo(const std::string& authorized_entity, | |
105 const GetEncryptionInfoCallback& callback); | |
106 | |
93 // Revokes a granted token. | 107 // Revokes a granted token. |
94 // |authorized_entity|: the authorized entity that is passed for obtaining a | 108 // |authorized_entity|: the authorized entity that is passed for obtaining a |
95 // token. | 109 // token. |
96 // |scope|: the scope that is passed for obtaining a token. | 110 // |scope|: the scope that is passed for obtaining a token. |
97 // |callback|: to be called once the asynchronous operation is done. | 111 // |callback|: to be called once the asynchronous operation is done. |
98 virtual void DeleteToken(const std::string& authorized_entity, | 112 void DeleteToken(const std::string& authorized_entity, |
99 const std::string& scope, | 113 const std::string& scope, |
100 const DeleteTokenCallback& callback) = 0; | 114 const DeleteTokenCallback& callback); |
101 | 115 |
102 // Resets the app instance identifier and revokes all tokens associated with | 116 // Resets the app instance identifier and revokes all tokens associated with |
103 // it. | 117 // it. |
104 // |callback|: to be called once the asynchronous operation is done. | 118 // |callback|: to be called once the asynchronous operation is done. |
105 virtual void DeleteID(const DeleteIDCallback& callback) = 0; | 119 void DeleteID(const DeleteIDCallback& callback); |
106 | 120 |
107 std::string app_id() const { return app_id_; } | 121 std::string app_id() const { return app_id_; } |
108 | 122 |
109 protected: | 123 protected: |
110 InstanceID(const std::string& app_id); | 124 InstanceID(const std::string& app_id, gcm::GCMDriver* gcm_driver); |
125 | |
126 // Platform-specific implementations. | |
127 virtual void DeleteTokenImpl(const std::string& authorized_entity, | |
128 const std::string& scope, | |
129 const DeleteTokenCallback& callback) = 0; | |
130 virtual void DeleteIDImpl(const DeleteIDCallback& callback) = 0; | |
111 | 131 |
112 void NotifyTokenRefresh(bool update_id); | 132 void NotifyTokenRefresh(bool update_id); |
113 | 133 |
134 gcm::GCMDriver* gcm_driver() { return gcm_driver_; } | |
135 | |
114 private: | 136 private: |
137 void DidDelete(const std::string& authorized_entity, | |
138 const base::Callback<void(Result result)>& callback, | |
139 Result result); | |
140 | |
141 // Owned by GCMProfileServiceFactory, which is a dependency of | |
142 // InstanceIDProfileServiceFactory, which owns this. | |
143 gcm::GCMDriver* gcm_driver_; | |
144 | |
115 std::string app_id_; | 145 std::string app_id_; |
116 TokenRefreshCallback token_refresh_callback_; | 146 TokenRefreshCallback token_refresh_callback_; |
117 | 147 |
148 base::WeakPtrFactory<InstanceID> weak_ptr_factory_; | |
149 | |
118 DISALLOW_COPY_AND_ASSIGN(InstanceID); | 150 DISALLOW_COPY_AND_ASSIGN(InstanceID); |
119 }; | 151 }; |
120 | 152 |
121 } // namespace instance_id | 153 } // namespace instance_id |
122 | 154 |
123 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ | 155 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ |
OLD | NEW |