Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: chrome/browser/android/devtools_manager_delegate_android.cc

Issue 2833213002: DevTools: retain DTAH in all the targets to match their life time. (Closed)
Patch Set: cast test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/browser/android/devtools_manager_delegate_android.h" 5 #include "chrome/browser/android/devtools_manager_delegate_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 153
154 const int tab_id_; 154 const int tab_id_;
155 const std::string title_; 155 const std::string title_;
156 const GURL url_; 156 const GURL url_;
157 scoped_refptr<DevToolsAgentHost> agent_host_; 157 scoped_refptr<DevToolsAgentHost> agent_host_;
158 content::DevToolsExternalAgentProxy* proxy_; 158 content::DevToolsExternalAgentProxy* proxy_;
159 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); 159 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate);
160 }; 160 };
161 161
162 scoped_refptr<DevToolsAgentHost> DevToolsAgentHostForTab(TabAndroid* tab) {
163 scoped_refptr<DevToolsAgentHost> result = tab->GetDevToolsAgentHost();
164 if (result)
165 return result;
166
167 result = DevToolsAgentHost::Forward(base::IntToString(tab->GetAndroidId()),
168 base::MakeUnique<TabProxyDelegate>(tab));
169 tab->SetDevToolsAgentHost(result);
170 return result;
171 }
172
162 } // namespace 173 } // namespace
163 174
164 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() 175 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid()
165 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { 176 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) {
166 content::DevToolsAgentHost::AddObserver(this); 177 content::DevToolsAgentHost::AddObserver(this);
167 } 178 }
168 179
169 DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() { 180 DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() {
170 content::DevToolsAgentHost::RemoveObserver(this); 181 content::DevToolsAgentHost::RemoveObserver(this);
171 } 182 }
172 183
173 base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand( 184 base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand(
174 DevToolsAgentHost* agent_host, 185 DevToolsAgentHost* agent_host,
175 base::DictionaryValue* command_dict) { 186 base::DictionaryValue* command_dict) {
176 return network_protocol_handler_->HandleCommand(agent_host, command_dict); 187 return network_protocol_handler_->HandleCommand(agent_host, command_dict);
177 } 188 }
178 189
179 std::string DevToolsManagerDelegateAndroid::GetTargetType( 190 std::string DevToolsManagerDelegateAndroid::GetTargetType(
180 content::RenderFrameHost* host) { 191 content::RenderFrameHost* host) {
181 content::WebContents* web_contents = 192 content::WebContents* web_contents =
182 content::WebContents::FromRenderFrameHost(host); 193 content::WebContents::FromRenderFrameHost(host);
183 TabAndroid* tab = web_contents ? TabAndroid::FromWebContents(web_contents) 194 TabAndroid* tab = web_contents ? TabAndroid::FromWebContents(web_contents)
184 : nullptr; 195 : nullptr;
185 return tab ? DevToolsAgentHost::kTypePage : 196 return tab ? DevToolsAgentHost::kTypePage :
186 DevToolsAgentHost::kTypeOther; 197 DevToolsAgentHost::kTypeOther;
187 } 198 }
188 199
189 bool DevToolsManagerDelegateAndroid::DiscoverTargets( 200 DevToolsAgentHost::List
190 const DevToolsAgentHost::DiscoveryCallback& callback) { 201 DevToolsManagerDelegateAndroid::RemoteDebuggingTargets() {
191 #if defined(OS_ANDROID)
192 // Enumerate existing tabs, including the ones with no WebContents. 202 // Enumerate existing tabs, including the ones with no WebContents.
193 DevToolsAgentHost::List result; 203 DevToolsAgentHost::List result;
194 std::set<WebContents*> tab_web_contents; 204 std::set<WebContents*> tab_web_contents;
195 for (TabModelList::const_iterator iter = TabModelList::begin(); 205 for (TabModelList::const_iterator iter = TabModelList::begin();
196 iter != TabModelList::end(); ++iter) { 206 iter != TabModelList::end(); ++iter) {
197 TabModel* model = *iter; 207 TabModel* model = *iter;
198 for (int i = 0; i < model->GetTabCount(); ++i) { 208 for (int i = 0; i < model->GetTabCount(); ++i) {
199 TabAndroid* tab = model->GetTabAt(i); 209 TabAndroid* tab = model->GetTabAt(i);
200 if (!tab) 210 if (!tab)
201 continue; 211 continue;
202 212
203 if (tab->web_contents()) 213 if (tab->web_contents())
204 tab_web_contents.insert(tab->web_contents()); 214 tab_web_contents.insert(tab->web_contents());
205 215 result.push_back(DevToolsAgentHostForTab(tab));
206 scoped_refptr<DevToolsAgentHost> host =
207 DevToolsAgentHost::Forward(
208 base::IntToString(tab->GetAndroidId()),
209 base::WrapUnique(new TabProxyDelegate(tab)));
210 result.push_back(host);
211 } 216 }
212 } 217 }
213 218
214 // Add descriptors for targets not associated with any tabs. 219 // Add descriptors for targets not associated with any tabs.
215 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); 220 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
216 for (DevToolsAgentHost::List::iterator it = agents.begin(); 221 for (DevToolsAgentHost::List::iterator it = agents.begin();
217 it != agents.end(); ++it) { 222 it != agents.end(); ++it) {
218 if (WebContents* web_contents = (*it)->GetWebContents()) { 223 if (WebContents* web_contents = (*it)->GetWebContents()) {
219 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) 224 if (tab_web_contents.find(web_contents) != tab_web_contents.end())
220 continue; 225 continue;
221 } 226 }
222 result.push_back(*it); 227 result.push_back(*it);
223 } 228 }
224 229
225 callback.Run(std::move(result)); 230 return result;
226 return true;
227 #else
228 return false;
229 #endif // defined(OS_ANDROID)
230 } 231 }
231 232
232 scoped_refptr<DevToolsAgentHost> 233 scoped_refptr<DevToolsAgentHost>
233 DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) { 234 DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) {
234 if (TabModelList::empty()) 235 if (TabModelList::empty())
235 return nullptr; 236 return nullptr;
236 237
237 TabModel* tab_model = TabModelList::get(0); 238 TabModel* tab_model = TabModelList::get(0);
238 if (!tab_model) 239 if (!tab_model)
239 return nullptr; 240 return nullptr;
240 241
241 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); 242 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url);
242 if (!web_contents) 243 if (!web_contents)
243 return nullptr; 244 return nullptr;
244 245
245 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); 246 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
246 if (!tab) 247 return tab ? DevToolsAgentHostForTab(tab) : nullptr;
247 return nullptr;
248
249 return DevToolsAgentHost::Forward(
250 base::IntToString(tab->GetAndroidId()),
251 base::WrapUnique(new TabProxyDelegate(tab)));
252 } 248 }
253 249
254 std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() { 250 std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() {
255 return ResourceBundle::GetSharedInstance().GetRawDataResource( 251 return ResourceBundle::GetSharedInstance().GetRawDataResource(
256 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); 252 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string();
257 } 253 }
258 254
259 void DevToolsManagerDelegateAndroid::DevToolsAgentHostAttached( 255 void DevToolsManagerDelegateAndroid::DevToolsAgentHostAttached(
260 content::DevToolsAgentHost* agent_host) { 256 content::DevToolsAgentHost* agent_host) {
261 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, true); 257 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, true);
262 } 258 }
263 259
264 void DevToolsManagerDelegateAndroid::DevToolsAgentHostDetached( 260 void DevToolsManagerDelegateAndroid::DevToolsAgentHostDetached(
265 content::DevToolsAgentHost* agent_host) { 261 content::DevToolsAgentHost* agent_host) {
266 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, false); 262 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, false);
267 } 263 }
OLDNEW
« no previous file with comments | « chrome/browser/android/devtools_manager_delegate_android.h ('k') | chrome/browser/android/tab_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698