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

Unified Diff: chrome/browser/managed_mode/managed_mode_interstitial.cc

Issue 250803004: Cleanup: Refactor ManagedModeInterstitial to not "delete this" in the ctor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/managed_mode/managed_mode_interstitial.cc
diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.cc b/chrome/browser/managed_mode/managed_mode_interstitial.cc
index 04dede1c3e74322fa7bb27c609560e072e194cc4..e67e759c2956a99f8f084f96c7b6dd6e2d65210d 100644
--- a/chrome/browser/managed_mode/managed_mode_interstitial.cc
+++ b/chrome/browser/managed_mode/managed_mode_interstitial.cc
@@ -33,6 +33,21 @@
using content::BrowserThread;
+ManagedModeInterstitial::~ManagedModeInterstitial() {}
+
+// static
+void ManagedModeInterstitial::Show(content::WebContents* web_contents,
+ const GURL& url,
+ const base::Callback<void(bool)>& callback) {
+ ManagedModeInterstitial* interstitial =
+ new ManagedModeInterstitial(web_contents, url, callback);
+
+ // If Init() does not complete fully, immediately delete the interstitial.
+ if (!interstitial->Init())
+ delete interstitial;
+ // Else |interstitial_page_| is responsible for deleting it.
Bernhard Bauer 2014/04/25 11:10:18 Nit: "Otherwise" instead of "else".
Marc Treib 2014/04/25 12:02:19 Done.
+}
+
ManagedModeInterstitial::ManagedModeInterstitial(
content::WebContents* web_contents,
const GURL& url,
@@ -40,19 +55,20 @@ ManagedModeInterstitial::ManagedModeInterstitial(
: web_contents_(web_contents),
interstitial_page_(NULL),
url_(url),
- callback_(callback) {
+ callback_(callback) {}
+
+bool ManagedModeInterstitial::Init() {
if (ShouldProceed()) {
// It can happen that the site was only allowed very recently and the URL
// filter on the IO thread had not been updated yet. Proceed with the
// request without showing the interstitial.
DispatchContinueRequest(true);
- delete this;
- return;
+ return false;
}
- InfoBarService* service = InfoBarService::FromWebContents(web_contents);
+ InfoBarService* service = InfoBarService::FromWebContents(web_contents_);
if (service) {
- // Remove all the infobars which are attached to |web_contents| and for
+ // Remove all the infobars which are attached to |web_contents_| and for
// which ShouldExpire() returns true.
content::LoadCommittedDetails details;
// |details.is_in_page| is default false, and |details.is_main_frame| is
@@ -60,7 +76,7 @@ ManagedModeInterstitial::ManagedModeInterstitial(
// true.
DCHECK(details.is_navigation_to_different_page());
const content::NavigationController& controller =
- web_contents->GetController();
+ web_contents_->GetController();
details.entry = controller.GetActiveEntry();
if (controller.GetLastCommittedEntry()) {
details.previous_entry_index = controller.GetLastCommittedEntryIndex();
@@ -78,7 +94,7 @@ ManagedModeInterstitial::ManagedModeInterstitial(
// TODO(bauerb): Extract an observer callback on ManagedUserService for this.
Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext());
PrefService* prefs = profile->GetPrefs();
pref_change_registrar_.Init(prefs);
pref_change_registrar_.Add(
@@ -96,11 +112,11 @@ ManagedModeInterstitial::ManagedModeInterstitial(
languages_ = prefs->GetString(prefs::kAcceptLanguages);
interstitial_page_ =
- content::InterstitialPage::Create(web_contents, true, url_, this);
+ content::InterstitialPage::Create(web_contents_, true, url_, this);
interstitial_page_->Show();
-}
-ManagedModeInterstitial::~ManagedModeInterstitial() {}
+ return true;
+}
std::string ManagedModeInterstitial::GetHTMLContents() {
base::DictionaryValue strings;

Powered by Google App Engine
This is Rietveld 408576698