| 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 "components/omnibox/search_provider.h" | 5 #include "components/omnibox/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 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 // pending. | 1460 // pending. |
| 1461 done_ = !timer_.IsRunning() && !default_fetcher_ && !keyword_fetcher_; | 1461 done_ = !timer_.IsRunning() && !default_fetcher_ && !keyword_fetcher_; |
| 1462 } | 1462 } |
| 1463 | 1463 |
| 1464 std::string SearchProvider::GetSessionToken() { | 1464 std::string SearchProvider::GetSessionToken() { |
| 1465 base::TimeTicks current_time(base::TimeTicks::Now()); | 1465 base::TimeTicks current_time(base::TimeTicks::Now()); |
| 1466 // Renew token if it expired. | 1466 // Renew token if it expired. |
| 1467 if (current_time > token_expiration_time_) { | 1467 if (current_time > token_expiration_time_) { |
| 1468 const size_t kTokenBytes = 12; | 1468 const size_t kTokenBytes = 12; |
| 1469 std::string raw_data; | 1469 std::string raw_data; |
| 1470 base::RandBytes(WriteInto(&raw_data, kTokenBytes + 1), kTokenBytes); | 1470 base::RandBytes(base::WriteInto(&raw_data, kTokenBytes + 1), kTokenBytes); |
| 1471 base::Base64Encode(raw_data, ¤t_token_); | 1471 base::Base64Encode(raw_data, ¤t_token_); |
| 1472 | 1472 |
| 1473 // Make the base64 encoded value URL and filename safe(see RFC 3548). | 1473 // Make the base64 encoded value URL and filename safe(see RFC 3548). |
| 1474 std::replace(current_token_.begin(), current_token_.end(), '+', '-'); | 1474 std::replace(current_token_.begin(), current_token_.end(), '+', '-'); |
| 1475 std::replace(current_token_.begin(), current_token_.end(), '/', '_'); | 1475 std::replace(current_token_.begin(), current_token_.end(), '/', '_'); |
| 1476 } | 1476 } |
| 1477 | 1477 |
| 1478 // Extend expiration time another 60 seconds. | 1478 // Extend expiration time another 60 seconds. |
| 1479 token_expiration_time_ = current_time + base::TimeDelta::FromSeconds(60); | 1479 token_expiration_time_ = current_time + base::TimeDelta::FromSeconds(60); |
| 1480 | 1480 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1514 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
| 1515 matches.push_back(i->second); | 1515 matches.push_back(i->second); |
| 1516 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1516 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
| 1517 | 1517 |
| 1518 // If there is a top scoring entry, find the corresponding answer. | 1518 // If there is a top scoring entry, find the corresponding answer. |
| 1519 if (!matches.empty()) | 1519 if (!matches.empty()) |
| 1520 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1520 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
| 1521 | 1521 |
| 1522 return AnswersQueryData(); | 1522 return AnswersQueryData(); |
| 1523 } | 1523 } |
| OLD | NEW |