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

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

Issue 2344753002: DevTools: return discovered targets asynchronously. (Closed)
Patch Set: for bots 2 Created 4 years, 3 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 150 }
151 151
152 const int tab_id_; 152 const int tab_id_;
153 const std::string title_; 153 const std::string title_;
154 const GURL url_; 154 const GURL url_;
155 scoped_refptr<DevToolsAgentHost> agent_host_; 155 scoped_refptr<DevToolsAgentHost> agent_host_;
156 content::DevToolsExternalAgentProxy* proxy_; 156 content::DevToolsExternalAgentProxy* proxy_;
157 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); 157 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate);
158 }; 158 };
159 159
160 DevToolsAgentHost::List GetDescriptors() {
161 DevToolsAgentHost::List result;
162
163 // Enumerate existing tabs, including the ones with no WebContents.
164 std::set<WebContents*> tab_web_contents;
165 for (TabModelList::const_iterator iter = TabModelList::begin();
166 iter != TabModelList::end(); ++iter) {
167 TabModel* model = *iter;
168 for (int i = 0; i < model->GetTabCount(); ++i) {
169 TabAndroid* tab = model->GetTabAt(i);
170 if (!tab)
171 continue;
172
173 scoped_refptr<DevToolsAgentHost> host =
174 DevToolsAgentHost::Forward(
175 base::IntToString(tab->GetAndroidId()),
176 base::WrapUnique(new TabProxyDelegate(tab)));
177 }
178 }
179
180 // Add descriptors for targets not associated with any tabs.
181 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
182 for (DevToolsAgentHost::List::iterator it = agents.begin();
183 it != agents.end(); ++it) {
184 if (WebContents* web_contents = (*it)->GetWebContents()) {
185 if (tab_web_contents.find(web_contents) != tab_web_contents.end())
186 continue;
187 }
188 result.push_back(*it);
189 }
190
191 return result;
192 }
193
194 } // namespace 160 } // namespace
195 161
196 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() 162 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid()
197 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { 163 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) {
198 #if BUILDFLAG(ANDROID_JAVA_UI)
199 DevToolsAgentHost::AddDiscoveryProvider(base::Bind(&GetDescriptors));
200 #endif // BUILDFLAG(ANDROID_JAVA_UI)
201 } 164 }
202 165
203 DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() { 166 DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() {
204 } 167 }
205 168
206 void DevToolsManagerDelegateAndroid::Inspect( 169 void DevToolsManagerDelegateAndroid::Inspect(
207 DevToolsAgentHost* agent_host) { 170 DevToolsAgentHost* agent_host) {
208 } 171 }
209 172
210 base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand( 173 base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand(
(...skipping 13 matching lines...) Expand all
224 } 187 }
225 188
226 std::string DevToolsManagerDelegateAndroid::GetTargetTitle( 189 std::string DevToolsManagerDelegateAndroid::GetTargetTitle(
227 content::RenderFrameHost* host) { 190 content::RenderFrameHost* host) {
228 content::WebContents* web_contents = 191 content::WebContents* web_contents =
229 content::WebContents::FromRenderFrameHost(host); 192 content::WebContents::FromRenderFrameHost(host);
230 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); 193 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
231 return tab ? base::UTF16ToUTF8(tab->GetTitle()) : ""; 194 return tab ? base::UTF16ToUTF8(tab->GetTitle()) : "";
232 } 195 }
233 196
197 bool DevToolsManagerDelegateAndroid::DiscoverTargets(
198 const DevToolsAgentHost::DiscoveryCallback& callback) {
199 #if BUILDFLAG(ANDROID_JAVA_UI)
200 // Enumerate existing tabs, including the ones with no WebContents.
201 std::set<WebContents*> tab_web_contents;
202 for (TabModelList::const_iterator iter = TabModelList::begin();
203 iter != TabModelList::end(); ++iter) {
204 TabModel* model = *iter;
205 for (int i = 0; i < model->GetTabCount(); ++i) {
206 TabAndroid* tab = model->GetTabAt(i);
207 if (!tab)
208 continue;
209
210 scoped_refptr<DevToolsAgentHost> host =
211 DevToolsAgentHost::Forward(
212 base::IntToString(tab->GetAndroidId()),
213 base::WrapUnique(new TabProxyDelegate(tab)));
214 }
215 }
216
217 // Add descriptors for targets not associated with any tabs.
218 DevToolsAgentHost::List result = DevToolsAgentHost::GetOrCreateAll();
219 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
220 for (DevToolsAgentHost::List::iterator it = agents.begin();
221 it != agents.end(); ++it) {
222 if (WebContents* web_contents = (*it)->GetWebContents()) {
223 if (tab_web_contents.find(web_contents) != tab_web_contents.end())
224 continue;
225 }
226 result.push_back(*it);
227 }
228
229 callback.Run(std::move(result));
230 return true;
231 #else
232 return false;
233 #endif // BUILDFLAG(ANDROID_JAVA_UI)
234 }
235
234 scoped_refptr<DevToolsAgentHost> 236 scoped_refptr<DevToolsAgentHost>
235 DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) { 237 DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) {
236 if (TabModelList::empty()) 238 if (TabModelList::empty())
237 return nullptr; 239 return nullptr;
238 240
239 TabModel* tab_model = TabModelList::get(0); 241 TabModel* tab_model = TabModelList::get(0);
240 if (!tab_model) 242 if (!tab_model)
241 return nullptr; 243 return nullptr;
242 244
243 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); 245 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url);
(...skipping 11 matching lines...) Expand all
255 257
256 std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() { 258 std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() {
257 return ResourceBundle::GetSharedInstance().GetRawDataResource( 259 return ResourceBundle::GetSharedInstance().GetRawDataResource(
258 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); 260 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string();
259 } 261 }
260 262
261 void DevToolsManagerDelegateAndroid::DevToolsAgentStateChanged( 263 void DevToolsManagerDelegateAndroid::DevToolsAgentStateChanged(
262 DevToolsAgentHost* agent_host, bool attached) { 264 DevToolsAgentHost* agent_host, bool attached) {
263 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); 265 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached);
264 } 266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698