Stack sampling profiler: add fire-and-forget interface
[chromium-blink-merge.git] / components / gcm_driver / instance_id / instance_id.h
blob9adf0e5def2604150b45e9a3f99fdbe5614cc9ee
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_
8 #include <map>
9 #include <string>
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
16 namespace gcm {
17 class GCMDriver;
18 } // namespace gcm
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.
25 class InstanceID {
26 public:
27 enum Result {
28 // Successful operation.
29 SUCCESS,
30 // Invalid parameter.
31 INVALID_PARAMETER,
32 // Instance ID is disabled.
33 DISABLED,
34 // Previous asynchronous operation is still pending to finish.
35 ASYNC_OPERATION_PENDING,
36 // Network socket error.
37 NETWORK_ERROR,
38 // Problem at the server.
39 SERVER_ERROR,
40 // Other errors.
41 UNKNOWN_ERROR
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;
57 // Creator.
58 // |app_id|: identifies the application that uses the Instance ID.
59 // |gcm_driver|: driver to access the GCM functionalities needed to support
60 // Instance ID.
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
67 // to be triggered.
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
85 // the request.
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
94 // token.
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
102 // it.
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_; }
108 protected:
109 explicit InstanceID(const std::string& app_id);
111 void NotifyTokenRefresh(bool update_id);
113 private:
114 std::string app_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_