OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/extensions/api/sessions/session_id.h" | 5 #include "chrome/browser/extensions/api/sessions/session_id.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
10 | 11 |
11 namespace extensions { | 12 namespace extensions { |
12 | 13 |
13 const char kIdSeparator = '.'; | 14 const char kIdSeparator = '.'; |
14 | 15 |
15 // static | 16 // static |
16 scoped_ptr<SessionId> SessionId::Parse(const std::string& session_id) { | 17 std::unique_ptr<SessionId> SessionId::Parse(const std::string& session_id) { |
17 std::string session_tag; | 18 std::string session_tag; |
18 | 19 |
19 // Populate session_tag if the |session_id| represents a foreign SessionId. | 20 // Populate session_tag if the |session_id| represents a foreign SessionId. |
20 std::size_t separator = session_id.find(kIdSeparator); | 21 std::size_t separator = session_id.find(kIdSeparator); |
21 if (separator != std::string::npos) { | 22 if (separator != std::string::npos) { |
22 session_tag = session_id.substr(0, separator); | 23 session_tag = session_id.substr(0, separator); |
23 } | 24 } |
24 | 25 |
25 // session_tag will be the empty string for local sessions that have only | 26 // session_tag will be the empty string for local sessions that have only |
26 // a unique integer as the identifier. | 27 // a unique integer as the identifier. |
27 int id; | 28 int id; |
28 if (!base::StringToInt( | 29 if (!base::StringToInt( |
29 session_tag.empty() ? session_id : session_id.substr(separator + 1), | 30 session_tag.empty() ? session_id : session_id.substr(separator + 1), |
30 &id)) { | 31 &id)) { |
31 return scoped_ptr<SessionId>(); | 32 return std::unique_ptr<SessionId>(); |
32 } | 33 } |
33 return make_scoped_ptr(new SessionId(session_tag, id)); | 34 return base::WrapUnique(new SessionId(session_tag, id)); |
34 } | 35 } |
35 | 36 |
36 SessionId::SessionId(const std::string& session_tag, int id) | 37 SessionId::SessionId(const std::string& session_tag, int id) |
37 : session_tag_(session_tag), id_(id) { | 38 : session_tag_(session_tag), id_(id) { |
38 } | 39 } |
39 | 40 |
40 bool SessionId::IsForeign() const { | 41 bool SessionId::IsForeign() const { |
41 return !session_tag_.empty(); | 42 return !session_tag_.empty(); |
42 } | 43 } |
43 | 44 |
44 std::string SessionId::ToString() const { | 45 std::string SessionId::ToString() const { |
45 return IsForeign() ? | 46 return IsForeign() ? |
46 (session_tag_ + kIdSeparator + base::IntToString(id_)) | 47 (session_tag_ + kIdSeparator + base::IntToString(id_)) |
47 : base::IntToString(id_); | 48 : base::IntToString(id_); |
48 } | 49 } |
49 | 50 |
50 } // namespace extensions | 51 } // namespace extensions |
OLD | NEW |