| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/profiles/avatar_menu_actions_desktop.h" | 5 #include "chrome/browser/profiles/avatar_menu_actions_desktop.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/browser/profiles/profile_window.h" | 12 #include "chrome/browser/profiles/profile_window.h" |
| 13 #include "chrome/browser/profiles/profiles_state.h" | 13 #include "chrome/browser/profiles/profiles_state.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_dialogs.h" | 15 #include "chrome/browser/ui/browser_dialogs.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "chrome/browser/ui/chrome_pages.h" | 18 #include "chrome/browser/ui/chrome_pages.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "content/public/browser/site_instance.h" | 21 #include "content/public/browser/site_instance.h" |
| 22 #include "google_apis/gaia/gaia_urls.h" | 22 #include "google_apis/gaia/gaia_urls.h" |
| 23 #include "net/base/url_util.h" | 23 #include "net/base/url_util.h" |
| 24 | 24 |
| 25 namespace { | |
| 26 | |
| 27 class SignoutTracker : public content::WebContentsObserver { | |
| 28 public: | |
| 29 SignoutTracker(Profile* profile, | |
| 30 const GURL& signout_landing_url, | |
| 31 content::WebContents* contents, | |
| 32 Browser* browser); | |
| 33 | |
| 34 virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE; | |
| 35 virtual void DidStopLoading(content::RenderViewHost* render_view_host) | |
| 36 OVERRIDE; | |
| 37 | |
| 38 private: | |
| 39 scoped_ptr<content::WebContents> contents_; | |
| 40 GURL signout_landing_url_; | |
| 41 Profile* profile_; | |
| 42 Browser* browser_; | |
| 43 | |
| 44 DISALLOW_COPY_AND_ASSIGN(SignoutTracker); | |
| 45 }; | |
| 46 | |
| 47 SignoutTracker::SignoutTracker(Profile* profile, | |
| 48 const GURL& signout_landing_url, | |
| 49 content::WebContents* contents, | |
| 50 Browser* browser) | |
| 51 : WebContentsObserver(contents), | |
| 52 contents_(contents), | |
| 53 signout_landing_url_(signout_landing_url), | |
| 54 profile_(profile), | |
| 55 browser_(browser) { | |
| 56 } | |
| 57 | |
| 58 void SignoutTracker::DidStopLoading(content::RenderViewHost* render_view_host) { | |
| 59 // Only close when we reach the final landing; ignore redirects until then. | |
| 60 if (web_contents()->GetURL() == signout_landing_url_) { | |
| 61 if (profiles::IsNewProfileManagementEnabled()) { | |
| 62 DCHECK(profile_); | |
| 63 chrome::ShowUserManager(profile_->GetPath()); | |
| 64 } | |
| 65 Observe(NULL); | |
| 66 BrowserList::CloseAllBrowsersWithProfile(profile_); | |
| 67 delete this; /* success */ | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 void SignoutTracker::WebContentsDestroyed(content::WebContents* contents) { | |
| 72 delete this; /* failure */ | |
| 73 } | |
| 74 | |
| 75 } // namespace | |
| 76 | |
| 77 AvatarMenuActionsDesktop::AvatarMenuActionsDesktop() { | 25 AvatarMenuActionsDesktop::AvatarMenuActionsDesktop() { |
| 78 } | 26 } |
| 79 | 27 |
| 80 AvatarMenuActionsDesktop::~AvatarMenuActionsDesktop() { | 28 AvatarMenuActionsDesktop::~AvatarMenuActionsDesktop() { |
| 81 } | 29 } |
| 82 | 30 |
| 83 // static | 31 // static |
| 84 AvatarMenuActions* AvatarMenuActions::Create() { | 32 AvatarMenuActions* AvatarMenuActions::Create() { |
| 85 return new AvatarMenuActionsDesktop(); | 33 return new AvatarMenuActionsDesktop(); |
| 86 } | 34 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 113 | 61 |
| 114 bool AvatarMenuActionsDesktop::ShouldShowAddNewProfileLink() const { | 62 bool AvatarMenuActionsDesktop::ShouldShowAddNewProfileLink() const { |
| 115 // |browser_| can be NULL in unit_tests. | 63 // |browser_| can be NULL in unit_tests. |
| 116 return !browser_ || !browser_->profile()->IsManaged(); | 64 return !browser_ || !browser_->profile()->IsManaged(); |
| 117 } | 65 } |
| 118 | 66 |
| 119 bool AvatarMenuActionsDesktop::ShouldShowEditProfileLink() const { | 67 bool AvatarMenuActionsDesktop::ShouldShowEditProfileLink() const { |
| 120 return true; | 68 return true; |
| 121 } | 69 } |
| 122 | 70 |
| 123 content::WebContents* AvatarMenuActionsDesktop::BeginSignOut() { | 71 void AvatarMenuActionsDesktop::BeginSignOut() { |
| 124 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 72 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 125 Profile* current_profile = browser_->profile(); | 73 Profile* current_profile = browser_->profile(); |
| 126 | 74 |
| 127 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 75 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 128 size_t index = cache.GetIndexOfProfileWithPath(current_profile->GetPath()); | 76 size_t index = cache.GetIndexOfProfileWithPath(current_profile->GetPath()); |
| 129 cache.SetProfileSigninRequiredAtIndex(index, true); | 77 cache.SetProfileSigninRequiredAtIndex(index, true); |
| 130 | 78 |
| 131 std::string landing_url = signin::GetLandingURL("close", 1).spec(); | 79 // Close all the browser windows for this profile and open the user manager. |
| 132 GURL logout_url(GaiaUrls::GetInstance()->service_logout_url()); | 80 DCHECK(profiles::IsNewProfileManagementEnabled()); |
| 133 logout_url = net::AppendQueryParameter(logout_url, "continue", landing_url); | 81 DCHECK(current_profile); |
| 134 if (!logout_override_.empty()) { | 82 chrome::ShowUserManager(current_profile->GetPath()); |
| 135 // We're testing... | 83 BrowserList::CloseAllBrowsersWithProfile(current_profile); |
| 136 landing_url = logout_override_; | |
| 137 logout_url = GURL(logout_override_); | |
| 138 } | |
| 139 | |
| 140 content::WebContents::CreateParams create_params(current_profile); | |
| 141 create_params.site_instance = | |
| 142 content::SiteInstance::CreateForURL(current_profile, logout_url); | |
| 143 content::WebContents* contents = content::WebContents::Create(create_params); | |
| 144 // This object may be destructed when the menu closes but we need something | |
| 145 // around to finish the sign-out process and close the profile windows. | |
| 146 new SignoutTracker(current_profile, | |
| 147 GURL(landing_url), | |
| 148 contents, | |
| 149 browser_); | |
| 150 contents->GetController().LoadURL( | |
| 151 logout_url, content::Referrer(), | |
| 152 content::PAGE_TRANSITION_GENERATED, std::string()); | |
| 153 | |
| 154 return contents; // returned for testing purposes | |
| 155 } | |
| 156 | |
| 157 void AvatarMenuActionsDesktop::SetLogoutURL(const std::string& logout_url) { | |
| 158 logout_override_ = logout_url; | |
| 159 } | 84 } |
| 160 | 85 |
| 161 void AvatarMenuActionsDesktop::ActiveBrowserChanged(Browser* browser) { | 86 void AvatarMenuActionsDesktop::ActiveBrowserChanged(Browser* browser) { |
| 162 browser_ = browser; | 87 browser_ = browser; |
| 163 } | 88 } |
| OLD | NEW |