| 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_impl.h" | 5 #include "components/gcm_driver/instance_id/instance_id_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 NOTIMPLEMENTED(); | 52 NOTIMPLEMENTED(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void InstanceIDImpl::DeleteID(const DeleteIDCallback& callback) { | 55 void InstanceIDImpl::DeleteID(const DeleteIDCallback& callback) { |
| 56 // TODO(jianli): Delete the ID from the store. | 56 // TODO(jianli): Delete the ID from the store. |
| 57 id_.clear(); | 57 id_.clear(); |
| 58 creation_time_ = base::Time(); | 58 creation_time_ = base::Time(); |
| 59 | 59 |
| 60 base::MessageLoop::current()->PostTask( | 60 base::MessageLoop::current()->PostTask( |
| 61 FROM_HERE, | 61 FROM_HERE, |
| 62 base::Bind(callback, this, InstanceID::SUCCESS)); | 62 base::Bind(callback, InstanceID::SUCCESS)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void InstanceIDImpl::EnsureIDGenerated() { | 65 void InstanceIDImpl::EnsureIDGenerated() { |
| 66 if (!id_.empty()) | 66 if (!id_.empty()) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 // Now produce the ID in the following steps: | 69 // Now produce the ID in the following steps: |
| 70 | 70 |
| 71 // 1) Generates the random number in 8 bytes which is required by the server. | 71 // 1) Generates the random number in 8 bytes which is required by the server. |
| 72 // We don't want to be strictly cryptographically secure. The server might | 72 // We don't want to be strictly cryptographically secure. The server might |
| (...skipping 15 matching lines...) Expand all Loading... |
| 88 std::replace(id_.begin(), id_.end(), '+', '-'); | 88 std::replace(id_.begin(), id_.end(), '+', '-'); |
| 89 std::replace(id_.begin(), id_.end(), '/', '_'); | 89 std::replace(id_.begin(), id_.end(), '/', '_'); |
| 90 id_.erase(std::remove(id_.begin(), id_.end(), '='), id_.end()); | 90 id_.erase(std::remove(id_.begin(), id_.end(), '='), id_.end()); |
| 91 | 91 |
| 92 creation_time_ = base::Time::Now(); | 92 creation_time_ = base::Time::Now(); |
| 93 | 93 |
| 94 // TODO(jianli): Save the ID to the store. | 94 // TODO(jianli): Save the ID to the store. |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace instance_id | 97 } // namespace instance_id |
| OLD | NEW |