Support getting and deleting token for Instance ID.
[chromium-blink-merge.git] / components / gcm_driver / instance_id / instance_id_impl.h
blob8b0d9420a0d22548bc659be266b18cb43de8cfd4
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_
6 #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_
8 #include <map>
9 #include <string>
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h"
16 #include "components/gcm_driver/gcm_client.h"
17 #include "components/gcm_driver/gcm_delayed_task_controller.h"
18 #include "components/gcm_driver/instance_id/instance_id.h"
20 namespace gcm {
21 class GCMDriver;
22 class InstanceIDHandler;
23 } // namespace gcm
25 namespace instance_id {
27 // InstanceID implementation for desktop and iOS.
28 class InstanceIDImpl : public InstanceID {
29 public:
30 InstanceIDImpl(const std::string& app_id, gcm::GCMDriver* gcm_driver);
31 ~InstanceIDImpl() override;
33 // InstanceID:
34 void GetID(const GetIDCallback& callback) override;
35 void GetCreationTime(const GetCreationTimeCallback& callback) override;
36 void GetToken(const std::string& authorized_entity,
37 const std::string& scope,
38 const std::map<std::string, std::string>& options,
39 const GetTokenCallback& callback) override;
40 void DeleteToken(const std::string& authorized_entity,
41 const std::string& scope,
42 const DeleteTokenCallback& callback) override;
43 void DeleteID(const DeleteIDCallback& callback) override;
45 private:
46 gcm::InstanceIDHandler* GetInstanceIDHandler() const;
48 void EnsureIDGenerated();
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);
55 void OnDeleteIDCompleted(const DeleteIDCallback& callback,
56 gcm::GCMClient::Result result);
57 void GetInstanceIDDataCompleted(const std::string& instance_id,
58 const std::string& extra_data);
60 void DoGetID(const GetIDCallback& callback);
61 void DoGetCreationTime(const GetCreationTimeCallback& callback);
62 void DoGetToken(
63 const std::string& authorized_entity,
64 const std::string& scope,
65 const std::map<std::string, std::string>& options,
66 const GetTokenCallback& callback);
67 void DoDeleteToken(const std::string& authorized_entity,
68 const std::string& scope,
69 const DeleteTokenCallback& callback);
70 void DoDeleteID(const DeleteIDCallback& callback);
72 gcm::GCMDriver* gcm_driver_; // Not owned.
74 gcm::GCMDelayedTaskController delayed_task_controller_;
76 // Flag to indicate that we have tries to load the data from the store.
77 bool load_from_store_;
79 // The generated Instance ID.
80 std::string id_;
82 // The time when the Instance ID has been generated.
83 base::Time creation_time_;
85 base::WeakPtrFactory<InstanceIDImpl> weak_ptr_factory_;
87 DISALLOW_COPY_AND_ASSIGN(InstanceIDImpl);
90 } // namespace instance_id
92 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_