1 // Copyright (c) 2011 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/test/webdriver/webdriver_session_manager.h" 6 7 #include "chrome/test/webdriver/webdriver_session.h" 8 9 namespace webdriver { 10 11 void SessionManager::Add(Session* session) { 12 base::AutoLock lock(map_lock_); 13 map_[session->id()] = session; 14 } 15 16 bool SessionManager::Has(const std::string& id) const { 17 base::AutoLock lock(map_lock_); 18 return map_.find(id) != map_.end(); 19 } 20 21 bool SessionManager::Remove(const std::string& id) { 22 std::map<std::string, Session*>::iterator it; 23 base::AutoLock lock(map_lock_); 24 it = map_.find(id); 25 if (it == map_.end()) 26 return false; 27 map_.erase(it); 28 return true; 29 } 30 31 Session* SessionManager::GetSession(const std::string& id) const { 32 std::map<std::string, Session*>::const_iterator it; 33 base::AutoLock lock(map_lock_); 34 it = map_.find(id); 35 if (it == map_.end()) 36 return NULL; 37 return it->second; 38 } 39 40 void SessionManager::set_port(const std::string& port) { 41 port_ = port; 42 } 43 44 void SessionManager::set_url_base(const std::string& url_base) { 45 url_base_ = url_base; 46 } 47 48 std::string SessionManager::url_base() const { 49 return url_base_; 50 } 51 52 SessionManager::SessionManager() {} 53 54 SessionManager::~SessionManager() {} 55 56 // static 57 SessionManager* SessionManager::GetInstance() { 58 return Singleton<SessionManager>::get(); 59 } 60 61 } // namespace webdriver 62