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