Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: chrome/browser/extensions/api/sessions/session_id.cc

Issue 21022018: Sessions API - previously Session Restore API. Supports restoring currently open foreign windows an… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delete test. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/sessions/session_id.h"
6
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/stringprintf.h"
9
10 namespace extensions {
11
12 const char kIdSeparator = '.';
13
14 // static
15 scoped_ptr<SessionId> SessionId::Parse(const std::string& session_id) {
16 std::string session_tag;
17
18 // Populate session_tag if the |session_id| represents a foreign SessionId.
19 std::size_t separator = session_id.find(kIdSeparator);
20 if (separator != std::string::npos) {
21 session_tag = session_id.substr(0, separator);
22 }
23
24 // session_tag will be the empty string for local sessions that have only
25 // a unique integer as the identifier.
26 int id;
27 if (!base::StringToInt(
28 session_tag.empty() ? session_id : session_id.substr(separator + 1),
29 &id)) {
30 return scoped_ptr<SessionId>();
31 }
32 return make_scoped_ptr(new SessionId(session_tag, id));
33 }
34
35 SessionId::SessionId(const std::string& session_tag, int id)
36 : session_tag_(session_tag), id_(id) {
37 }
38
39 bool SessionId::IsForeign() const {
40 return !session_tag_.empty();
41 }
42
43 std::string SessionId::ToString() const {
44 return IsForeign() ?
45 (session_tag_ + kIdSeparator + base::StringPrintf("%d", id_))
46 : base::StringPrintf("%d", id_);
47 }
48
49 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/sessions/session_id.h ('k') | chrome/browser/extensions/api/sessions/sessions_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698