• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSION_ID_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSION_ID_H__
7 
8 #include <string>
9 
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 
13 namespace extensions {
14 
15 class SessionId {
16  public:
17   // Returns a SessionId, representing either a local or a foreign session.
18   // In the case that the session is local, |session_tag_| will be empty string.
19   // |session_string| should be in the format that ToString() would produce.
20   static scoped_ptr<SessionId> Parse(const std::string& session_string);
21 
22   // Constructs a SessionId object for the given session information.
23   // |session_tag| is the string used to uniquely identify a synced foreign
24   // session from the SessionModelAssociator. In the case that SessionId
25   // represents a local session, |session_tag_| will be the empty string. |id|
26   // uniquely identifies either a window or tab object in the local or the
27   // |session_tag| session.
28   SessionId(const std::string& session_tag, int id);
29 
30   // Returns true if the SessionId represents a foreign session.
31   bool IsForeign() const;
32 
33   // Returns the compressed std::string representation of a SessionId in the
34   // same format that Parse() accepts as its |session_string| parameter.
35   std::string ToString() const;
36 
session_tag()37   const std::string& session_tag() const { return session_tag_; }
id()38   int id() const { return id_; }
39 
40  private:
41   // The unique identifier for a foreign session, given by the
42   // SessionModelAssociator.
43   std::string session_tag_;
44 
45   // ID corresponding to a window or tab object.
46   int id_;
47 
48   DISALLOW_COPY_AND_ASSIGN(SessionId);
49 };
50 
51 }  // namespace extensions
52 
53 #endif  // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSION_ID_H__
54