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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_
6 #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
20 namespace instance_id
{
22 // Encapsulates Instance ID functionalities that need to be implemented for
23 // different platform. One instance is created per application. Life of
24 // Instance ID is managed by the InstanceIdDriver.
28 // Successful operation.
32 // Instance ID is disabled.
34 // Previous asynchronous operation is still pending to finish.
35 ASYNC_OPERATION_PENDING
,
36 // Network socket error.
38 // Problem at the server.
44 // Asynchronous callbacks.
45 typedef base::Callback
<void(const std::string
& app_id
,
46 bool update_id
)> TokenRefreshCallback
;
47 typedef base::Callback
<void(const std::string
& id
)> GetIDCallback
;
48 typedef base::Callback
<void(const base::Time
& creation_time
)>
49 GetCreationTimeCallback
;
50 typedef base::Callback
<void(const std::string
& token
,
51 Result result
)> GetTokenCallback
;
52 typedef base::Callback
<void(Result result
)> DeleteTokenCallback
;
53 typedef base::Callback
<void(Result result
)> DeleteIDCallback
;
55 static const int kInstanceIDByteLength
= 8;
58 // |app_id|: identifies the application that uses the Instance ID.
59 // |gcm_driver|: driver to access the GCM functionalities needed to support
61 static scoped_ptr
<InstanceID
> Create(const std::string
& app_id
,
62 gcm::GCMDriver
* gcm_driver
);
64 virtual ~InstanceID();
66 // Sets the callback that will be invoked when the token refresh event needs
68 void SetTokenRefreshCallback(const TokenRefreshCallback
& callback
);
70 // Returns the Instance ID.
71 virtual void GetID(const GetIDCallback
& callback
) = 0;
73 // Returns the time when the InstanceID has been generated.
74 virtual void GetCreationTime(const GetCreationTimeCallback
& callback
) = 0;
76 // Retrieves a token that allows the authorized entity to access the service
77 // defined as "scope".
78 // |authorized_entity|: identifies the entity that is authorized to access
79 // resources associated with this Instance ID. It can be
80 // another Instance ID or a project ID.
81 // |scope|: identifies authorized actions that the authorized entity can take.
82 // E.g. for sending GCM messages, "GCM" scope should be used.
83 // |options|: allows including a small number of string key/value pairs that
84 // will be associated with the token and may be used in processing
86 // |callback|: to be called once the asynchronous operation is done.
87 virtual void GetToken(const std::string
& authorized_entity
,
88 const std::string
& scope
,
89 const std::map
<std::string
, std::string
>& options
,
90 const GetTokenCallback
& callback
) = 0;
92 // Revokes a granted token.
93 // |authorized_entity|: the authorized entity that is passed for obtaining a
95 // |scope|: the scope that is passed for obtaining a token.
96 // |callback|: to be called once the asynchronous operation is done.
97 virtual void DeleteToken(const std::string
& authorized_entity
,
98 const std::string
& scope
,
99 const DeleteTokenCallback
& callback
) = 0;
101 // Resets the app instance identifier and revokes all tokens associated with
103 // |callback|: to be called once the asynchronous operation is done.
104 virtual void DeleteID(const DeleteIDCallback
& callback
) = 0;
106 std::string
app_id() const { return app_id_
; }
109 explicit InstanceID(const std::string
& app_id
);
111 void NotifyTokenRefresh(bool update_id
);
115 TokenRefreshCallback token_refresh_callback_
;
117 DISALLOW_COPY_AND_ASSIGN(InstanceID
);
120 } // namespace instance_id
122 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_