| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/renderer_host/websocket_dispatcher_host.h" | 5 #include "content/browser/renderer_host/websocket_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | |
| 9 | 8 |
| 10 #include "base/callback.h" | 9 #include "base/callback.h" |
| 11 #include "base/logging.h" | 10 #include "base/logging.h" |
| 12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 13 #include "content/browser/child_process_security_policy_impl.h" | 12 #include "content/browser/child_process_security_policy_impl.h" |
| 14 #include "content/browser/renderer_host/websocket_host.h" | 13 #include "content/browser/renderer_host/websocket_host.h" |
| 15 #include "content/common/websocket_messages.h" | 14 #include "content/common/websocket_messages.h" |
| 16 | 15 |
| 17 namespace content { | 16 namespace content { |
| 18 | 17 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 const std::string& reason) { | 171 const std::string& reason) { |
| 173 if (SendOrDrop( | 172 if (SendOrDrop( |
| 174 new WebSocketMsg_DropChannel(routing_id, was_clean, code, reason)) == | 173 new WebSocketMsg_DropChannel(routing_id, was_clean, code, reason)) == |
| 175 WEBSOCKET_HOST_DELETED) | 174 WEBSOCKET_HOST_DELETED) |
| 176 return WEBSOCKET_HOST_DELETED; | 175 return WEBSOCKET_HOST_DELETED; |
| 177 DeleteWebSocketHost(routing_id); | 176 DeleteWebSocketHost(routing_id); |
| 178 return WEBSOCKET_HOST_DELETED; | 177 return WEBSOCKET_HOST_DELETED; |
| 179 } | 178 } |
| 180 | 179 |
| 181 WebSocketDispatcherHost::~WebSocketDispatcherHost() { | 180 WebSocketDispatcherHost::~WebSocketDispatcherHost() { |
| 182 std::vector<WebSocketHost*> hosts; | |
| 183 for (base::hash_map<int, WebSocketHost*>::const_iterator i = hosts_.begin(); | |
| 184 i != hosts_.end(); ++i) { | |
| 185 // In order to avoid changing the container while iterating, we copy | |
| 186 // the hosts. | |
| 187 hosts.push_back(i->second); | |
| 188 } | |
| 189 | |
| 190 for (size_t i = 0; i < hosts.size(); ++i) { | |
| 191 // Note that some calls to GoAway could fail. In that case hosts[i] will be | |
| 192 // deleted and removed from |hosts_| in |DoDropChannel|. | |
| 193 hosts[i]->GoAway(); | |
| 194 hosts[i] = NULL; | |
| 195 } | |
| 196 | |
| 197 STLDeleteContainerPairSecondPointers(hosts_.begin(), hosts_.end()); | 181 STLDeleteContainerPairSecondPointers(hosts_.begin(), hosts_.end()); |
| 198 } | 182 } |
| 199 | 183 |
| 200 void WebSocketDispatcherHost::DeleteWebSocketHost(int routing_id) { | 184 void WebSocketDispatcherHost::DeleteWebSocketHost(int routing_id) { |
| 201 WebSocketHostTable::iterator it = hosts_.find(routing_id); | 185 WebSocketHostTable::iterator it = hosts_.find(routing_id); |
| 202 DCHECK(it != hosts_.end()); | 186 DCHECK(it != hosts_.end()); |
| 203 delete it->second; | 187 delete it->second; |
| 204 hosts_.erase(it); | 188 hosts_.erase(it); |
| 205 } | 189 } |
| 206 | 190 |
| 207 } // namespace content | 191 } // namespace content |
| OLD | NEW |