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 |
25 AvatarMenuActionsDesktop::AvatarMenuActionsDesktop() { | 77 AvatarMenuActionsDesktop::AvatarMenuActionsDesktop() { |
26 } | 78 } |
27 | 79 |
28 AvatarMenuActionsDesktop::~AvatarMenuActionsDesktop() { | 80 AvatarMenuActionsDesktop::~AvatarMenuActionsDesktop() { |
29 } | 81 } |
30 | 82 |
31 // static | 83 // static |
32 AvatarMenuActions* AvatarMenuActions::Create() { | 84 AvatarMenuActions* AvatarMenuActions::Create() { |
33 return new AvatarMenuActionsDesktop(); | 85 return new AvatarMenuActionsDesktop(); |
34 } | 86 } |
(...skipping 26 matching lines...) Expand all Loading... |
61 | 113 |
62 bool AvatarMenuActionsDesktop::ShouldShowAddNewProfileLink() const { | 114 bool AvatarMenuActionsDesktop::ShouldShowAddNewProfileLink() const { |
63 // |browser_| can be NULL in unit_tests. | 115 // |browser_| can be NULL in unit_tests. |
64 return !browser_ || !browser_->profile()->IsManaged(); | 116 return !browser_ || !browser_->profile()->IsManaged(); |
65 } | 117 } |
66 | 118 |
67 bool AvatarMenuActionsDesktop::ShouldShowEditProfileLink() const { | 119 bool AvatarMenuActionsDesktop::ShouldShowEditProfileLink() const { |
68 return true; | 120 return true; |
69 } | 121 } |
70 | 122 |
| 123 content::WebContents* AvatarMenuActionsDesktop::BeginSignOut() { |
| 124 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 125 Profile* current_profile = browser_->profile(); |
| 126 |
| 127 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 128 size_t index = cache.GetIndexOfProfileWithPath(current_profile->GetPath()); |
| 129 cache.SetProfileSigninRequiredAtIndex(index, true); |
| 130 |
| 131 std::string landing_url = signin::GetLandingURL("close", 1).spec(); |
| 132 GURL logout_url(GaiaUrls::GetInstance()->service_logout_url()); |
| 133 logout_url = net::AppendQueryParameter(logout_url, "continue", landing_url); |
| 134 if (!logout_override_.empty()) { |
| 135 // We're testing... |
| 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 } |
| 160 |
71 void AvatarMenuActionsDesktop::ActiveBrowserChanged(Browser* browser) { | 161 void AvatarMenuActionsDesktop::ActiveBrowserChanged(Browser* browser) { |
72 browser_ = browser; | 162 browser_ = browser; |
73 } | 163 } |
OLD | NEW |