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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_interstitial.cc

Issue 2842833003: Update SupportsUserData uses with unique_ptr. (Closed)
Patch Set: rebase Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/supervised_user/supervised_user_interstitial.h" 5 #include "chrome/browser/supervised_user/supervised_user_interstitial.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "chrome/browser/ui/tabs/tab_strip_model.h" 46 #include "chrome/browser/ui/tabs/tab_strip_model.h"
47 #endif 47 #endif
48 48
49 using content::BrowserThread; 49 using content::BrowserThread;
50 using content::WebContents; 50 using content::WebContents;
51 51
52 namespace { 52 namespace {
53 53
54 class TabCloser : public content::WebContentsUserData<TabCloser> { 54 class TabCloser : public content::WebContentsUserData<TabCloser> {
55 public: 55 public:
56 ~TabCloser() override {}
57
56 static void MaybeClose(WebContents* web_contents) { 58 static void MaybeClose(WebContents* web_contents) {
57 DCHECK(web_contents); 59 DCHECK(web_contents);
58 60
59 // Close the tab only if there is a browser for it (which is not the case 61 // Close the tab only if there is a browser for it (which is not the case
60 // for example in a <webview>). 62 // for example in a <webview>).
61 #if !defined(OS_ANDROID) 63 #if !defined(OS_ANDROID)
62 if (!chrome::FindBrowserWithWebContents(web_contents)) 64 if (!chrome::FindBrowserWithWebContents(web_contents))
63 return; 65 return;
64 #endif 66 #endif
65 TabCloser::CreateForWebContents(web_contents); 67 TabCloser::CreateForWebContents(web_contents);
66 } 68 }
67 69
68 private: 70 private:
69 friend class content::WebContentsUserData<TabCloser>; 71 friend class content::WebContentsUserData<TabCloser>;
70 72
71 explicit TabCloser(WebContents* web_contents) 73 explicit TabCloser(WebContents* web_contents)
72 : web_contents_(web_contents), weak_ptr_factory_(this) { 74 : web_contents_(web_contents), weak_ptr_factory_(this) {
73 BrowserThread::PostTask( 75 BrowserThread::PostTask(
74 BrowserThread::UI, 76 BrowserThread::UI,
75 FROM_HERE, 77 FROM_HERE,
76 base::Bind(&TabCloser::CloseTabImpl, weak_ptr_factory_.GetWeakPtr())); 78 base::Bind(&TabCloser::CloseTabImpl, weak_ptr_factory_.GetWeakPtr()));
77 } 79 }
78 ~TabCloser() override {}
79 80
80 void CloseTabImpl() { 81 void CloseTabImpl() {
81 // On Android, FindBrowserWithWebContents and TabStripModel don't exist. 82 // On Android, FindBrowserWithWebContents and TabStripModel don't exist.
82 #if !defined(OS_ANDROID) 83 #if !defined(OS_ANDROID)
83 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); 84 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
84 DCHECK(browser); 85 DCHECK(browser);
85 TabStripModel* tab_strip = browser->tab_strip_model(); 86 TabStripModel* tab_strip = browser->tab_strip_model();
86 DCHECK_NE(TabStripModel::kNoTab, 87 DCHECK_NE(TabStripModel::kNoTab,
87 tab_strip->GetIndexOfWebContents(web_contents_)); 88 tab_strip->GetIndexOfWebContents(web_contents_));
88 if (tab_strip->count() <= 1) { 89 if (tab_strip->count() <= 1) {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 SupervisedUserServiceFactory::GetForProfile(profile_); 349 SupervisedUserServiceFactory::GetForProfile(profile_);
349 supervised_user_service->RemoveObserver(this); 350 supervised_user_service->RemoveObserver(this);
350 351
351 if (!callback_.is_null()) 352 if (!callback_.is_null())
352 callback_.Run(continue_request); 353 callback_.Run(continue_request);
353 354
354 // After this, the WebContents may be destroyed. Make sure we don't try to use 355 // After this, the WebContents may be destroyed. Make sure we don't try to use
355 // it again. 356 // it again.
356 web_contents_ = nullptr; 357 web_contents_ = nullptr;
357 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698