OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/quic/crypto/source_address_token.h" | 5 #include "chrome/browser/extensions/api/sessions/foreign_session_id.h" |
6 | |
7 #include <vector> | |
8 | 6 |
9 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | |
11 | 8 |
12 using std::string; | 9 namespace extensions { |
13 using std::vector; | |
14 | 10 |
15 namespace net { | 11 const char kIdSeparator = '.'; |
16 | 12 |
17 SourceAddressToken::SourceAddressToken() { | 13 ForeignSessionId::ForeignSessionId(const std::string& session_tag, int id) |
14 : session_tag_(session_tag), id_(id) { | |
18 } | 15 } |
19 | 16 |
20 SourceAddressToken::~SourceAddressToken() { | 17 ForeignSessionId::ForeignSessionId(const std::string& foreign_session_string) { |
18 if (IsForeignSessionId(foreign_session_string)) { | |
19 std::size_t separator = foreign_session_string.find(kIdSeparator); | |
20 session_tag_ = foreign_session_string.substr(0, separator); | |
21 base::StringToInt(foreign_session_string.substr(separator + 1), &id_); | |
22 } | |
21 } | 23 } |
22 | 24 |
23 string SourceAddressToken::SerializeAsString() const { | 25 // static |
24 return ip_ + " " + base::Int64ToString(timestamp_); | 26 bool ForeignSessionId::IsForeignSessionId(const std::string& id) { |
27 return id.find(kIdSeparator) != std::string::npos; | |
25 } | 28 } |
26 | 29 |
27 bool SourceAddressToken::ParseFromArray(const char* plaintext, | 30 std::string ForeignSessionId::ToString() { |
28 size_t plaintext_length) { | 31 return (session_tag_ + kIdSeparator + base::IntToString(id_)); |
not at google - send to devlin
2013/08/12 23:51:34
use base::StringPrintf instead
Kristen Dwan
2013/08/15 07:11:56
Done.
| |
29 string data(plaintext, plaintext_length); | |
30 vector<string> results; | |
31 base::SplitString(data, ' ', &results); | |
32 if (results.size() < 2) { | |
33 return false; | |
34 } | |
35 | |
36 int64 timestamp; | |
37 if (!base::StringToInt64(results[1], ×tamp)) { | |
38 return false; | |
39 } | |
40 | |
41 ip_ = results[0]; | |
42 timestamp_ = timestamp; | |
43 return true; | |
44 } | 32 } |
45 | 33 |
46 } // namespace net | 34 } // namespace extensions |
OLD | NEW |