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> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // 6 is omitted, in case we ever merge this enum with GCMClient::Result. | 44 // 6 is omitted, in case we ever merge this enum with GCMClient::Result. |
45 // Other errors. | 45 // Other errors. |
46 UNKNOWN_ERROR = 7, | 46 UNKNOWN_ERROR = 7, |
47 | 47 |
48 // Used for UMA. Keep LAST_RESULT up to date and sync with histograms.xml. | 48 // Used for UMA. Keep LAST_RESULT up to date and sync with histograms.xml. |
49 LAST_RESULT = UNKNOWN_ERROR | 49 LAST_RESULT = UNKNOWN_ERROR |
50 }; | 50 }; |
51 | 51 |
52 // Asynchronous callbacks. Must not synchronously delete |this| (using | 52 // Asynchronous callbacks. Must not synchronously delete |this| (using |
53 // InstanceIDDriver::RemoveInstanceID). | 53 // InstanceIDDriver::RemoveInstanceID). |
54 typedef base::Callback<void(const std::string& app_id, | 54 using TokenRefreshCallback = |
55 bool update_id)> TokenRefreshCallback; | 55 base::Callback<void(const std::string& app_id, bool update_id)>; |
56 typedef base::Callback<void(const std::string& id)> GetIDCallback; | 56 using GetIDCallback = base::Callback<void(const std::string& id)>; |
57 typedef base::Callback<void(const base::Time& creation_time)> | 57 using GetCreationTimeCallback = |
58 GetCreationTimeCallback; | 58 base::Callback<void(const base::Time& creation_time)>; |
59 typedef base::Callback<void(const std::string& token, | 59 using GetTokenCallback = |
60 Result result)> GetTokenCallback; | 60 base::Callback<void(const std::string& token, Result result)>; |
61 typedef base::Callback<void(const std::string&, const std::string&)> | 61 using ValidateTokenCallback = base::Callback<void(bool is_valid)>; |
62 GetEncryptionInfoCallback; | 62 using GetEncryptionInfoCallback = |
63 typedef base::Callback<void(Result result)> DeleteTokenCallback; | 63 base::Callback<void(const std::string&, const std::string&)>; |
64 typedef base::Callback<void(Result result)> DeleteIDCallback; | 64 using DeleteTokenCallback = base::Callback<void(Result result)>; |
| 65 using DeleteIDCallback = base::Callback<void(Result result)>; |
65 | 66 |
66 static const int kInstanceIDByteLength = 8; | 67 static const int kInstanceIDByteLength = 8; |
67 | 68 |
68 // Creator. Should only be used by InstanceIDDriver::GetInstanceID. | 69 // Creator. Should only be used by InstanceIDDriver::GetInstanceID. |
69 // |app_id|: identifies the application that uses the Instance ID. | 70 // |app_id|: identifies the application that uses the Instance ID. |
70 // |handler|: provides the GCM functionality needed to support Instance ID. | 71 // |handler|: provides the GCM functionality needed to support Instance ID. |
71 // Must outlive this class. On Android, this can be null instead. | 72 // Must outlive this class. On Android, this can be null instead. |
72 static std::unique_ptr<InstanceID> CreateInternal(const std::string& app_id, | 73 static std::unique_ptr<InstanceID> CreateInternal(const std::string& app_id, |
73 gcm::GCMDriver* gcm_driver); | 74 gcm::GCMDriver* gcm_driver); |
74 | 75 |
(...skipping 18 matching lines...) Expand all Loading... |
93 // E.g. for sending GCM messages, "GCM" scope should be used. | 94 // E.g. for sending GCM messages, "GCM" scope should be used. |
94 // |options|: allows including a small number of string key/value pairs that | 95 // |options|: allows including a small number of string key/value pairs that |
95 // will be associated with the token and may be used in processing | 96 // will be associated with the token and may be used in processing |
96 // the request. | 97 // the request. |
97 // |callback|: to be called once the asynchronous operation is done. | 98 // |callback|: to be called once the asynchronous operation is done. |
98 virtual void GetToken(const std::string& authorized_entity, | 99 virtual void GetToken(const std::string& authorized_entity, |
99 const std::string& scope, | 100 const std::string& scope, |
100 const std::map<std::string, std::string>& options, | 101 const std::map<std::string, std::string>& options, |
101 const GetTokenCallback& callback) = 0; | 102 const GetTokenCallback& callback) = 0; |
102 | 103 |
| 104 // Checks that the provided |token| matches the stored token for (|app_id()|, |
| 105 // |authorized_entity|, |scope|). |
| 106 virtual void ValidateToken(const std::string& authorized_entity, |
| 107 const std::string& scope, |
| 108 const std::string& token, |
| 109 const ValidateTokenCallback& callback) = 0; |
| 110 |
103 // Get the public encryption key and authentication secret associated with a | 111 // Get the public encryption key and authentication secret associated with a |
104 // GCM-scoped token. If encryption info is not yet associated, it will be | 112 // GCM-scoped token. If encryption info is not yet associated, it will be |
105 // created. | 113 // created. |
106 // |authorized_entity|: the authorized entity passed when obtaining the token. | 114 // |authorized_entity|: the authorized entity passed when obtaining the token. |
107 // |callback|: to be called once the asynchronous operation is done. | 115 // |callback|: to be called once the asynchronous operation is done. |
108 void GetEncryptionInfo(const std::string& authorized_entity, | 116 void GetEncryptionInfo(const std::string& authorized_entity, |
109 const GetEncryptionInfoCallback& callback); | 117 const GetEncryptionInfoCallback& callback); |
110 | 118 |
111 // Revokes a granted token. | 119 // Revokes a granted token. |
112 // |authorized_entity|: the authorized entity passed when obtaining the token. | 120 // |authorized_entity|: the authorized entity passed when obtaining the token. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 TokenRefreshCallback token_refresh_callback_; | 157 TokenRefreshCallback token_refresh_callback_; |
150 | 158 |
151 base::WeakPtrFactory<InstanceID> weak_ptr_factory_; | 159 base::WeakPtrFactory<InstanceID> weak_ptr_factory_; |
152 | 160 |
153 DISALLOW_COPY_AND_ASSIGN(InstanceID); | 161 DISALLOW_COPY_AND_ASSIGN(InstanceID); |
154 }; | 162 }; |
155 | 163 |
156 } // namespace instance_id | 164 } // namespace instance_id |
157 | 165 |
158 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ | 166 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ |
OLD | NEW |