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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 // Compensate for built-in vertical padding in the anchor view's image. | 227 // Compensate for built-in vertical padding in the anchor view's image. |
228 set_anchor_view_insets(gfx::Insets(kArrowHeight, 0, kArrowHeight, 0)); | 228 set_anchor_view_insets(gfx::Insets(kArrowHeight, 0, kArrowHeight, 0)); |
229 | 229 |
230 ResetLinksAndButtons(); | 230 ResetLinksAndButtons(); |
231 | 231 |
232 avatar_menu_.reset(new AvatarMenu( | 232 avatar_menu_.reset(new AvatarMenu( |
233 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 233 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
234 this, | 234 this, |
235 browser_)); | 235 browser_)); |
236 avatar_menu_->RebuildMenu(); | 236 avatar_menu_->RebuildMenu(); |
237 | |
238 Profile* profile = browser_->profile(); | |
239 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->AddObserver(this); | |
237 } | 240 } |
238 | 241 |
239 ProfileChooserView::~ProfileChooserView() { | 242 ProfileChooserView::~ProfileChooserView() { |
243 Profile* profile = browser_->profile(); | |
244 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> | |
245 RemoveObserver(this); | |
240 } | 246 } |
241 | 247 |
242 void ProfileChooserView::ResetLinksAndButtons() { | 248 void ProfileChooserView::ResetLinksAndButtons() { |
243 manage_accounts_link_ = NULL; | 249 manage_accounts_link_ = NULL; |
244 signout_current_profile_link_ = NULL; | 250 signout_current_profile_link_ = NULL; |
245 signin_current_profile_link_ = NULL; | 251 signin_current_profile_link_ = NULL; |
246 change_photo_link_ = NULL; | 252 change_photo_link_ = NULL; |
247 guest_button_ = NULL; | 253 guest_button_ = NULL; |
248 end_guest_button_ = NULL; | 254 end_guest_button_ = NULL; |
249 users_button_ = NULL; | 255 users_button_ = NULL; |
250 add_user_button_ = NULL; | 256 add_user_button_ = NULL; |
251 add_account_button_ = NULL; | 257 add_account_button_ = NULL; |
252 open_other_profile_indexes_map_.clear(); | 258 open_other_profile_indexes_map_.clear(); |
259 view_mode_ = PROFILE_CHOOSER_VIEW; | |
sky
2013/11/04 21:19:33
Is there a reason this is here not the member init
guohui
2013/11/05 14:40:01
Because this is the current central place to initi
sky
2013/11/05 15:53:50
For view_mode_ don't you only want it reset to the
guohui
2013/11/05 20:00:50
it is the same as all other members, first reset t
| |
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 |