Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chrome/browser/ui/cocoa/browser/profile_chooser_controller.mm

Issue 128513002: Refactor the code that creates the list of secondary accounts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit. sigh. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/ui/cocoa/browser/profile_chooser_controller.h" 7 #import "chrome/browser/ui/cocoa/browser/profile_chooser_controller.h"
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/stl_util.h"
11 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/profiles/avatar_menu.h" 13 #include "chrome/browser/profiles/avatar_menu.h"
15 #include "chrome/browser/profiles/avatar_menu_observer.h" 14 #include "chrome/browser/profiles/avatar_menu_observer.h"
16 #include "chrome/browser/profiles/profile_info_cache.h" 15 #include "chrome/browser/profiles/profile_info_cache.h"
17 #include "chrome/browser/profiles/profile_info_util.h" 16 #include "chrome/browser/profiles/profile_info_util.h"
18 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/profiles/profile_window.h" 18 #include "chrome/browser/profiles/profile_window.h"
19 #include "chrome/browser/profiles/profiles_state.h"
20 #include "chrome/browser/signin/profile_oauth2_token_service.h" 20 #include "chrome/browser/signin/profile_oauth2_token_service.h"
21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
22 #include "chrome/browser/signin/signin_manager.h" 22 #include "chrome/browser/signin/signin_manager.h"
23 #include "chrome/browser/signin/signin_manager_factory.h" 23 #include "chrome/browser/signin/signin_manager_factory.h"
24 #include "chrome/browser/signin/signin_promo.h" 24 #include "chrome/browser/signin/signin_promo.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_dialogs.h" 26 #include "chrome/browser/ui/browser_dialogs.h"
27 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/chrome_style.h" 28 #include "chrome/browser/ui/chrome_style.h"
29 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 29 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 [container addSubview:accountEmails]; 573 [container addSubview:accountEmails];
574 [container setFrameSize:NSMakeSize( 574 [container setFrameSize:NSMakeSize(
575 NSWidth([container frame]), NSMaxY([accountEmails frame]))]; 575 NSWidth([container frame]), NSMaxY([accountEmails frame]))];
576 return container.autorelease(); 576 return container.autorelease();
577 } 577 }
578 578
579 - (NSView*)createAccountsListWithRect:(NSRect)rect { 579 - (NSView*)createAccountsListWithRect:(NSRect)rect {
580 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); 580 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
581 currentProfileAccounts_.clear(); 581 currentProfileAccounts_.clear();
582 582
583 // The primary account should always be listed first. However, the vector
584 // returned by ProfileOAuth2TokenService::GetAccounts() will contain the
585 // primary account too. Ignore it when it appears later.
586 // TODO(rogerta): we still need to further differentiate the primary account
587 // from the others, so more work is likely required here: crbug.com/311124.
588 Profile* profile = browser_->profile(); 583 Profile* profile = browser_->profile();
589
590 // TODO(noms): This code is duplicated by the views implementation. See
591 // crbug.com/331805.
592 std::string primaryAccount = 584 std::string primaryAccount =
593 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); 585 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername();
594 DCHECK(!primaryAccount.empty()); 586 DCHECK(!primaryAccount.empty());
595 std::vector<std::string> accounts = 587 std::vector<std::string>accounts =
596 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->GetAccounts(); 588 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount);
597 DCHECK_EQ(1, std::count_if(accounts.begin(), accounts.end(), 589
598 std::bind1st(std::equal_to<std::string>(),
599 primaryAccount)));
600 rect.origin.y = 0; 590 rect.origin.y = 0;
601 for (size_t i = 0; i < accounts.size(); ++i) { 591 for (size_t i = 0; i < accounts.size(); ++i) {
602 // Save the original email address, as the button text could be elided. 592 // Save the original email address, as the button text could be elided.
603 currentProfileAccounts_[i] = accounts[i]; 593 currentProfileAccounts_[i] = accounts[i];
604 if (primaryAccount != accounts[i]) { 594 NSButton* accountButton = [self makeAccountButtonWithRect:rect
605 NSButton* accountButton = [self makeAccountButtonWithRect:rect 595 title:accounts[i]
606 title:accounts[i] 596 canBeDeleted:true];
607 canBeDeleted:true]; 597 [accountButton setTag:i];
608 [accountButton setTag:i]; 598 [container addSubview:accountButton];
609 [container addSubview:accountButton]; 599 rect.origin.y = NSMaxY([accountButton frame]) + kSmallVerticalSpacing;
610 rect.origin.y = NSMaxY([accountButton frame]) + kSmallVerticalSpacing;
611 }
612 } 600 }
613 601
614 // Add the primary account button. It doesn't need a tag, as it cannot be 602 // The primary account should always be listed first. It doesn't need a tag,
615 // removed. 603 // as it cannot be removed.
604 // TODO(rogerta): we still need to further differentiate the primary account
605 // from the others, so more work is likely required here: crbug.com/311124.
Alexei Svitkine (slow) 2014/01/08 21:28:37 Should this TODO be in the utility function? Or do
noms (inactive) 2014/01/08 21:35:13 Differentiate in the UI. Fixed. On 2014/01/08 21:2
616 NSButton* accountButton = [self makeAccountButtonWithRect:rect 606 NSButton* accountButton = [self makeAccountButtonWithRect:rect
617 title:primaryAccount 607 title:primaryAccount
618 canBeDeleted:false]; 608 canBeDeleted:false];
619 [container addSubview:accountButton]; 609 [container addSubview:accountButton];
620 [container setFrameSize:NSMakeSize(NSWidth([container frame]), 610 [container setFrameSize:NSMakeSize(NSWidth([container frame]),
621 NSMaxY([accountButton frame]))]; 611 NSMaxY([accountButton frame]))];
622 return container.autorelease(); 612 return container.autorelease();
623 } 613 }
624 614
625 - (NSView*) createGaiaEmbeddedView { 615 - (NSView*) createGaiaEmbeddedView {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 [button setImagePosition:NSImageRight]; 682 [button setImagePosition:NSImageRight];
693 [button setTarget:self]; 683 [button setTarget:self];
694 [button setAction:@selector(removeAccount:)]; 684 [button setAction:@selector(removeAccount:)];
695 } 685 }
696 686
697 return button.autorelease(); 687 return button.autorelease();
698 } 688 }
699 689
700 @end 690 @end
701 691
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698