Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/profiles/force_signout_dialog.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/strings/string16.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/signin/force_signout_timer.h" | |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "chrome/browser/ui/browser_list.h" | |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 15 #include "chrome/browser/ui/views/profiles/force_signout_dialog_view.h" | |
| 16 #include "chrome/grit/generated_resources.h" | |
| 17 #include "components/app_modal/app_modal_dialog_queue.h" | |
| 18 #include "components/signin/core/browser/signin_manager.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 void Signout(SigninManager* signin_manager) { | |
| 24 signin_manager->SignOut( | |
| 25 signin_metrics::AUTHENTICATION_FAILED_WITH_FORCE_SIGNIN, | |
| 26 signin_metrics::SignoutDelete::KEEPING); | |
| 27 } | |
| 28 | |
| 29 content::WebContents* GetWebContentsFromBrowser(Browser* browser) { | |
| 30 content::WebContents* web_contents = | |
| 31 browser->tab_strip_model()->GetActiveWebContents(); | |
| 32 if (web_contents == nullptr) | |
|
sky
2017/05/04 03:45:11
This should be a DCHECK. You earlier check the siz
zmin
2017/05/04 23:13:52
Done.
| |
| 33 return browser->tab_strip_model()->GetWebContentsAt(0); | |
| 34 else | |
| 35 return web_contents; | |
| 36 } | |
| 37 | |
| 38 bool IsBrowserBelongedToProfile(Browser* browser, Profile* profile) { | |
|
sky
2017/05/04 03:45:11
How about naming this IsMatchingBrowser and includ
zmin
2017/05/04 23:13:52
Done.
Two questions on the implementation:
sky
2017/05/05 00:00:10
Be careful there. You should verify you get the ri
| |
| 39 return browser->profile()->GetOriginalProfile() == | |
| 40 profile->GetOriginalProfile(); | |
| 41 } | |
| 42 | |
| 43 // Find a browser that is assoicated with |profile| to show the dialog for | |
| 44 // Sign out warning. | |
| 45 Browser* FindBrowserWithProfile(Profile* profile) { | |
| 46 Browser* browser = BrowserList::GetInstance()->GetLastActive(); | |
| 47 if (browser && IsBrowserBelongedToProfile(browser, profile) && | |
| 48 !browser->tab_strip_model()->empty()) { | |
| 49 return browser; | |
| 50 } | |
| 51 for (auto* browser : *BrowserList::GetInstance()) { | |
| 52 if (IsBrowserBelongedToProfile(browser, profile) && | |
| 53 !browser->tab_strip_model()->empty()) { | |
| 54 return browser; | |
| 55 } | |
| 56 } | |
| 57 return nullptr; | |
| 58 } | |
| 59 | |
| 60 } // namespace | |
| 61 | |
| 62 // static | |
| 63 void ForceSignoutDialog::ShowDialog(Profile* profile, | |
| 64 SigninManager* signin_manager, | |
| 65 ForceSignoutTimer* signout_timer) { | |
| 66 Browser* browser = FindBrowserWithProfile(profile); | |
| 67 if (browser == nullptr) { // If there is no browser, we can just sign | |
| 68 // out profile directly. | |
| 69 Signout(signin_manager); | |
| 70 return; | |
| 71 } | |
| 72 app_modal::AppModalDialogQueue::GetInstance()->AddDialog( | |
| 73 new ForceSignoutDialog(browser, signin_manager, signout_timer)); | |
| 74 } | |
| 75 | |
| 76 app_modal::NativeAppModalDialog* ForceSignoutDialog::CreateNativeDialog() { | |
| 77 return new ForceSignoutDialogView(browser_, this); | |
| 78 } | |
| 79 | |
| 80 void ForceSignoutDialog::OnAccept() { | |
| 81 CompleteDialog(); | |
| 82 Signout(signin_manager_); | |
| 83 } | |
| 84 void ForceSignoutDialog::OnCancel() { | |
| 85 CompleteDialog(); | |
| 86 signout_timer_->Start(); | |
| 87 } | |
| 88 | |
| 89 std::string ForceSignoutDialog::GetEmail() { | |
| 90 return signin_manager_->GetAuthenticatedAccountInfo().email; | |
| 91 } | |
| 92 | |
| 93 bool ForceSignoutDialog::IsDelayAllowed() { | |
| 94 return signout_timer_ != nullptr; | |
| 95 } | |
| 96 | |
| 97 ForceSignoutDialog::ForceSignoutDialog(Browser* browser, | |
| 98 SigninManager* signin_manager, | |
| 99 ForceSignoutTimer* signout_timer) | |
| 100 : app_modal::AppModalDialog( | |
|
sky
2017/05/04 03:45:11
Why are you using app_modal_dialog here? I underst
zmin
2017/05/04 23:13:52
No, I don't want to be tied to WebContents. Howeve
sky
2017/05/05 00:00:10
Also, what happens if the browser you are anchored
sky
2017/05/05 00:00:10
Also, user could still interact with non-browser w
| |
| 101 GetWebContentsFromBrowser(browser), | |
| 102 l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_TITLE)), | |
| 103 browser_(browser), | |
| 104 signin_manager_(signin_manager), | |
| 105 signout_timer_(signout_timer) {} | |
| OLD | NEW |