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/websockets/websocket_manager.h" | 5 #include "content/browser/websockets/websocket_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
14 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/render_process_host_observer.h" | 18 #include "content/public/browser/render_process_host_observer.h" |
18 #include "content/public/browser/storage_partition.h" | 19 #include "content/public/browser/storage_partition.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 namespace { | 23 namespace { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 63 |
63 // Maintain a WebSocketManager per RenderProcessHost. While the instance of | 64 // Maintain a WebSocketManager per RenderProcessHost. While the instance of |
64 // WebSocketManager is allocated on the UI thread, it must only be used and | 65 // WebSocketManager is allocated on the UI thread, it must only be used and |
65 // deleted from the IO thread. | 66 // deleted from the IO thread. |
66 | 67 |
67 Handle* handle = | 68 Handle* handle = |
68 static_cast<Handle*>(host->GetUserData(kWebSocketManagerKeyName)); | 69 static_cast<Handle*>(host->GetUserData(kWebSocketManagerKeyName)); |
69 if (!handle) { | 70 if (!handle) { |
70 handle = new Handle( | 71 handle = new Handle( |
71 new WebSocketManager(process_id, host->GetStoragePartition())); | 72 new WebSocketManager(process_id, host->GetStoragePartition())); |
72 host->SetUserData(kWebSocketManagerKeyName, handle); | 73 host->SetUserData(kWebSocketManagerKeyName, base::WrapUnique(handle)); |
73 host->AddObserver(handle); | 74 host->AddObserver(handle); |
74 } else { | 75 } else { |
75 DCHECK(handle->manager()); | 76 DCHECK(handle->manager()); |
76 } | 77 } |
77 | 78 |
78 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
79 BrowserThread::IO, | 80 BrowserThread::IO, |
80 FROM_HERE, | 81 FROM_HERE, |
81 base::Bind(&WebSocketManager::DoCreateWebSocket, | 82 base::Bind(&WebSocketManager::DoCreateWebSocket, |
82 base::Unretained(handle->manager()), | 83 base::Unretained(handle->manager()), |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
236 if (!url_request_context_getter_->GetURLRequestContext()) { | 237 if (!url_request_context_getter_->GetURLRequestContext()) { |
237 context_destroyed_ = true; | 238 context_destroyed_ = true; |
238 url_request_context_getter_ = nullptr; | 239 url_request_context_getter_ = nullptr; |
239 return; | 240 return; |
240 } | 241 } |
241 url_request_context_getter_->AddObserver(this); | 242 url_request_context_getter_->AddObserver(this); |
242 } | 243 } |
243 | 244 |
244 } // namespace content | 245 } // namespace content |
OLD | NEW |