OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/debugger/devtools_http_protocol_handler.h" | 5 #include "content/browser/debugger/devtools_http_protocol_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/lazy_instance.h" | |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
14 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "content/browser/debugger/devtools_client_host.h" | 19 #include "content/browser/debugger/devtools_client_host.h" |
19 #include "content/browser/debugger/devtools_manager.h" | 20 #include "content/browser/debugger/devtools_manager.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 net::HttpServer* server_; | 86 net::HttpServer* server_; |
86 int connection_id_; | 87 int connection_id_; |
87 }; | 88 }; |
88 | 89 |
89 static int next_id = 1; | 90 static int next_id = 1; |
90 | 91 |
91 class TabContentsIDHelper : public TabContentsObserver { | 92 class TabContentsIDHelper : public TabContentsObserver { |
92 public: | 93 public: |
93 | 94 |
94 static int GetID(TabContents* tab) { | 95 static int GetID(TabContents* tab) { |
95 TabContentsToIdMap::iterator it = tabcontents_to_id_.find(tab); | 96 TabContentsToIdMap::iterator it = tabcontents_to_id_.Get().find(tab); |
96 if (it != tabcontents_to_id_.end()) | 97 if (it != tabcontents_to_id_.Get().end()) |
97 return it->second; | 98 return it->second; |
98 TabContentsIDHelper* wrapper = new TabContentsIDHelper(tab); | 99 TabContentsIDHelper* wrapper = new TabContentsIDHelper(tab); |
99 return wrapper->id_; | 100 return wrapper->id_; |
100 } | 101 } |
101 | 102 |
102 static TabContents* GetTabContents(int id) { | 103 static TabContents* GetTabContents(int id) { |
103 IdToTabContentsMap::iterator it = id_to_tabcontents_.find(id); | 104 IdToTabContentsMap::iterator it = id_to_tabcontents_.Get().find(id); |
104 if (it != id_to_tabcontents_.end()) | 105 if (it != id_to_tabcontents_.Get().end()) |
105 return it->second; | 106 return it->second; |
106 return NULL; | 107 return NULL; |
107 } | 108 } |
108 | 109 |
109 private: | 110 private: |
110 explicit TabContentsIDHelper(TabContents* tab) | 111 explicit TabContentsIDHelper(TabContents* tab) |
111 : TabContentsObserver(tab), | 112 : TabContentsObserver(tab), |
112 id_(next_id++) { | 113 id_(next_id++) { |
113 id_to_tabcontents_[id_] = tab; | 114 id_to_tabcontents_.Get()[id_] = tab; |
114 tabcontents_to_id_[tab] = id_; | 115 tabcontents_to_id_.Get()[tab] = id_; |
115 } | 116 } |
116 | 117 |
117 virtual ~TabContentsIDHelper() {} | 118 virtual ~TabContentsIDHelper() {} |
118 | 119 |
119 virtual void TabContentsDestroyed(TabContents* tab) { | 120 virtual void TabContentsDestroyed(TabContents* tab) { |
120 id_to_tabcontents_.erase(id_); | 121 id_to_tabcontents_.Get().erase(id_); |
121 tabcontents_to_id_.erase(tab); | 122 tabcontents_to_id_.Get().erase(tab); |
122 delete this; | 123 delete this; |
123 } | 124 } |
124 | 125 |
125 int id_; | 126 int id_; |
126 typedef std::map<int, TabContents*> IdToTabContentsMap; | 127 typedef std::map<int, TabContents*> IdToTabContentsMap; |
127 static IdToTabContentsMap id_to_tabcontents_; | 128 static base::LazyInstance<IdToTabContentsMap, |
Mark Mentovai
2011/11/07 22:34:15
Note that I have no real concern with private + st
| |
129 base::LeakyLazyInstanceTraits<IdToTabContentsMap> > | |
130 id_to_tabcontents_; | |
128 typedef std::map<TabContents*, int> TabContentsToIdMap; | 131 typedef std::map<TabContents*, int> TabContentsToIdMap; |
129 static TabContentsToIdMap tabcontents_to_id_; | 132 static base::LazyInstance<TabContentsToIdMap, |
133 base::LeakyLazyInstanceTraits<TabContentsToIdMap> > | |
134 tabcontents_to_id_; | |
130 }; | 135 }; |
131 | 136 |
132 TabContentsIDHelper::IdToTabContentsMap TabContentsIDHelper::id_to_tabcontents_; | 137 base::LazyInstance< |
133 TabContentsIDHelper::TabContentsToIdMap TabContentsIDHelper::tabcontents_to_id_; | 138 TabContentsIDHelper::IdToTabContentsMap, |
139 base::LeakyLazyInstanceTraits<TabContentsIDHelper::IdToTabContentsMap> > | |
140 TabContentsIDHelper::id_to_tabcontents_(base::LINKER_INITIALIZED); | |
141 base::LazyInstance< | |
142 TabContentsIDHelper::TabContentsToIdMap, | |
143 base::LeakyLazyInstanceTraits<TabContentsIDHelper::TabContentsToIdMap> > | |
144 TabContentsIDHelper::tabcontents_to_id_(base::LINKER_INITIALIZED); | |
134 | 145 |
135 } // namespace | 146 } // namespace |
136 | 147 |
137 // static | 148 // static |
138 scoped_refptr<DevToolsHttpProtocolHandler> DevToolsHttpProtocolHandler::Start( | 149 scoped_refptr<DevToolsHttpProtocolHandler> DevToolsHttpProtocolHandler::Start( |
139 const std::string& ip, | 150 const std::string& ip, |
140 int port, | 151 int port, |
141 const std::string& frontend_url, | 152 const std::string& frontend_url, |
142 Delegate* delegate) { | 153 Delegate* delegate) { |
143 scoped_refptr<DevToolsHttpProtocolHandler> http_handler = | 154 scoped_refptr<DevToolsHttpProtocolHandler> http_handler = |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 void DevToolsHttpProtocolHandler::AcceptWebSocket( | 556 void DevToolsHttpProtocolHandler::AcceptWebSocket( |
546 int connection_id, | 557 int connection_id, |
547 const net::HttpServerRequestInfo& request) { | 558 const net::HttpServerRequestInfo& request) { |
548 BrowserThread::PostTask( | 559 BrowserThread::PostTask( |
549 BrowserThread::IO, FROM_HERE, | 560 BrowserThread::IO, FROM_HERE, |
550 NewRunnableMethod(server_.get(), | 561 NewRunnableMethod(server_.get(), |
551 &net::HttpServer::AcceptWebSocket, | 562 &net::HttpServer::AcceptWebSocket, |
552 connection_id, | 563 connection_id, |
553 request)); | 564 request)); |
554 } | 565 } |
OLD | NEW |