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 <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 | 15 |
16 namespace gcm { | 16 namespace gcm { |
17 class GCMDriver; | 17 class InstanceIDHandler; |
18 } // namespace gcm | 18 } // namespace gcm |
19 | 19 |
20 namespace instance_id { | 20 namespace instance_id { |
21 | 21 |
22 // Encapsulates Instance ID functionalities that need to be implemented for | 22 // Encapsulates Instance ID functionalities that need to be implemented for |
23 // different platform. One instance is created per application. Life of | 23 // different platform. One instance is created per application. Life of |
24 // Instance ID is managed by the InstanceIdDriver. | 24 // Instance ID is managed by the InstanceIdDriver. |
25 class InstanceID { | 25 class InstanceID { |
26 public: | 26 public: |
27 enum Result { | 27 enum Result { |
(...skipping 21 matching lines...) Expand all Loading... | |
49 GetCreationTimeCallback; | 49 GetCreationTimeCallback; |
50 typedef base::Callback<void(const std::string& token, | 50 typedef base::Callback<void(const std::string& token, |
51 Result result)> GetTokenCallback; | 51 Result result)> GetTokenCallback; |
52 typedef base::Callback<void(Result result)> DeleteTokenCallback; | 52 typedef base::Callback<void(Result result)> DeleteTokenCallback; |
53 typedef base::Callback<void(Result result)> DeleteIDCallback; | 53 typedef base::Callback<void(Result result)> DeleteIDCallback; |
54 | 54 |
55 static const int kInstanceIDByteLength = 8; | 55 static const int kInstanceIDByteLength = 8; |
56 | 56 |
57 // Creator. | 57 // Creator. |
58 // |app_id|: identifies the application that uses the Instance ID. | 58 // |app_id|: identifies the application that uses the Instance ID. |
59 // |gcm_driver|: driver to access the GCM functionalities needed to support | 59 // |gcm_driver|: driver to access the GCM functionalities needed to support |
Peter Beverloo
2016/03/11 16:10:19
Please update this comment.
johnme
2016/03/11 17:53:23
Done.
| |
60 // Instance ID. | 60 // Instance ID. Its InstanceIDHandler must outlive this class. |
61 static scoped_ptr<InstanceID> Create(const std::string& app_id, | 61 static scoped_ptr<InstanceID> Create(const std::string& app_id, |
62 gcm::GCMDriver* gcm_driver); | 62 gcm::InstanceIDHandler* handler); |
63 | 63 |
64 virtual ~InstanceID(); | 64 virtual ~InstanceID(); |
65 | 65 |
66 // Sets the callback that will be invoked when the token refresh event needs | 66 // Sets the callback that will be invoked when the token refresh event needs |
67 // to be triggered. | 67 // to be triggered. |
68 void SetTokenRefreshCallback(const TokenRefreshCallback& callback); | 68 void SetTokenRefreshCallback(const TokenRefreshCallback& callback); |
69 | 69 |
70 // Returns the Instance ID. | 70 // Returns the Instance ID. |
71 virtual void GetID(const GetIDCallback& callback) = 0; | 71 virtual void GetID(const GetIDCallback& callback) = 0; |
72 | 72 |
(...skipping 26 matching lines...) Expand all Loading... | |
99 const DeleteTokenCallback& callback) = 0; | 99 const DeleteTokenCallback& callback) = 0; |
100 | 100 |
101 // Resets the app instance identifier and revokes all tokens associated with | 101 // Resets the app instance identifier and revokes all tokens associated with |
102 // it. | 102 // it. |
103 // |callback|: to be called once the asynchronous operation is done. | 103 // |callback|: to be called once the asynchronous operation is done. |
104 virtual void DeleteID(const DeleteIDCallback& callback) = 0; | 104 virtual void DeleteID(const DeleteIDCallback& callback) = 0; |
105 | 105 |
106 std::string app_id() const { return app_id_; } | 106 std::string app_id() const { return app_id_; } |
107 | 107 |
108 protected: | 108 protected: |
109 explicit InstanceID(const std::string& app_id); | 109 InstanceID(const std::string& app_id, gcm::InstanceIDHandler* handler); |
110 | 110 |
111 void NotifyTokenRefresh(bool update_id); | 111 void NotifyTokenRefresh(bool update_id); |
112 | 112 |
113 gcm::InstanceIDHandler* handler() { return handler_; } | |
Peter Beverloo
2016/03/11 16:10:19
Can this be const? (Like the method you're replaci
johnme
2016/03/11 17:53:22
Done.
| |
114 | |
113 private: | 115 private: |
116 gcm::InstanceIDHandler* handler_; // Not owned. | |
Peter Beverloo
2016/03/11 16:10:19
Personally I would prefer documenting *why* it's s
johnme
2016/03/11 17:53:23
Done: "
// Owned by GCMProfileServiceFactory, whic
| |
114 std::string app_id_; | 117 std::string app_id_; |
115 TokenRefreshCallback token_refresh_callback_; | 118 TokenRefreshCallback token_refresh_callback_; |
116 | 119 |
117 DISALLOW_COPY_AND_ASSIGN(InstanceID); | 120 DISALLOW_COPY_AND_ASSIGN(InstanceID); |
118 }; | 121 }; |
119 | 122 |
120 } // namespace instance_id | 123 } // namespace instance_id |
121 | 124 |
122 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ | 125 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ |
OLD | NEW |