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) { |
Roger Tawa OOO till Jul 10th
2013/11/04 19:13:14
Initialize view_mode_ here?
guohui
2013/11/04 19:56:32
Done.
| |
225 // Reset the default margins inherited from the BubbleDelegateView. | 225 // Reset the default margins inherited from the BubbleDelegateView. |
226 set_margins(gfx::Insets()); | 226 set_margins(gfx::Insets()); |
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(); |
253 } | 259 } |
254 | 260 |
255 void ProfileChooserView::Init() { | 261 void ProfileChooserView::Init() { |
256 ShowView(PROFILE_CHOOSER_VIEW, avatar_menu_.get()); | 262 ShowView(PROFILE_CHOOSER_VIEW, avatar_menu_.get()); |
257 } | 263 } |
258 | 264 |
259 void ProfileChooserView::OnAvatarMenuChanged( | 265 void ProfileChooserView::OnAvatarMenuChanged( |
260 AvatarMenu* avatar_menu) { | 266 AvatarMenu* avatar_menu) { |
261 // Refresh the view with the new menu. We can't just update the local copy | 267 // 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 | 268 // as this may have been triggered by a sign out action, in which case |
263 // the view is being destroyed. | 269 // the view is being destroyed. |
264 ShowView(PROFILE_CHOOSER_VIEW, avatar_menu); | 270 ShowView(PROFILE_CHOOSER_VIEW, avatar_menu); |
265 } | 271 } |
266 | 272 |
273 void ProfileChooserView::OnRefreshTokenAvailable( | |
274 const std::string& account_id) { | |
275 // Refresh the account management view when a new account is added to the | |
276 // profile. | |
277 if (view_mode_ == ACCOUNT_MANAGEMENT_VIEW || | |
278 view_mode_ == GAIA_SIGNIN_VIEW || | |
279 view_mode_ == GAIA_ADD_ACCOUNT_VIEW) | |
280 ShowView(ACCOUNT_MANAGEMENT_VIEW, avatar_menu_.get()); | |
Roger Tawa OOO till Jul 10th
2013/11/04 19:13:14
Should add { and } around if block.
guohui
2013/11/04 19:56:32
Done.
| |
281 } | |
282 | |
283 void ProfileChooserView::OnRefreshTokenRevoked(const std::string& account_id) { | |
284 // Refresh the account management view when an account is removed from the | |
285 // profile. | |
286 if (view_mode_ == ACCOUNT_MANAGEMENT_VIEW) | |
287 ShowView(ACCOUNT_MANAGEMENT_VIEW, avatar_menu_.get()); | |
288 } | |
289 | |
267 void ProfileChooserView::ShowView(BubbleViewMode view_to_display, | 290 void ProfileChooserView::ShowView(BubbleViewMode view_to_display, |
268 AvatarMenu* avatar_menu) { | 291 AvatarMenu* avatar_menu) { |
269 // The account management view should only be displayed if the active profile | 292 // The account management view should only be displayed if the active profile |
270 // is signed in. | 293 // is signed in. |
271 if (view_to_display == ACCOUNT_MANAGEMENT_VIEW) { | 294 if (view_to_display == ACCOUNT_MANAGEMENT_VIEW) { |
272 const AvatarMenu::Item& active_item = avatar_menu->GetItemAt( | 295 const AvatarMenu::Item& active_item = avatar_menu->GetItemAt( |
273 avatar_menu->GetActiveProfileIndex()); | 296 avatar_menu->GetActiveProfileIndex()); |
274 DCHECK(active_item.signed_in); | 297 DCHECK(active_item.signed_in); |
275 } | 298 } |
276 | 299 |
277 ResetLinksAndButtons(); | 300 ResetLinksAndButtons(); |
278 RemoveAllChildViews(true); | 301 RemoveAllChildViews(true); |
302 view_mode_ = view_to_display; | |
279 | 303 |
280 views::GridLayout* layout = CreateSingleColumnLayout(this); | 304 views::GridLayout* layout = CreateSingleColumnLayout(this); |
281 layout->set_minimum_size(gfx::Size(kMinMenuWidth, 0)); | 305 layout->set_minimum_size(gfx::Size(kMinMenuWidth, 0)); |
282 | 306 |
283 if (view_to_display == GAIA_SIGNIN_VIEW || | 307 if (view_to_display == GAIA_SIGNIN_VIEW || |
284 view_to_display == GAIA_ADD_ACCOUNT_VIEW) { | 308 view_to_display == GAIA_ADD_ACCOUNT_VIEW) { |
285 // Minimum size for embedded sign in pages as defined in Gaia. | 309 // Minimum size for embedded sign in pages as defined in Gaia. |
286 const int kMinGaiaViewWidth = 320; | 310 const int kMinGaiaViewWidth = 320; |
287 const int kMinGaiaViewHeight = 500; | 311 const int kMinGaiaViewHeight = 500; |
288 Profile* profile = browser_->profile(); | 312 Profile* profile = browser_->profile(); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 648 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
625 | 649 |
626 add_account_button_ = new views::BlueButton( | 650 add_account_button_ = new views::BlueButton( |
627 this, | 651 this, |
628 l10n_util::GetStringFUTF16(IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, | 652 l10n_util::GetStringFUTF16(IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, |
629 avatar_item.name)); | 653 avatar_item.name)); |
630 layout->StartRow(1, 0); | 654 layout->StartRow(1, 0); |
631 layout->AddView(add_account_button_); | 655 layout->AddView(add_account_button_); |
632 return view; | 656 return view; |
633 } | 657 } |
OLD | NEW |