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

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: sync 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
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 <string> 5 #include "chrome/browser/extensions/api/sessions/session_id.h"
6 6
7 #include "base/strings/string_number_conversions.h"
7 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/extensions/webstore_installer.h"
9 #include "chrome/common/omaha_query_params/omaha_query_params.h"
10 #include "extensions/common/id_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using base::StringPrintf;
14 using chrome::OmahaQueryParams;
15 9
16 namespace extensions { 10 namespace extensions {
17 11
18 // Returns true if |target| is found in |source|. 12 const char kIdSeparator = '.';
19 bool Contains(const std::string& source, const std::string& target) { 13
20 return source.find(target) != std::string::npos; 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));
21 } 33 }
22 34
23 TEST(WebstoreInstallerTest, PlatformParams) { 35 SessionId::SessionId(const std::string& session_tag, int id)
24 std::string id = extensions::id_util::GenerateId("some random string"); 36 : session_tag_(session_tag), id_(id) {
25 GURL url = WebstoreInstaller::GetWebstoreInstallURL(id, ""); 37 }
26 std::string query = url.query();
27 EXPECT_TRUE(Contains(query,StringPrintf("os=%s", OmahaQueryParams::getOS())));
28 EXPECT_TRUE(Contains(query,StringPrintf("arch=%s",
29 OmahaQueryParams::getArch())));
30 EXPECT_TRUE(Contains(query,StringPrintf("nacl_arch=%s",
31 OmahaQueryParams::getNaclArch())));
32 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_);
33 } 47 }
34 48
35 } // namespace extensions 49 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698