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 CHROME_BROWSER_EXTENSIONS_API_INSTANCE_ID_INSTANCE_ID_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_INSTANCE_ID_INSTANCE_ID_API_H_
8 #include "base/macros.h"
9 #include "components/gcm_driver/instance_id/instance_id.h"
10 #include "extensions/browser/extension_function.h"
14 namespace extensions
{
16 class InstanceIDApiFunction
: public UIThreadExtensionFunction
{
18 InstanceIDApiFunction();
21 ~InstanceIDApiFunction() override
;
24 ResponseAction
Run() override
;
26 // Actual implementation of specific functions.
27 virtual ResponseAction
DoWork() = 0;
29 // Checks whether the InstanceID API is enabled.
30 bool IsEnabled() const;
32 instance_id::InstanceID
* GetInstanceID() const;
34 DISALLOW_COPY_AND_ASSIGN(InstanceIDApiFunction
);
37 class InstanceIDGetIDFunction
: public InstanceIDApiFunction
{
39 DECLARE_EXTENSION_FUNCTION("instanceID.getID", INSTANCEID_GETID
);
41 InstanceIDGetIDFunction();
44 ~InstanceIDGetIDFunction() override
;
46 // InstanceIDApiFunction:
47 ResponseAction
DoWork() override
;
50 void GetIDCompleted(const std::string
& id
);
52 DISALLOW_COPY_AND_ASSIGN(InstanceIDGetIDFunction
);
55 class InstanceIDGetCreationTimeFunction
: public InstanceIDApiFunction
{
57 DECLARE_EXTENSION_FUNCTION("instanceID.getCreationTime",
58 INSTANCEID_GETCREATIONTIME
);
60 InstanceIDGetCreationTimeFunction();
63 ~InstanceIDGetCreationTimeFunction() override
;
65 // InstanceIDApiFunction:
66 ResponseAction
DoWork() override
;
69 void GetCreationTimeCompleted(const base::Time
& creation_time
);
71 DISALLOW_COPY_AND_ASSIGN(InstanceIDGetCreationTimeFunction
);
74 class InstanceIDGetTokenFunction
: public InstanceIDApiFunction
{
76 DECLARE_EXTENSION_FUNCTION("instanceID.getToken", INSTANCEID_GETTOKEN
);
78 InstanceIDGetTokenFunction();
81 ~InstanceIDGetTokenFunction() override
;
83 // InstanceIDApiFunction:
84 ResponseAction
DoWork() override
;
87 void GetTokenCompleted(const std::string
& token
,
88 instance_id::InstanceID::Result result
);
90 DISALLOW_COPY_AND_ASSIGN(InstanceIDGetTokenFunction
);
93 class InstanceIDDeleteTokenFunction
: public InstanceIDApiFunction
{
95 DECLARE_EXTENSION_FUNCTION("instanceID.deleteToken", INSTANCEID_DELETETOKEN
);
97 InstanceIDDeleteTokenFunction();
100 ~InstanceIDDeleteTokenFunction() override
;
102 // InstanceIDApiFunction:
103 ResponseAction
DoWork() override
;
106 void DeleteTokenCompleted(instance_id::InstanceID::Result result
);
108 DISALLOW_COPY_AND_ASSIGN(InstanceIDDeleteTokenFunction
);
111 class InstanceIDDeleteIDFunction
: public InstanceIDApiFunction
{
113 DECLARE_EXTENSION_FUNCTION("instanceID.deleteID",
114 INSTANCEID_DELETEID
);
116 InstanceIDDeleteIDFunction();
119 ~InstanceIDDeleteIDFunction() override
;
121 // InstanceIDApiFunction:
122 ResponseAction
DoWork() override
;
125 void DeleteIDCompleted(instance_id::InstanceID::Result result
);
127 DISALLOW_COPY_AND_ASSIGN(InstanceIDDeleteIDFunction
);
130 } // namespace extensions
132 #endif // CHROME_BROWSER_EXTENSIONS_API_INSTANCE_ID_INSTANCE_ID_API_H_