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

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

Issue 1923953002: Integrate InstanceID with GCM crypto provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid5default
Patch Set: RunUntilIdle after deleting GCMDriver Created 4 years, 6 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
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 extern const char kGCMScope[];
24
22 // Encapsulates Instance ID functionalities that need to be implemented for 25 // Encapsulates Instance ID functionalities that need to be implemented for
23 // different platforms. One instance is created per application. Life of 26 // different platforms. One instance is created per application. Life of
24 // Instance ID is managed by the InstanceIDDriver. 27 // Instance ID is managed by the InstanceIDDriver.
25 class InstanceID { 28 class InstanceID {
26 public: 29 public:
27 enum Result { 30 enum Result {
28 // Successful operation. 31 // Successful operation.
29 SUCCESS, 32 SUCCESS,
30 // Invalid parameter. 33 // Invalid parameter.
31 INVALID_PARAMETER, 34 INVALID_PARAMETER,
(...skipping 11 matching lines...) Expand all
43 46
44 // Asynchronous callbacks. Must not synchronously delete |this| (using 47 // Asynchronous callbacks. Must not synchronously delete |this| (using
45 // InstanceIDDriver::RemoveInstanceID). 48 // InstanceIDDriver::RemoveInstanceID).
46 typedef base::Callback<void(const std::string& app_id, 49 typedef base::Callback<void(const std::string& app_id,
47 bool update_id)> TokenRefreshCallback; 50 bool update_id)> TokenRefreshCallback;
48 typedef base::Callback<void(const std::string& id)> GetIDCallback; 51 typedef base::Callback<void(const std::string& id)> GetIDCallback;
49 typedef base::Callback<void(const base::Time& creation_time)> 52 typedef base::Callback<void(const base::Time& creation_time)>
50 GetCreationTimeCallback; 53 GetCreationTimeCallback;
51 typedef base::Callback<void(const std::string& token, 54 typedef base::Callback<void(const std::string& token,
52 Result result)> GetTokenCallback; 55 Result result)> GetTokenCallback;
56 typedef base::Callback<void(const std::string&, const std::string&)>
57 GetEncryptionInfoCallback;
53 typedef base::Callback<void(Result result)> DeleteTokenCallback; 58 typedef base::Callback<void(Result result)> DeleteTokenCallback;
54 typedef base::Callback<void(Result result)> DeleteIDCallback; 59 typedef base::Callback<void(Result result)> DeleteIDCallback;
55 60
56 static const int kInstanceIDByteLength = 8; 61 static const int kInstanceIDByteLength = 8;
57 62
58 // Creator. 63 // Creator.
59 // |app_id|: identifies the application that uses the Instance ID. 64 // |app_id|: identifies the application that uses the Instance ID.
60 // |handler|: provides the GCM functionality needed to support Instance ID. 65 // |handler|: provides the GCM functionality needed to support Instance ID.
61 // Must outlive this class. On Android, this can be null instead. 66 // Must outlive this class. On Android, this can be null instead.
62 static std::unique_ptr<InstanceID> Create(const std::string& app_id, 67 static std::unique_ptr<InstanceID> Create(const std::string& app_id,
63 gcm::InstanceIDHandler* handler); 68 gcm::GCMDriver* gcm_driver);
64 69
65 virtual ~InstanceID(); 70 virtual ~InstanceID();
66 71
67 // Sets the callback that will be invoked when the token refresh event needs 72 // Sets the callback that will be invoked when the token refresh event needs
68 // to be triggered. 73 // to be triggered.
69 void SetTokenRefreshCallback(const TokenRefreshCallback& callback); 74 void SetTokenRefreshCallback(const TokenRefreshCallback& callback);
70 75
71 // Returns the Instance ID. 76 // Returns the Instance ID.
72 virtual void GetID(const GetIDCallback& callback) = 0; 77 virtual void GetID(const GetIDCallback& callback) = 0;
73 78
74 // Returns the time when the InstanceID has been generated. 79 // Returns the time when the InstanceID has been generated.
75 virtual void GetCreationTime(const GetCreationTimeCallback& callback) = 0; 80 virtual void GetCreationTime(const GetCreationTimeCallback& callback) = 0;
76 81
77 // Retrieves a token that allows the authorized entity to access the service 82 // Retrieves a token that allows the authorized entity to access the service
78 // defined as "scope". 83 // defined as "scope".
79 // |authorized_entity|: identifies the entity that is authorized to access 84 // |authorized_entity|: identifies the entity that is authorized to access
80 // resources associated with this Instance ID. It can be 85 // resources associated with this Instance ID. It can be
81 // another Instance ID or a project ID. 86 // another Instance ID or a project ID.
82 // |scope|: identifies authorized actions that the authorized entity can take. 87 // |scope|: identifies authorized actions that the authorized entity can take.
83 // E.g. for sending GCM messages, "GCM" scope should be used. 88 // E.g. for sending GCM messages, "GCM" scope should be used.
84 // |options|: allows including a small number of string key/value pairs that 89 // |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 90 // will be associated with the token and may be used in processing
86 // the request. 91 // the request.
87 // |callback|: to be called once the asynchronous operation is done. 92 // |callback|: to be called once the asynchronous operation is done.
88 virtual void GetToken(const std::string& authorized_entity, 93 virtual void GetToken(const std::string& authorized_entity,
89 const std::string& scope, 94 const std::string& scope,
90 const std::map<std::string, std::string>& options, 95 const std::map<std::string, std::string>& options,
91 const GetTokenCallback& callback) = 0; 96 const GetTokenCallback& callback) = 0;
92 97
98 // Get the public encryption key and authentication secret associated with a
99 // GCM-scoped token. If encryption info is not yet associated, it will be
100 // created.
101 // |authorized_entity|: the authorized entity passed when obtaining the token.
102 // |callback|: to be called once the asynchronous operation is done.
103 void GetEncryptionInfo(const std::string& authorized_entity,
104 const GetEncryptionInfoCallback& callback);
105
93 // Revokes a granted token. 106 // Revokes a granted token.
94 // |authorized_entity|: the authorized entity that is passed for obtaining a 107 // |authorized_entity|: the authorized entity passed when obtaining the token.
95 // token. 108 // |scope|: the scope that was passed when obtaining the token.
96 // |scope|: the scope that is passed for obtaining a token.
97 // |callback|: to be called once the asynchronous operation is done. 109 // |callback|: to be called once the asynchronous operation is done.
98 virtual void DeleteToken(const std::string& authorized_entity, 110 void DeleteToken(const std::string& authorized_entity,
99 const std::string& scope, 111 const std::string& scope,
100 const DeleteTokenCallback& callback) = 0; 112 const DeleteTokenCallback& callback);
101 113
102 // Resets the app instance identifier and revokes all tokens associated with 114 // Resets the app instance identifier and revokes all tokens associated with
103 // it. 115 // it.
104 // |callback|: to be called once the asynchronous operation is done. 116 // |callback|: to be called once the asynchronous operation is done.
105 virtual void DeleteID(const DeleteIDCallback& callback) = 0; 117 void DeleteID(const DeleteIDCallback& callback);
106 118
107 std::string app_id() const { return app_id_; } 119 std::string app_id() const { return app_id_; }
108 120
109 protected: 121 protected:
110 InstanceID(const std::string& app_id); 122 InstanceID(const std::string& app_id, gcm::GCMDriver* gcm_driver);
123
124 // Platform-specific implementations.
125 virtual void DeleteTokenImpl(const std::string& authorized_entity,
126 const std::string& scope,
127 const DeleteTokenCallback& callback) = 0;
128 virtual void DeleteIDImpl(const DeleteIDCallback& callback) = 0;
111 129
112 void NotifyTokenRefresh(bool update_id); 130 void NotifyTokenRefresh(bool update_id);
113 131
132 gcm::GCMDriver* gcm_driver() { return gcm_driver_; }
133
114 private: 134 private:
135 void DidDelete(const std::string& authorized_entity,
136 const base::Callback<void(Result result)>& callback,
137 Result result);
138
139 // Owned by GCMProfileServiceFactory, which is a dependency of
140 // InstanceIDProfileServiceFactory, which owns this.
141 gcm::GCMDriver* gcm_driver_;
142
115 std::string app_id_; 143 std::string app_id_;
116 TokenRefreshCallback token_refresh_callback_; 144 TokenRefreshCallback token_refresh_callback_;
117 145
146 base::WeakPtrFactory<InstanceID> weak_ptr_factory_;
147
118 DISALLOW_COPY_AND_ASSIGN(InstanceID); 148 DISALLOW_COPY_AND_ASSIGN(InstanceID);
119 }; 149 };
120 150
121 } // namespace instance_id 151 } // namespace instance_id
122 152
123 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ 153 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_
OLDNEW
« no previous file with comments | « components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.cc ('k') | components/gcm_driver/instance_id/instance_id.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698