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/ui/views/profile_chooser_view.h" | 5 #include "chrome/browser/ui/views/profile_chooser_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/profile_info_util.h" | 10 #include "chrome/browser/profiles/profile_info_util.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 void ProfileChooserView::Hide() { | 214 void ProfileChooserView::Hide() { |
215 if (IsShowing()) | 215 if (IsShowing()) |
216 profile_bubble_->GetWidget()->Close(); | 216 profile_bubble_->GetWidget()->Close(); |
217 } | 217 } |
218 | 218 |
219 ProfileChooserView::ProfileChooserView(views::View* anchor_view, | 219 ProfileChooserView::ProfileChooserView(views::View* anchor_view, |
220 views::BubbleBorder::Arrow arrow, | 220 views::BubbleBorder::Arrow arrow, |
221 const gfx::Rect& anchor_rect, | 221 const gfx::Rect& anchor_rect, |
222 Browser* browser) | 222 Browser* browser) |
223 : BubbleDelegateView(anchor_view, arrow), | 223 : BubbleDelegateView(anchor_view, arrow), |
224 browser_(browser) { | 224 browser_(browser), |
| 225 view_mode_(PROFILE_CHOOSER_VIEW) { |
225 // Reset the default margins inherited from the BubbleDelegateView. | 226 // Reset the default margins inherited from the BubbleDelegateView. |
226 set_margins(gfx::Insets()); | 227 set_margins(gfx::Insets()); |
227 // Compensate for built-in vertical padding in the anchor view's image. | 228 // Compensate for built-in vertical padding in the anchor view's image. |
228 set_anchor_view_insets(gfx::Insets(kArrowHeight, 0, kArrowHeight, 0)); | 229 set_anchor_view_insets(gfx::Insets(kArrowHeight, 0, kArrowHeight, 0)); |
229 | 230 |
230 ResetLinksAndButtons(); | 231 ResetLinksAndButtons(); |
231 | 232 |
232 avatar_menu_.reset(new AvatarMenu( | 233 avatar_menu_.reset(new AvatarMenu( |
233 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 234 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
234 this, | 235 this, |
235 browser_)); | 236 browser_)); |
236 avatar_menu_->RebuildMenu(); | 237 avatar_menu_->RebuildMenu(); |
| 238 |
| 239 Profile* profile = browser_->profile(); |
| 240 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->AddObserver(this); |
237 } | 241 } |
238 | 242 |
239 ProfileChooserView::~ProfileChooserView() { | 243 ProfileChooserView::~ProfileChooserView() { |
| 244 Profile* profile = browser_->profile(); |
| 245 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> |
| 246 RemoveObserver(this); |
240 } | 247 } |
241 | 248 |
242 void ProfileChooserView::ResetLinksAndButtons() { | 249 void ProfileChooserView::ResetLinksAndButtons() { |
243 manage_accounts_link_ = NULL; | 250 manage_accounts_link_ = NULL; |
244 signout_current_profile_link_ = NULL; | 251 signout_current_profile_link_ = NULL; |
245 signin_current_profile_link_ = NULL; | 252 signin_current_profile_link_ = NULL; |
246 change_photo_link_ = NULL; | 253 change_photo_link_ = NULL; |
247 guest_button_ = NULL; | 254 guest_button_ = NULL; |
248 end_guest_button_ = NULL; | 255 end_guest_button_ = NULL; |
249 users_button_ = NULL; | 256 users_button_ = NULL; |
250 add_user_button_ = NULL; | 257 add_user_button_ = NULL; |
251 add_account_button_ = NULL; | 258 add_account_button_ = NULL; |
252 open_other_profile_indexes_map_.clear(); | 259 open_other_profile_indexes_map_.clear(); |
253 } | 260 } |
254 | 261 |
255 void ProfileChooserView::Init() { | 262 void ProfileChooserView::Init() { |
256 ShowView(PROFILE_CHOOSER_VIEW, avatar_menu_.get()); | 263 ShowView(PROFILE_CHOOSER_VIEW, avatar_menu_.get()); |
257 } | 264 } |
258 | 265 |
259 void ProfileChooserView::OnAvatarMenuChanged( | 266 void ProfileChooserView::OnAvatarMenuChanged( |
260 AvatarMenu* avatar_menu) { | 267 AvatarMenu* avatar_menu) { |
261 // Refresh the view with the new menu. We can't just update the local copy | 268 // Refresh the view with the new menu. We can't just update the local copy |
262 // as this may have been triggered by a sign out action, in which case | 269 // as this may have been triggered by a sign out action, in which case |
263 // the view is being destroyed. | 270 // the view is being destroyed. |
264 ShowView(PROFILE_CHOOSER_VIEW, avatar_menu); | 271 ShowView(PROFILE_CHOOSER_VIEW, avatar_menu); |
265 } | 272 } |
266 | 273 |
| 274 void ProfileChooserView::OnRefreshTokenAvailable( |
| 275 const std::string& account_id) { |
| 276 // Refresh the account management view when a new account is added to the |
| 277 // profile. |
| 278 if (view_mode_ == ACCOUNT_MANAGEMENT_VIEW || |
| 279 view_mode_ == GAIA_SIGNIN_VIEW || |
| 280 view_mode_ == GAIA_ADD_ACCOUNT_VIEW) { |
| 281 ShowView(ACCOUNT_MANAGEMENT_VIEW, avatar_menu_.get()); |
| 282 } |
| 283 } |
| 284 |
| 285 void ProfileChooserView::OnRefreshTokenRevoked(const std::string& account_id) { |
| 286 // Refresh the account management view when an account is removed from the |
| 287 // profile. |
| 288 if (view_mode_ == ACCOUNT_MANAGEMENT_VIEW) |
| 289 ShowView(ACCOUNT_MANAGEMENT_VIEW, avatar_menu_.get()); |
| 290 } |
| 291 |
267 void ProfileChooserView::ShowView(BubbleViewMode view_to_display, | 292 void ProfileChooserView::ShowView(BubbleViewMode view_to_display, |
268 AvatarMenu* avatar_menu) { | 293 AvatarMenu* avatar_menu) { |
269 // The account management view should only be displayed if the active profile | 294 // The account management view should only be displayed if the active profile |
270 // is signed in. | 295 // is signed in. |
271 if (view_to_display == ACCOUNT_MANAGEMENT_VIEW) { | 296 if (view_to_display == ACCOUNT_MANAGEMENT_VIEW) { |
272 const AvatarMenu::Item& active_item = avatar_menu->GetItemAt( | 297 const AvatarMenu::Item& active_item = avatar_menu->GetItemAt( |
273 avatar_menu->GetActiveProfileIndex()); | 298 avatar_menu->GetActiveProfileIndex()); |
274 DCHECK(active_item.signed_in); | 299 DCHECK(active_item.signed_in); |
275 } | 300 } |
276 | 301 |
277 ResetLinksAndButtons(); | 302 ResetLinksAndButtons(); |
278 RemoveAllChildViews(true); | 303 RemoveAllChildViews(true); |
| 304 view_mode_ = view_to_display; |
279 | 305 |
280 views::GridLayout* layout = CreateSingleColumnLayout(this); | 306 views::GridLayout* layout = CreateSingleColumnLayout(this); |
281 layout->set_minimum_size(gfx::Size(kMinMenuWidth, 0)); | 307 layout->set_minimum_size(gfx::Size(kMinMenuWidth, 0)); |
282 | 308 |
283 if (view_to_display == GAIA_SIGNIN_VIEW || | 309 if (view_to_display == GAIA_SIGNIN_VIEW || |
284 view_to_display == GAIA_ADD_ACCOUNT_VIEW) { | 310 view_to_display == GAIA_ADD_ACCOUNT_VIEW) { |
285 // Minimum size for embedded sign in pages as defined in Gaia. | 311 // Minimum size for embedded sign in pages as defined in Gaia. |
286 const int kMinGaiaViewWidth = 320; | 312 const int kMinGaiaViewWidth = 320; |
287 const int kMinGaiaViewHeight = 500; | 313 const int kMinGaiaViewHeight = 500; |
288 Profile* profile = browser_->profile(); | 314 Profile* profile = browser_->profile(); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 650 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
625 | 651 |
626 add_account_button_ = new views::BlueButton( | 652 add_account_button_ = new views::BlueButton( |
627 this, | 653 this, |
628 l10n_util::GetStringFUTF16(IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, | 654 l10n_util::GetStringFUTF16(IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, |
629 avatar_item.name)); | 655 avatar_item.name)); |
630 layout->StartRow(1, 0); | 656 layout->StartRow(1, 0); |
631 layout->AddView(add_account_button_); | 657 layout->AddView(add_account_button_); |
632 return view; | 658 return view; |
633 } | 659 } |
OLD | NEW |