| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "chrome/browser/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 } | 1145 } |
| 1146 | 1146 |
| 1147 std::string SearchProvider::GetSessionToken() { | 1147 std::string SearchProvider::GetSessionToken() { |
| 1148 base::TimeTicks current_time(base::TimeTicks::Now()); | 1148 base::TimeTicks current_time(base::TimeTicks::Now()); |
| 1149 // Renew token if it expired. | 1149 // Renew token if it expired. |
| 1150 if (current_time > token_expiration_time_) { | 1150 if (current_time > token_expiration_time_) { |
| 1151 const size_t kTokenBytes = 12; | 1151 const size_t kTokenBytes = 12; |
| 1152 std::string raw_data; | 1152 std::string raw_data; |
| 1153 base::RandBytes(WriteInto(&raw_data, kTokenBytes + 1), kTokenBytes); | 1153 base::RandBytes(WriteInto(&raw_data, kTokenBytes + 1), kTokenBytes); |
| 1154 base::Base64Encode(raw_data, ¤t_token_); | 1154 base::Base64Encode(raw_data, ¤t_token_); |
| 1155 |
| 1156 // Make the base64 encoded value URL and filename safe(see RFC 3548). |
| 1157 std::replace(current_token_.begin(), current_token_.end(), '+', '-'); |
| 1158 std::replace(current_token_.begin(), current_token_.end(), '/', '_'); |
| 1155 } | 1159 } |
| 1156 | 1160 |
| 1157 // Extend expiration time another 60 seconds. | 1161 // Extend expiration time another 60 seconds. |
| 1158 token_expiration_time_ = current_time + base::TimeDelta::FromSeconds(60); | 1162 token_expiration_time_ = current_time + base::TimeDelta::FromSeconds(60); |
| 1159 | 1163 |
| 1160 return current_token_; | 1164 return current_token_; |
| 1161 } | 1165 } |
| OLD | NEW |