summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/session_manager.h
blob: 5f7ce395fed97292a4821191988a289733101146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_WEBDRIVER_SESSION_MANAGER_H_
#define CHROME_TEST_WEBDRIVER_SESSION_MANAGER_H_

#include <map>
#include <string>

#include "base/file_path.h"
#include "base/memory/singleton.h"
#include "base/synchronization/lock.h"
#include "chrome/test/webdriver/session.h"

namespace webdriver {

// Session manager keeps track of all of the session that are currently
// running on the machine under test. With webdriver the user is allowed
// multiple instances of the browser on the same machine.  So 2 sessions
// open would mean you would have 2 instances of chrome running under
// their own profiles.
class SessionManager {
 public:
  // Returns the singleton instance.
  static SessionManager* GetInstance();

  std::string GetAddress();

  void Add(Session* session);
  bool Remove(const std::string& id);
  bool Has(const std::string& id) const;

  Session* GetSession(const std::string& id) const;

  void set_port(const std::string& port);

  void set_url_base(const std::string& url_base);
  std::string url_base() const;

  void set_chrome_dir(const FilePath& chrome_dir);
  FilePath chrome_dir() const;

 private:
  SessionManager();
  ~SessionManager();
  friend struct DefaultSingletonTraits<SessionManager>;

  std::map<std::string, Session*> map_;
  mutable base::Lock map_lock_;
  std::string port_;
  std::string url_base_;
  FilePath chrome_dir_;

  DISALLOW_COPY_AND_ASSIGN(SessionManager);
};

}  // namespace webdriver

#endif  // CHROME_TEST_WEBDRIVER_SESSION_MANAGER_H_