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

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

Issue 1113213002: Generate Instance ID locally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback 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
« no previous file with comments | « components/gcm_driver/instance_id/instance_id_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_impl.h" 5 #include "components/gcm_driver/instance_id/instance_id_impl.h"
6 6
7 #include <algorithm>
8 #include "base/bind.h"
9 #include "base/guid.h"
7 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h"
8 12
9 namespace instance_id { 13 namespace instance_id {
10 14
11 // static 15 // static
12 InstanceID* InstanceID::Create(const std::string& app_id) { 16 InstanceID* InstanceID::Create(const std::string& app_id) {
13 return new InstanceIDImpl(app_id); 17 return new InstanceIDImpl(app_id);
14 } 18 }
15 19
16 InstanceIDImpl::InstanceIDImpl(const std::string& app_id) 20 InstanceIDImpl::InstanceIDImpl(const std::string& app_id)
17 : InstanceID(app_id) { 21 : InstanceID(app_id) {
18 } 22 }
19 23
20 InstanceIDImpl::~InstanceIDImpl() { 24 InstanceIDImpl::~InstanceIDImpl() {
21 } 25 }
22 26
23 std::string InstanceIDImpl::GetID() { 27 std::string InstanceIDImpl::GetID() {
24 NOTIMPLEMENTED(); 28 EnsureIDGenerated();
25 return std::string(); 29 return id_;
26 } 30 }
27 31
28 base::Time InstanceIDImpl::GetCreationTime() { 32 base::Time InstanceIDImpl::GetCreationTime() {
29 NOTIMPLEMENTED(); 33 return creation_time_;
30 return base::Time();
31 } 34 }
32 35
33 void InstanceIDImpl::GetToken( 36 void InstanceIDImpl::GetToken(
34 const std::string& audience, 37 const std::string& audience,
35 const std::string& scope, 38 const std::string& scope,
36 const std::map<std::string, std::string>& options, 39 const std::map<std::string, std::string>& options,
37 const GetTokenCallback& callback) { 40 const GetTokenCallback& callback) {
38 NOTIMPLEMENTED(); 41 NOTIMPLEMENTED();
39 } 42 }
40 43
41 void InstanceIDImpl::DeleteToken(const std::string& audience, 44 void InstanceIDImpl::DeleteToken(const std::string& audience,
42 const std::string& scope, 45 const std::string& scope,
43 const DeleteTokenCallback& callback) { 46 const DeleteTokenCallback& callback) {
44 NOTIMPLEMENTED(); 47 NOTIMPLEMENTED();
45 } 48 }
46 49
47 void InstanceIDImpl::DeleteID(const DeleteIDCallback& callback) { 50 void InstanceIDImpl::DeleteID(const DeleteIDCallback& callback) {
48 NOTIMPLEMENTED(); 51 // TODO(jianli): Delete the ID from the store.
52 id_.clear();
53 creation_time_ = base::Time();
54
55 base::MessageLoop::current()->PostTask(
56 FROM_HERE,
57 base::Bind(callback, this, InstanceID::SUCCESS));
58 }
59
60 void InstanceIDImpl::EnsureIDGenerated() {
61 if (!id_.empty())
62 return;
63
64 id_ = base::GenerateGUID();
fgorski 2015/05/04 16:11:19 Based on the prior code, shouldn't you start from
jianli 2015/05/04 20:14:49 I've updated the ID generation algorithm based on
65 id_.erase(std::remove(id_.begin(), id_.end(), '-'), id_.end());
66
67 creation_time_ = base::Time::Now();
68
69 // TODO(jianli): Save the ID to the store.
49 } 70 }
50 71
51 } // namespace instance_id 72 } // namespace instance_id
OLDNEW
« no previous file with comments | « components/gcm_driver/instance_id/instance_id_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698