Chromium Code Reviews| 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 GCMDriver; |
| 18 class InstanceIDHandler; | |
| 18 } // namespace gcm | 19 } // namespace gcm |
| 19 | 20 |
| 20 namespace instance_id { | 21 namespace instance_id { |
| 21 | 22 |
| 22 // Encapsulates Instance ID functionalities that need to be implemented for | 23 // Encapsulates Instance ID functionalities that need to be implemented for |
| 23 // different platform. One instance is created per application. Life of | 24 // different platform. One instance is created per application. Life of |
| 24 // Instance ID is managed by the InstanceIdDriver. | 25 // Instance ID is managed by the InstanceIdDriver. |
| 25 class InstanceID { | 26 class InstanceID { |
| 26 public: | 27 public: |
| 27 enum Result { | 28 enum Result { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 50 typedef base::Callback<void(const std::string& token, | 51 typedef base::Callback<void(const std::string& token, |
| 51 Result result)> GetTokenCallback; | 52 Result result)> GetTokenCallback; |
| 52 typedef base::Callback<void(Result result)> DeleteTokenCallback; | 53 typedef base::Callback<void(Result result)> DeleteTokenCallback; |
| 53 typedef base::Callback<void(Result result)> DeleteIDCallback; | 54 typedef base::Callback<void(Result result)> DeleteIDCallback; |
| 54 | 55 |
| 55 static const int kInstanceIDByteLength = 8; | 56 static const int kInstanceIDByteLength = 8; |
| 56 | 57 |
| 57 // Creator. | 58 // Creator. |
| 58 // |app_id|: identifies the application that uses the Instance ID. | 59 // |app_id|: identifies the application that uses the Instance ID. |
| 59 // |gcm_driver|: driver to access the GCM functionalities needed to support | 60 // |gcm_driver|: driver to access the GCM functionalities needed to support |
| 60 // Instance ID. | 61 // Instance ID. Its InstanceIDHandler must outlive this class. |
| 61 static scoped_ptr<InstanceID> Create(const std::string& app_id, | 62 static scoped_ptr<InstanceID> Create(const std::string& app_id, |
| 62 gcm::GCMDriver* gcm_driver); | 63 gcm::GCMDriver* gcm_driver); |
| 63 | 64 |
| 64 virtual ~InstanceID(); | 65 virtual ~InstanceID(); |
| 65 | 66 |
| 66 // Sets the callback that will be invoked when the token refresh event needs | 67 // Sets the callback that will be invoked when the token refresh event needs |
| 67 // to be triggered. | 68 // to be triggered. |
| 68 void SetTokenRefreshCallback(const TokenRefreshCallback& callback); | 69 void SetTokenRefreshCallback(const TokenRefreshCallback& callback); |
| 69 | 70 |
| 70 // Returns the Instance ID. | 71 // Returns the Instance ID. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 99 const DeleteTokenCallback& callback) = 0; | 100 const DeleteTokenCallback& callback) = 0; |
| 100 | 101 |
| 101 // Resets the app instance identifier and revokes all tokens associated with | 102 // Resets the app instance identifier and revokes all tokens associated with |
| 102 // it. | 103 // it. |
| 103 // |callback|: to be called once the asynchronous operation is done. | 104 // |callback|: to be called once the asynchronous operation is done. |
| 104 virtual void DeleteID(const DeleteIDCallback& callback) = 0; | 105 virtual void DeleteID(const DeleteIDCallback& callback) = 0; |
| 105 | 106 |
| 106 std::string app_id() const { return app_id_; } | 107 std::string app_id() const { return app_id_; } |
| 107 | 108 |
| 108 protected: | 109 protected: |
| 109 explicit InstanceID(const std::string& app_id); | 110 InstanceID(const std::string& app_id, gcm::GCMDriver* gcm_driver); |
|
Peter Beverloo
2016/03/10 21:11:23
As discussed, let's limit knowledge and have this
johnme
2016/03/11 15:56:04
Done.
| |
| 110 | 111 |
| 111 void NotifyTokenRefresh(bool update_id); | 112 void NotifyTokenRefresh(bool update_id); |
| 112 | 113 |
| 114 gcm::InstanceIDHandler* handler_; // Not owned. | |
|
Peter Beverloo
2016/03/10 21:11:23
Per the styleguide:
""Limit the use of protected
johnme
2016/03/11 15:56:04
Done.
| |
| 115 | |
| 113 private: | 116 private: |
| 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 |