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 CHROME_BROWSER_EXTENSIONS_API_INSTANCE_ID_INSTANCE_ID_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_INSTANCE_ID_INSTANCE_ID_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_INSTANCE_ID_INSTANCE_ID_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_INSTANCE_ID_INSTANCE_ID_API_H_ |
7 | 7 |
| 8 #include "base/macros.h" |
| 9 #include "components/gcm_driver/instance_id/instance_id.h" |
8 #include "extensions/browser/extension_function.h" | 10 #include "extensions/browser/extension_function.h" |
9 | 11 |
10 class Profile; | 12 class Profile; |
11 | 13 |
12 namespace extensions { | 14 namespace extensions { |
13 | 15 |
14 class InstanceIDGetIDFunction : public UIThreadExtensionFunction { | 16 class InstanceIDApiFunction : public UIThreadExtensionFunction { |
| 17 public: |
| 18 InstanceIDApiFunction(); |
| 19 |
| 20 protected: |
| 21 ~InstanceIDApiFunction() override; |
| 22 |
| 23 // ExtensionFunction: |
| 24 ResponseAction Run() override; |
| 25 |
| 26 // Actual implementation of specific functions. |
| 27 virtual ResponseAction DoWork() = 0; |
| 28 |
| 29 // Checks whether the InstanceID API is enabled. |
| 30 bool IsEnabled() const; |
| 31 |
| 32 instance_id::InstanceID* GetInstanceID() const; |
| 33 |
| 34 DISALLOW_COPY_AND_ASSIGN(InstanceIDApiFunction); |
| 35 }; |
| 36 |
| 37 class InstanceIDGetIDFunction : public InstanceIDApiFunction { |
15 public: | 38 public: |
16 DECLARE_EXTENSION_FUNCTION("instanceID.getID", INSTANCEID_GETID); | 39 DECLARE_EXTENSION_FUNCTION("instanceID.getID", INSTANCEID_GETID); |
17 | 40 |
18 InstanceIDGetIDFunction(); | 41 InstanceIDGetIDFunction(); |
19 | 42 |
20 protected: | 43 protected: |
21 ~InstanceIDGetIDFunction() override; | 44 ~InstanceIDGetIDFunction() override; |
22 | 45 |
23 // ExtensionFunction: | 46 // InstanceIDApiFunction: |
24 ResponseAction Run() override; | 47 ResponseAction DoWork() override; |
| 48 |
| 49 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(InstanceIDGetIDFunction); |
25 }; | 51 }; |
26 | 52 |
27 class InstanceIDGetCreationTimeFunction : public UIThreadExtensionFunction { | 53 class InstanceIDGetCreationTimeFunction : public InstanceIDApiFunction { |
28 public: | 54 public: |
29 DECLARE_EXTENSION_FUNCTION("instanceID.getCreationTime", | 55 DECLARE_EXTENSION_FUNCTION("instanceID.getCreationTime", |
30 INSTANCEID_GETCREATIONTIME); | 56 INSTANCEID_GETCREATIONTIME); |
31 | 57 |
32 InstanceIDGetCreationTimeFunction(); | 58 InstanceIDGetCreationTimeFunction(); |
33 | 59 |
34 protected: | 60 protected: |
35 ~InstanceIDGetCreationTimeFunction() override; | 61 ~InstanceIDGetCreationTimeFunction() override; |
36 | 62 |
37 // ExtensionFunction: | 63 // InstanceIDApiFunction: |
38 ResponseAction Run() override; | 64 ResponseAction DoWork() override; |
| 65 |
| 66 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(InstanceIDGetCreationTimeFunction); |
39 }; | 68 }; |
40 | 69 |
41 class InstanceIDGetTokenFunction : public UIThreadExtensionFunction { | 70 class InstanceIDGetTokenFunction : public InstanceIDApiFunction { |
42 public: | 71 public: |
43 DECLARE_EXTENSION_FUNCTION("instanceID.getToken", INSTANCEID_GETTOKEN); | 72 DECLARE_EXTENSION_FUNCTION("instanceID.getToken", INSTANCEID_GETTOKEN); |
44 | 73 |
45 InstanceIDGetTokenFunction(); | 74 InstanceIDGetTokenFunction(); |
46 | 75 |
47 protected: | 76 protected: |
48 ~InstanceIDGetTokenFunction() override; | 77 ~InstanceIDGetTokenFunction() override; |
49 | 78 |
50 // ExtensionFunction: | 79 // InstanceIDApiFunction: |
51 ResponseAction Run() override; | 80 ResponseAction DoWork() override; |
| 81 |
| 82 private: |
| 83 void GetTokenCompleted(const std::string& token, |
| 84 instance_id::InstanceID::Result result); |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(InstanceIDGetTokenFunction); |
52 }; | 87 }; |
53 | 88 |
54 class InstanceIDDeleteTokenFunction : public UIThreadExtensionFunction { | 89 class InstanceIDDeleteTokenFunction : public InstanceIDApiFunction { |
55 public: | 90 public: |
56 DECLARE_EXTENSION_FUNCTION("instanceID.DeleteToken", INSTANCEID_DELETETOKEN); | 91 DECLARE_EXTENSION_FUNCTION("instanceID.DeleteToken", INSTANCEID_DELETETOKEN); |
57 | 92 |
58 InstanceIDDeleteTokenFunction(); | 93 InstanceIDDeleteTokenFunction(); |
59 | 94 |
60 protected: | 95 protected: |
61 ~InstanceIDDeleteTokenFunction() override; | 96 ~InstanceIDDeleteTokenFunction() override; |
62 | 97 |
63 // ExtensionFunction: | 98 // InstanceIDApiFunction: |
64 ResponseAction Run() override; | 99 ResponseAction DoWork() override; |
| 100 |
| 101 private: |
| 102 void DeleteTokenCompleted(instance_id::InstanceID::Result result); |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(InstanceIDDeleteTokenFunction); |
65 }; | 105 }; |
66 | 106 |
67 class InstanceIDDeleteIDFunction : public UIThreadExtensionFunction { | 107 class InstanceIDDeleteIDFunction : public InstanceIDApiFunction { |
68 public: | 108 public: |
69 DECLARE_EXTENSION_FUNCTION("instanceID.deleteID", | 109 DECLARE_EXTENSION_FUNCTION("instanceID.deleteID", |
70 INSTANCEID_DELETEID); | 110 INSTANCEID_DELETEID); |
71 | 111 |
72 InstanceIDDeleteIDFunction(); | 112 InstanceIDDeleteIDFunction(); |
73 | 113 |
74 protected: | 114 protected: |
75 ~InstanceIDDeleteIDFunction() override; | 115 ~InstanceIDDeleteIDFunction() override; |
76 | 116 |
77 // ExtensionFunction: | 117 // InstanceIDApiFunction: |
78 ResponseAction Run() override; | 118 ResponseAction DoWork() override; |
| 119 |
| 120 private: |
| 121 void DeleteIDCompleted(instance_id::InstanceID::Result result); |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(InstanceIDDeleteIDFunction); |
79 }; | 124 }; |
80 | 125 |
81 } // namespace extensions | 126 } // namespace extensions |
82 | 127 |
83 #endif // CHROME_BROWSER_EXTENSIONS_API_INSTANCE_ID_INSTANCE_ID_API_H_ | 128 #endif // CHROME_BROWSER_EXTENSIONS_API_INSTANCE_ID_INSTANCE_ID_API_H_ |
OLD | NEW |