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_delayed_task_controller.h" | 17 #include "components/gcm_driver/gcm_delayed_task_controller.h" |
17 #include "components/gcm_driver/instance_id/instance_id.h" | 18 #include "components/gcm_driver/instance_id/instance_id.h" |
18 | 19 |
19 namespace gcm { | 20 namespace gcm { |
20 class GCMDriver; | 21 class GCMDriver; |
| 22 class InstanceIDHandler; |
21 } // namespace gcm | 23 } // namespace gcm |
22 | 24 |
23 namespace instance_id { | 25 namespace instance_id { |
24 | 26 |
25 // InstanceID implementation for desktop and iOS. | 27 // InstanceID implementation for desktop and iOS. |
26 class InstanceIDImpl : public InstanceID { | 28 class InstanceIDImpl : public InstanceID { |
27 public: | 29 public: |
28 InstanceIDImpl(const std::string& app_id, gcm::GCMDriver* gcm_driver); | 30 InstanceIDImpl(const std::string& app_id, gcm::GCMDriver* gcm_driver); |
29 ~InstanceIDImpl() override; | 31 ~InstanceIDImpl() override; |
30 | 32 |
31 // InstanceID: | 33 // InstanceID: |
32 void GetID(const GetIDCallback& callback) override; | 34 void GetID(const GetIDCallback& callback) override; |
33 void GetCreationTime(const GetCreationTimeCallback& callback) override; | 35 void GetCreationTime(const GetCreationTimeCallback& callback) override; |
34 void GetToken(const std::string& authorized_entity, | 36 void GetToken(const std::string& authorized_entity, |
35 const std::string& scope, | 37 const std::string& scope, |
36 const std::map<std::string, std::string>& options, | 38 const std::map<std::string, std::string>& options, |
37 const GetTokenCallback& callback) override; | 39 const GetTokenCallback& callback) override; |
38 void DeleteToken(const std::string& authorized_entity, | 40 void DeleteToken(const std::string& authorized_entity, |
39 const std::string& scope, | 41 const std::string& scope, |
40 const DeleteTokenCallback& callback) override; | 42 const DeleteTokenCallback& callback) override; |
41 void DeleteID(const DeleteIDCallback& callback) override; | 43 void DeleteID(const DeleteIDCallback& callback) override; |
42 | 44 |
43 private: | 45 private: |
| 46 gcm::InstanceIDHandler* GetInstanceIDHandler() const; |
| 47 |
44 void EnsureIDGenerated(); | 48 void EnsureIDGenerated(); |
| 49 |
| 50 void OnGetTokenCompleted(const GetTokenCallback& callback, |
| 51 const std::string& token, |
| 52 gcm::GCMClient::Result result); |
| 53 void OnDeleteTokenCompleted(const DeleteTokenCallback& callback, |
| 54 gcm::GCMClient::Result result); |
45 void GetInstanceIDDataCompleted(const std::string& instance_id_data); | 55 void GetInstanceIDDataCompleted(const std::string& instance_id_data); |
46 | 56 |
47 void DoGetID(const GetIDCallback& callback); | 57 void DoGetID(const GetIDCallback& callback); |
48 void DoGetCreationTime(const GetCreationTimeCallback& callback); | 58 void DoGetCreationTime(const GetCreationTimeCallback& callback); |
| 59 void DoGetToken( |
| 60 const std::string& authorized_entity, |
| 61 const std::string& scope, |
| 62 const std::map<std::string, std::string>& options, |
| 63 const GetTokenCallback& callback); |
| 64 void DoDeleteToken(const std::string& authorized_entity, |
| 65 const std::string& scope, |
| 66 const DeleteTokenCallback& callback); |
49 | 67 |
50 // Encodes/decodes the InstanceID data to work with the persistent store. | 68 // Encodes/decodes the InstanceID data to work with the persistent store. |
51 std::string SerializeAsString() const; | 69 std::string SerializeAsString() const; |
52 void Deserialize(const std::string& serialized_data); | 70 void Deserialize(const std::string& serialized_data); |
53 | 71 |
54 gcm::GCMDriver* gcm_driver_; // Not owned. | 72 gcm::GCMDriver* gcm_driver_; // Not owned. |
55 | 73 |
56 gcm::GCMDelayedTaskController delayed_task_controller_; | 74 gcm::GCMDelayedTaskController delayed_task_controller_; |
57 | 75 |
58 // Flag to indicate that we have tries to load the data from the store. | 76 // Flag to indicate that we have tries to load the data from the store. |
59 bool load_from_store_; | 77 bool load_from_store_; |
60 | 78 |
61 // The generated Instance ID. | 79 // The generated Instance ID. |
62 std::string id_; | 80 std::string id_; |
63 | 81 |
64 // The time when the Instance ID has been generated. | 82 // The time when the Instance ID has been generated. |
65 base::Time creation_time_; | 83 base::Time creation_time_; |
66 | 84 |
67 base::WeakPtrFactory<InstanceIDImpl> weak_ptr_factory_; | 85 base::WeakPtrFactory<InstanceIDImpl> weak_ptr_factory_; |
68 | 86 |
69 DISALLOW_COPY_AND_ASSIGN(InstanceIDImpl); | 87 DISALLOW_COPY_AND_ASSIGN(InstanceIDImpl); |
70 }; | 88 }; |
71 | 89 |
72 } // namespace instance_id | 90 } // namespace instance_id |
73 | 91 |
74 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ | 92 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ |
OLD | NEW |