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_IMPL_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ |
6 #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ | 6 #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "components/gcm_driver/gcm_client.h" | 16 #include "components/gcm_driver/gcm_client.h" |
17 #include "components/gcm_driver/gcm_delayed_task_controller.h" | 17 #include "components/gcm_driver/gcm_delayed_task_controller.h" |
18 #include "components/gcm_driver/instance_id/instance_id.h" | 18 #include "components/gcm_driver/instance_id/instance_id.h" |
19 | 19 |
20 namespace gcm { | 20 namespace gcm { |
21 class GCMDriver; | |
21 class InstanceIDHandler; | 22 class InstanceIDHandler; |
22 } // namespace gcm | 23 } // namespace gcm |
23 | 24 |
24 namespace instance_id { | 25 namespace instance_id { |
25 | 26 |
26 // InstanceID implementation for desktop and iOS. | 27 // InstanceID implementation for desktop and iOS. |
27 class InstanceIDImpl : public InstanceID { | 28 class InstanceIDImpl : public InstanceID { |
28 public: | 29 public: |
29 InstanceIDImpl(const std::string& app_id, gcm::InstanceIDHandler* handler); | 30 InstanceIDImpl(const std::string& app_id, gcm::GCMDriver* gcm_driver); |
30 ~InstanceIDImpl() override; | 31 ~InstanceIDImpl() override; |
31 | 32 |
32 // InstanceID: | 33 // InstanceID: |
33 void GetID(const GetIDCallback& callback) override; | 34 void GetID(const GetIDCallback& callback) override; |
34 void GetCreationTime(const GetCreationTimeCallback& callback) override; | 35 void GetCreationTime(const GetCreationTimeCallback& callback) override; |
35 void GetToken(const std::string& authorized_entity, | 36 void GetToken(const std::string& authorized_entity, |
36 const std::string& scope, | 37 const std::string& scope, |
37 const std::map<std::string, std::string>& options, | 38 const std::map<std::string, std::string>& options, |
38 const GetTokenCallback& callback) override; | 39 const GetTokenCallback& callback) override; |
39 void DeleteToken(const std::string& authorized_entity, | 40 void DeleteTokenImpl(const std::string& authorized_entity, |
40 const std::string& scope, | 41 const std::string& scope, |
41 const DeleteTokenCallback& callback) override; | 42 const DeleteTokenCallback& callback) override; |
42 void DeleteID(const DeleteIDCallback& callback) override; | 43 void DeleteIDImpl(const DeleteIDCallback& callback) override; |
43 | 44 |
44 private: | 45 private: |
45 void EnsureIDGenerated(); | 46 void EnsureIDGenerated(); |
46 | 47 |
47 void OnGetTokenCompleted(const GetTokenCallback& callback, | 48 void OnGetTokenCompleted(const GetTokenCallback& callback, |
48 const std::string& token, | 49 const std::string& token, |
49 gcm::GCMClient::Result result); | 50 gcm::GCMClient::Result result); |
50 void OnDeleteTokenCompleted(const DeleteTokenCallback& callback, | 51 void OnDeleteTokenCompleted(const DeleteTokenCallback& callback, |
51 gcm::GCMClient::Result result); | 52 gcm::GCMClient::Result result); |
52 void OnDeleteIDCompleted(const DeleteIDCallback& callback, | 53 void OnDeleteIDCompleted(const DeleteIDCallback& callback, |
53 gcm::GCMClient::Result result); | 54 gcm::GCMClient::Result result); |
54 void GetInstanceIDDataCompleted(const std::string& instance_id, | 55 void GetInstanceIDDataCompleted(const std::string& instance_id, |
55 const std::string& extra_data); | 56 const std::string& extra_data); |
56 | 57 |
57 void DoGetID(const GetIDCallback& callback); | 58 void DoGetID(const GetIDCallback& callback); |
58 void DoGetCreationTime(const GetCreationTimeCallback& callback); | 59 void DoGetCreationTime(const GetCreationTimeCallback& callback); |
59 void DoGetToken( | 60 void DoGetToken( |
60 const std::string& authorized_entity, | 61 const std::string& authorized_entity, |
61 const std::string& scope, | 62 const std::string& scope, |
62 const std::map<std::string, std::string>& options, | 63 const std::map<std::string, std::string>& options, |
63 const GetTokenCallback& callback); | 64 const GetTokenCallback& callback); |
64 void DoDeleteToken(const std::string& authorized_entity, | 65 void DoDeleteToken(const std::string& authorized_entity, |
65 const std::string& scope, | 66 const std::string& scope, |
66 const DeleteTokenCallback& callback); | 67 const DeleteTokenCallback& callback); |
67 void DoDeleteID(const DeleteIDCallback& callback); | 68 void DoDeleteID(const DeleteIDCallback& callback); |
68 | 69 |
69 // Owned by GCMProfileServiceFactory, which is a dependency of | 70 // Owned by GCMProfileServiceFactory, which is a dependency of |
70 // InstanceIDProfileServiceFactory, which owns this. | 71 // InstanceIDProfileServiceFactory, which owns this. |
71 gcm::InstanceIDHandler* handler_; | 72 gcm::InstanceIDHandler* handler_; |
Peter Beverloo
2016/05/11 16:05:00
It's a bit unfortunate that this class will now en
johnme
2016/05/13 16:25:45
Done. There's now a Handler() method.
| |
72 | 73 |
73 gcm::GCMDelayedTaskController delayed_task_controller_; | 74 gcm::GCMDelayedTaskController delayed_task_controller_; |
74 | 75 |
75 // The generated Instance ID. | 76 // The generated Instance ID. |
76 std::string id_; | 77 std::string id_; |
77 | 78 |
78 // The time when the Instance ID has been generated. | 79 // The time when the Instance ID has been generated. |
79 base::Time creation_time_; | 80 base::Time creation_time_; |
80 | 81 |
81 base::WeakPtrFactory<InstanceIDImpl> weak_ptr_factory_; | 82 base::WeakPtrFactory<InstanceIDImpl> weak_ptr_factory_; |
82 | 83 |
83 DISALLOW_COPY_AND_ASSIGN(InstanceIDImpl); | 84 DISALLOW_COPY_AND_ASSIGN(InstanceIDImpl); |
84 }; | 85 }; |
85 | 86 |
86 } // namespace instance_id | 87 } // namespace instance_id |
87 | 88 |
88 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ | 89 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ |
OLD | NEW |