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

Side by Side Diff: chrome/browser/ui/webui/net_internals/net_internals_ui.cc

Issue 2346863003: PrerenderManager: No longer expose weak pointers. (Closed)
Patch Set: Fix net-internals 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
« no previous file with comments | « chrome/browser/prerender/prerender_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/net_internals/net_internals_ui.h" 5 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 bool success, 233 bool success,
234 const net::CertificateList& onc_trusted_certificates); 234 const net::CertificateList& onc_trusted_certificates);
235 #endif 235 #endif
236 236
237 private: 237 private:
238 class IOThreadImpl; 238 class IOThreadImpl;
239 239
240 // This is the "real" message handler, which lives on the IO thread. 240 // This is the "real" message handler, which lives on the IO thread.
241 scoped_refptr<IOThreadImpl> proxy_; 241 scoped_refptr<IOThreadImpl> proxy_;
242 242
243 base::WeakPtr<prerender::PrerenderManager> prerender_manager_;
244
245 DISALLOW_COPY_AND_ASSIGN(NetInternalsMessageHandler); 243 DISALLOW_COPY_AND_ASSIGN(NetInternalsMessageHandler);
246 }; 244 };
247 245
248 // This class is the "real" message handler. It is allocated and destroyed on 246 // This class is the "real" message handler. It is allocated and destroyed on
249 // the UI thread. With the exception of OnAddEntry, OnWebUIDeleted, and 247 // the UI thread. With the exception of OnAddEntry, OnWebUIDeleted, and
250 // SendJavascriptCommand, its methods are all expected to be called from the IO 248 // SendJavascriptCommand, its methods are all expected to be called from the IO
251 // thread. OnAddEntry and SendJavascriptCommand can be called from any thread, 249 // thread. OnAddEntry and SendJavascriptCommand can be called from any thread,
252 // and OnWebUIDeleted can only be called from the UI thread. 250 // and OnWebUIDeleted can only be called from the UI thread.
253 class NetInternalsMessageHandler::IOThreadImpl 251 class NetInternalsMessageHandler::IOThreadImpl
254 : public base::RefCountedThreadSafe< 252 : public base::RefCountedThreadSafe<
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 401
404 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), 402 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(),
405 profile->GetRequestContext()); 403 profile->GetRequestContext());
406 proxy_->AddRequestContextGetter( 404 proxy_->AddRequestContextGetter(
407 content::BrowserContext::GetDefaultStoragePartition(profile)-> 405 content::BrowserContext::GetDefaultStoragePartition(profile)->
408 GetMediaURLRequestContext()); 406 GetMediaURLRequestContext());
409 #if defined(ENABLE_EXTENSIONS) 407 #if defined(ENABLE_EXTENSIONS)
410 proxy_->AddRequestContextGetter(profile->GetRequestContextForExtensions()); 408 proxy_->AddRequestContextGetter(profile->GetRequestContextForExtensions());
411 #endif 409 #endif
412 410
413 prerender::PrerenderManager* prerender_manager =
414 prerender::PrerenderManagerFactory::GetForProfile(profile);
415 if (prerender_manager) {
416 prerender_manager_ = prerender_manager->AsWeakPtr();
417 } else {
418 prerender_manager_ = base::WeakPtr<prerender::PrerenderManager>();
419 }
420
421 web_ui()->RegisterMessageCallback( 411 web_ui()->RegisterMessageCallback(
422 "notifyReady", 412 "notifyReady",
423 base::Bind(&NetInternalsMessageHandler::OnRendererReady, 413 base::Bind(&NetInternalsMessageHandler::OnRendererReady,
424 base::Unretained(this))); 414 base::Unretained(this)));
425 web_ui()->RegisterMessageCallback( 415 web_ui()->RegisterMessageCallback(
426 "getNetInfo", 416 "getNetInfo",
427 base::Bind(&IOThreadImpl::CallbackHelper, 417 base::Bind(&IOThreadImpl::CallbackHelper,
428 &IOThreadImpl::OnGetNetInfo, proxy_)); 418 &IOThreadImpl::OnGetNetInfo, proxy_));
429 web_ui()->RegisterMessageCallback( 419 web_ui()->RegisterMessageCallback(
430 "reloadProxySettings", 420 "reloadProxySettings",
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 BrowsingDataRemover::REMOVE_CACHE, 525 BrowsingDataRemover::REMOVE_CACHE,
536 BrowsingDataHelper::UNPROTECTED_WEB); 526 BrowsingDataHelper::UNPROTECTED_WEB);
537 // BrowsingDataRemover deletes itself. 527 // BrowsingDataRemover deletes itself.
538 } 528 }
539 529
540 void NetInternalsMessageHandler::OnGetPrerenderInfo( 530 void NetInternalsMessageHandler::OnGetPrerenderInfo(
541 const base::ListValue* /* list */) { 531 const base::ListValue* /* list */) {
542 DCHECK_CURRENTLY_ON(BrowserThread::UI); 532 DCHECK_CURRENTLY_ON(BrowserThread::UI);
543 533
544 std::unique_ptr<base::DictionaryValue> value; 534 std::unique_ptr<base::DictionaryValue> value;
545 if (prerender_manager_) { 535
546 value = prerender_manager_->GetAsValue(); 536 prerender::PrerenderManager* prerender_manager =
537 prerender::PrerenderManagerFactory::GetForProfile(
538 Profile::FromWebUI(web_ui()));
539 if (prerender_manager) {
540 value = prerender_manager->GetAsValue();
547 } else { 541 } else {
548 value.reset(new base::DictionaryValue()); 542 value.reset(new base::DictionaryValue());
549 value->SetBoolean("enabled", false); 543 value->SetBoolean("enabled", false);
550 value->SetBoolean("omnibox_enabled", false); 544 value->SetBoolean("omnibox_enabled", false);
551 } 545 }
552 SendJavascriptCommand("receivedPrerenderInfo", std::move(value)); 546 SendJavascriptCommand("receivedPrerenderInfo", std::move(value));
553 } 547 }
554 548
555 void NetInternalsMessageHandler::OnGetHistoricNetworkStats( 549 void NetInternalsMessageHandler::OnGetHistoricNetworkStats(
556 const base::ListValue* list) { 550 const base::ListValue* list) {
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 //////////////////////////////////////////////////////////////////////////////// 1169 ////////////////////////////////////////////////////////////////////////////////
1176 1170
1177 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) 1171 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui)
1178 : WebUIController(web_ui) { 1172 : WebUIController(web_ui) {
1179 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); 1173 web_ui->AddMessageHandler(new NetInternalsMessageHandler());
1180 1174
1181 // Set up the chrome://net-internals/ source. 1175 // Set up the chrome://net-internals/ source.
1182 Profile* profile = Profile::FromWebUI(web_ui); 1176 Profile* profile = Profile::FromWebUI(web_ui);
1183 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); 1177 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource());
1184 } 1178 }
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698