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 <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.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; | |
22 class InstanceIDHandler; | 21 class InstanceIDHandler; |
23 } // namespace gcm | 22 } // namespace gcm |
24 | 23 |
25 namespace instance_id { | 24 namespace instance_id { |
26 | 25 |
27 // InstanceID implementation for desktop and iOS. | 26 // InstanceID implementation for desktop and iOS. |
28 class InstanceIDImpl : public InstanceID { | 27 class InstanceIDImpl : public InstanceID { |
29 public: | 28 public: |
30 InstanceIDImpl(const std::string& app_id, gcm::GCMDriver* gcm_driver); | 29 InstanceIDImpl(const std::string& app_id, gcm::InstanceIDHandler* handler); |
31 ~InstanceIDImpl() override; | 30 ~InstanceIDImpl() override; |
32 | 31 |
33 // InstanceID: | 32 // InstanceID: |
34 void GetID(const GetIDCallback& callback) override; | 33 void GetID(const GetIDCallback& callback) override; |
35 void GetCreationTime(const GetCreationTimeCallback& callback) override; | 34 void GetCreationTime(const GetCreationTimeCallback& callback) override; |
36 void GetToken(const std::string& authorized_entity, | 35 void GetToken(const std::string& authorized_entity, |
37 const std::string& scope, | 36 const std::string& scope, |
38 const std::map<std::string, std::string>& options, | 37 const std::map<std::string, std::string>& options, |
39 const GetTokenCallback& callback) override; | 38 const GetTokenCallback& callback) override; |
40 void DeleteToken(const std::string& authorized_entity, | 39 void DeleteToken(const std::string& authorized_entity, |
41 const std::string& scope, | 40 const std::string& scope, |
42 const DeleteTokenCallback& callback) override; | 41 const DeleteTokenCallback& callback) override; |
43 void DeleteID(const DeleteIDCallback& callback) override; | 42 void DeleteID(const DeleteIDCallback& callback) override; |
44 | 43 |
45 private: | 44 private: |
46 gcm::InstanceIDHandler* GetInstanceIDHandler() const; | |
47 | |
48 void EnsureIDGenerated(); | 45 void EnsureIDGenerated(); |
49 | 46 |
50 void OnGetTokenCompleted(const GetTokenCallback& callback, | 47 void OnGetTokenCompleted(const GetTokenCallback& callback, |
51 const std::string& token, | 48 const std::string& token, |
52 gcm::GCMClient::Result result); | 49 gcm::GCMClient::Result result); |
53 void OnDeleteTokenCompleted(const DeleteTokenCallback& callback, | 50 void OnDeleteTokenCompleted(const DeleteTokenCallback& callback, |
54 gcm::GCMClient::Result result); | 51 gcm::GCMClient::Result result); |
55 void OnDeleteIDCompleted(const DeleteIDCallback& callback, | 52 void OnDeleteIDCompleted(const DeleteIDCallback& callback, |
56 gcm::GCMClient::Result result); | 53 gcm::GCMClient::Result result); |
57 void GetInstanceIDDataCompleted(const std::string& instance_id, | 54 void GetInstanceIDDataCompleted(const std::string& instance_id, |
58 const std::string& extra_data); | 55 const std::string& extra_data); |
59 | 56 |
60 void DoGetID(const GetIDCallback& callback); | 57 void DoGetID(const GetIDCallback& callback); |
61 void DoGetCreationTime(const GetCreationTimeCallback& callback); | 58 void DoGetCreationTime(const GetCreationTimeCallback& callback); |
62 void DoGetToken( | 59 void DoGetToken( |
63 const std::string& authorized_entity, | 60 const std::string& authorized_entity, |
64 const std::string& scope, | 61 const std::string& scope, |
65 const std::map<std::string, std::string>& options, | 62 const std::map<std::string, std::string>& options, |
66 const GetTokenCallback& callback); | 63 const GetTokenCallback& callback); |
67 void DoDeleteToken(const std::string& authorized_entity, | 64 void DoDeleteToken(const std::string& authorized_entity, |
68 const std::string& scope, | 65 const std::string& scope, |
69 const DeleteTokenCallback& callback); | 66 const DeleteTokenCallback& callback); |
70 void DoDeleteID(const DeleteIDCallback& callback); | 67 void DoDeleteID(const DeleteIDCallback& callback); |
71 | 68 |
72 gcm::GCMDriver* gcm_driver_; // Not owned. | |
73 | |
74 gcm::GCMDelayedTaskController delayed_task_controller_; | 69 gcm::GCMDelayedTaskController delayed_task_controller_; |
75 | 70 |
76 // The generated Instance ID. | 71 // The generated Instance ID. |
77 std::string id_; | 72 std::string id_; |
78 | 73 |
79 // The time when the Instance ID has been generated. | 74 // The time when the Instance ID has been generated. |
80 base::Time creation_time_; | 75 base::Time creation_time_; |
81 | 76 |
82 base::WeakPtrFactory<InstanceIDImpl> weak_ptr_factory_; | 77 base::WeakPtrFactory<InstanceIDImpl> weak_ptr_factory_; |
83 | 78 |
84 DISALLOW_COPY_AND_ASSIGN(InstanceIDImpl); | 79 DISALLOW_COPY_AND_ASSIGN(InstanceIDImpl); |
85 }; | 80 }; |
86 | 81 |
87 } // namespace instance_id | 82 } // namespace instance_id |
88 | 83 |
89 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ | 84 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ |
OLD | NEW |