| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/test/webdriver/session_manager.h" | 5 #include "chrome/test/webdriver/session_manager.h" |
| 6 | 6 |
| 7 #ifdef OS_POSIX | 7 #ifdef OS_POSIX |
| 8 #include <netdb.h> | 8 #include <netdb.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 #include <arpa/inet.h> | 10 #include <arpa/inet.h> |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 TestTimeouts::Initialize(); | 134 TestTimeouts::Initialize(); |
| 135 | 135 |
| 136 *id = GenerateSessionID(); | 136 *id = GenerateSessionID(); |
| 137 if (map_.find(*id) != map_.end()) { | 137 if (map_.find(*id) != map_.end()) { |
| 138 LOG(ERROR) << "Failed to generate a unique session ID"; | 138 LOG(ERROR) << "Failed to generate a unique session ID"; |
| 139 return false; | 139 return false; |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Start chrome, if it doesn't startup quit. | 142 // Start chrome, if it doesn't startup quit. |
| 143 const int ap_timeout = TestTimeouts::command_execution_timeout_ms(); | 143 const int ap_timeout = TestTimeouts::command_execution_timeout_ms(); |
| 144 LOG(INFO) << "Waiting for a max of " << ap_timeout << " ms to " | 144 VLOG(1) << "Waiting for a max of " << ap_timeout << " ms to start the chrome " |
| 145 << "start the chrome browser"; | 145 "browser"; |
| 146 | 146 |
| 147 scoped_ptr<Session> session(new Session(*id)); | 147 scoped_ptr<Session> session(new Session(*id)); |
| 148 | 148 |
| 149 if (!session->Init()) { | 149 if (!session->Init()) { |
| 150 LOG(ERROR) << "Could not establish a valid connection to the browser"; | 150 LOG(ERROR) << "Could not establish a valid connection to the browser"; |
| 151 return false; | 151 return false; |
| 152 } | 152 } |
| 153 | 153 |
| 154 map_[*id] = session.release(); | 154 map_[*id] = session.release(); |
| 155 return true; | 155 return true; |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool SessionManager::Has(const std::string& id) const { | 158 bool SessionManager::Has(const std::string& id) const { |
| 159 return map_.find(id) != map_.end(); | 159 return map_.find(id) != map_.end(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool SessionManager::Delete(const std::string& id) { | 162 bool SessionManager::Delete(const std::string& id) { |
| 163 std::map<std::string, Session*>::iterator it; | 163 std::map<std::string, Session*>::iterator it; |
| 164 | 164 |
| 165 LOG(INFO) << "Deleting session with ID " << id; | 165 VLOG(1) << "Deleting session with ID " << id; |
| 166 it = map_.find(id); | 166 it = map_.find(id); |
| 167 if (it == map_.end()) { | 167 if (it == map_.end()) { |
| 168 LOG(INFO) << "No such session with ID " << id; | 168 VLOG(1) << "No such session with ID " << id; |
| 169 return false; | 169 return false; |
| 170 } | 170 } |
| 171 | 171 |
| 172 it->second->Terminate(); | 172 it->second->Terminate(); |
| 173 map_.erase(it); | 173 map_.erase(it); |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 | 176 |
| 177 Session* SessionManager::GetSession(const std::string& id) const { | 177 Session* SessionManager::GetSession(const std::string& id) const { |
| 178 std::map<std::string, Session*>::const_iterator it; | 178 std::map<std::string, Session*>::const_iterator it; |
| 179 it = map_.find(id); | 179 it = map_.find(id); |
| 180 if (it == map_.end()) { | 180 if (it == map_.end()) { |
| 181 LOG(INFO) << "No such session with ID " << id; | 181 VLOG(1) << "No such session with ID " << id; |
| 182 return NULL; | 182 return NULL; |
| 183 } | 183 } |
| 184 return it->second; | 184 return it->second; |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace webdriver | 187 } // namespace webdriver |
| OLD | NEW |