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

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

Issue 1137463003: Support getting and deleting token for Instance ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add new files Created 5 years, 7 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/fake_gcm_driver_for_instance_id.h" 5 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "components/gcm_driver/gcm_client.h"
9 12
10 namespace instance_id { 13 namespace instance_id {
11 14
12 FakeGCMDriverForInstanceID::FakeGCMDriverForInstanceID() { 15 FakeGCMDriverForInstanceID::FakeGCMDriverForInstanceID() {
13 } 16 }
14 17
15 FakeGCMDriverForInstanceID::~FakeGCMDriverForInstanceID() { 18 FakeGCMDriverForInstanceID::~FakeGCMDriverForInstanceID() {
16 } 19 }
17 20
18 gcm::InstanceIDStore* FakeGCMDriverForInstanceID::GetInstanceIDStore() { 21 gcm::InstanceIDHandler* FakeGCMDriverForInstanceID::GetInstanceIDHandler() {
19 return this; 22 return this;
20 } 23 }
21 24
22 void FakeGCMDriverForInstanceID::AddInstanceIDData( 25 void FakeGCMDriverForInstanceID::AddInstanceIDData(
23 const std::string& app_id, 26 const std::string& app_id,
24 const std::string& instance_id_data) { 27 const std::string& instance_id_data) {
25 instance_id_data_[app_id] = instance_id_data; 28 instance_id_data_[app_id] = instance_id_data;
26 } 29 }
27 30
28 void FakeGCMDriverForInstanceID::RemoveInstanceIDData( 31 void FakeGCMDriverForInstanceID::RemoveInstanceIDData(
29 const std::string& app_id) { 32 const std::string& app_id) {
30 instance_id_data_.erase(app_id); 33 instance_id_data_.erase(app_id);
31 } 34 }
32 35
33 void FakeGCMDriverForInstanceID::GetInstanceIDData( 36 void FakeGCMDriverForInstanceID::GetInstanceIDData(
34 const std::string& app_id, 37 const std::string& app_id,
35 const gcm::InstanceIDStore::GetInstanceIDDataCallback& callback) { 38 const GetInstanceIDDataCallback& callback) {
36 std::string data; 39 std::string data;
37 auto iter = instance_id_data_.find(app_id); 40 auto iter = instance_id_data_.find(app_id);
38 if (iter != instance_id_data_.end()) 41 if (iter != instance_id_data_.end())
39 data = iter->second; 42 data = iter->second;
40 base::MessageLoop::current()->PostTask( 43 base::MessageLoop::current()->PostTask(
41 FROM_HERE, 44 FROM_HERE,
42 base::Bind(callback, data)); 45 base::Bind(callback, data));
43 } 46 }
44 47
48 void FakeGCMDriverForInstanceID::GetToken(
49 const std::string& app_id,
50 const std::string& authorized_entity,
51 const std::string& scope,
52 const std::map<std::string, std::string>& options,
53 const GetTokenCallback& callback) {
54 std::string token;
55 std::string key = app_id + authorized_entity + scope;
56 auto iter = tokens_.find(key);
57 if (iter != tokens_.end()) {
58 token = iter->second;
59 } else {
60 token = base::Uint64ToString(base::RandUint64());
61 tokens_[key] = token;
62 }
63
64 base::MessageLoop::current()->PostTask(
65 FROM_HERE,
66 base::Bind(callback, token, gcm::GCMClient::SUCCESS));
67 }
68
69 void FakeGCMDriverForInstanceID::DeleteToken(
70 const std::string& app_id,
71 const std::string& authorized_entity,
72 const std::string& scope,
73 const DeleteTokenCallback& callback) {
74 std::string key = app_id + authorized_entity + scope;
75 tokens_.erase(key);
76 base::MessageLoop::current()->PostTask(
77 FROM_HERE,
78 base::Bind(callback, gcm::GCMClient::SUCCESS));
79 }
80
45 } // namespace instance_id 81 } // namespace instance_id
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698