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 #include "components/gcm_driver/instance_id/instance_id.h" | 5 #include "components/gcm_driver/instance_id/instance_id.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "components/gcm_driver/gcm_driver.h" | |
9 | |
7 namespace instance_id { | 10 namespace instance_id { |
8 | 11 |
9 InstanceID::InstanceID(const std::string& app_id) : app_id_(app_id) {} | 12 const char kGCMScope[] = "GCM"; |
13 | |
14 InstanceID::InstanceID(const std::string& app_id, gcm::GCMDriver* gcm_driver) | |
15 : gcm_driver_(gcm_driver), app_id_(app_id), weak_ptr_factory_(this) {} | |
10 | 16 |
11 InstanceID::~InstanceID() {} | 17 InstanceID::~InstanceID() {} |
12 | 18 |
13 void InstanceID::SetTokenRefreshCallback(const TokenRefreshCallback& callback) { | 19 void InstanceID::SetTokenRefreshCallback(const TokenRefreshCallback& callback) { |
14 token_refresh_callback_ = callback; | 20 token_refresh_callback_ = callback; |
15 } | 21 } |
16 | 22 |
17 void InstanceID::NotifyTokenRefresh(bool update_id) { | 23 void InstanceID::NotifyTokenRefresh(bool update_id) { |
18 if (!token_refresh_callback_.is_null()) | 24 if (!token_refresh_callback_.is_null()) |
19 token_refresh_callback_.Run(app_id_, update_id); | 25 token_refresh_callback_.Run(app_id_, update_id); |
20 } | 26 } |
21 | 27 |
28 void InstanceID::GetEncryptionInfo(const std::string& authorized_entity, | |
29 const GetEncryptionInfoCallback& callback) { | |
30 gcm_driver_->encryption_provider_internal()->GetEncryptionInfo( | |
31 app_id_, authorized_entity, callback); | |
32 } | |
33 | |
34 void InstanceID::DeleteToken(const std::string& authorized_entity, | |
35 const std::string& scope, | |
36 const DeleteTokenCallback& callback) { | |
37 DeleteTokenCallback wrapped_callback = | |
Peter Beverloo
2016/05/11 16:05:00
It would be good to document why this only applies
johnme
2016/05/13 16:25:45
Done.
| |
38 scope == kGCMScope | |
39 ? base::Bind(&InstanceID::DidDelete, weak_ptr_factory_.GetWeakPtr(), | |
40 authorized_entity, callback) | |
41 : callback; | |
42 DeleteTokenImpl(authorized_entity, scope, wrapped_callback); | |
43 } | |
44 | |
45 void InstanceID::DeleteID(const DeleteIDCallback& callback) { | |
46 // Use "*" as authorized_entity to remove encryption info for all tokens. | |
47 DeleteIDImpl(base::Bind(&InstanceID::DidDelete, | |
48 weak_ptr_factory_.GetWeakPtr(), | |
49 "*" /* authorized_entity */, callback)); | |
50 } | |
51 | |
52 void InstanceID::DidDelete(const std::string& authorized_entity, | |
53 const base::Callback<void(Result result)>& callback, | |
54 Result result) { | |
55 gcm_driver_->encryption_provider_internal()->RemoveEncryptionInfo( | |
56 app_id_, authorized_entity, base::Bind(callback, result)); | |
57 } | |
58 | |
22 } // namespace instance_id | 59 } // namespace instance_id |
OLD | NEW |