Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: components/gcm_driver/instance_id/instance_id.cc

Issue 1923953002: Integrate InstanceID with GCM crypto provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid5default
Patch Set: RunUntilIdle after deleting GCMDriver Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // A common use case for InstanceID tokens is to authorize and route push
13 // messages sent via Google Cloud Messaging (replacing the earlier registration
14 // IDs). To get such a GCM-enabled token, pass this scope to getToken.
15 // Must match Java GoogleCloudMessaging.INSTANCE_ID_SCOPE.
16 const char kGCMScope[] = "GCM";
17
18 InstanceID::InstanceID(const std::string& app_id, gcm::GCMDriver* gcm_driver)
19 : gcm_driver_(gcm_driver), app_id_(app_id), weak_ptr_factory_(this) {}
10 20
11 InstanceID::~InstanceID() {} 21 InstanceID::~InstanceID() {}
12 22
13 void InstanceID::SetTokenRefreshCallback(const TokenRefreshCallback& callback) { 23 void InstanceID::SetTokenRefreshCallback(const TokenRefreshCallback& callback) {
14 token_refresh_callback_ = callback; 24 token_refresh_callback_ = callback;
15 } 25 }
16 26
17 void InstanceID::NotifyTokenRefresh(bool update_id) { 27 void InstanceID::NotifyTokenRefresh(bool update_id) {
18 if (!token_refresh_callback_.is_null()) 28 if (!token_refresh_callback_.is_null())
19 token_refresh_callback_.Run(app_id_, update_id); 29 token_refresh_callback_.Run(app_id_, update_id);
20 } 30 }
21 31
32 void InstanceID::GetEncryptionInfo(const std::string& authorized_entity,
33 const GetEncryptionInfoCallback& callback) {
34 gcm_driver_->GetEncryptionProviderInternal()->GetEncryptionInfo(
35 app_id_, authorized_entity, callback);
36 }
37
38 void InstanceID::DeleteToken(const std::string& authorized_entity,
39 const std::string& scope,
40 const DeleteTokenCallback& callback) {
41 // Tokens with GCM scope act as Google Cloud Messaging registrations, so may
42 // have associated encryption information in the GCMKeyStore. This needs to be
43 // cleared when the token is deleted.
44 DeleteTokenCallback wrapped_callback =
45 scope == kGCMScope
46 ? base::Bind(&InstanceID::DidDelete, weak_ptr_factory_.GetWeakPtr(),
47 authorized_entity, callback)
48 : callback;
49 DeleteTokenImpl(authorized_entity, scope, wrapped_callback);
50 }
51
52 void InstanceID::DeleteID(const DeleteIDCallback& callback) {
53 // Use "*" as authorized_entity to remove any encryption info for all tokens.
54 DeleteIDImpl(base::Bind(&InstanceID::DidDelete,
55 weak_ptr_factory_.GetWeakPtr(),
56 "*" /* authorized_entity */, callback));
57 }
58
59 void InstanceID::DidDelete(const std::string& authorized_entity,
60 const base::Callback<void(Result result)>& callback,
61 Result result) {
62 gcm_driver_->GetEncryptionProviderInternal()->RemoveEncryptionInfo(
63 app_id_, authorized_entity, base::Bind(callback, result));
64 }
65
22 } // namespace instance_id 66 } // namespace instance_id
OLDNEW
« no previous file with comments | « components/gcm_driver/instance_id/instance_id.h ('k') | components/gcm_driver/instance_id/instance_id_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698