1c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved.
27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file.
47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
5c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/prefs/pref_service.h"
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/browser_process.h"
10effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "chrome/browser/lifetime/application_lifetime.h"
115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/prefs/incognito_mode_prefs.h"
12c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/profiles/profile_avatar_icon_util.h"
130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "chrome/browser/profiles/profile_info_cache.h"
147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h"
15010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/profiles/profile_metrics.h"
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/profiles/profile_window.h"
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/profiles/profiles_state.h"
181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/signin/local_auth.h"
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/signin/signin_header_helper.h"
21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/signin/signin_manager_factory.h"
22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/signin/signin_promo.h"
236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/signin/signin_ui_util.h"
2468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "chrome/browser/ui/browser_commands.h"
260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/ui/browser_dialogs.h"
27c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/ui/chrome_pages.h"
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/ui/singleton_tabs.h"
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/ui/user_manager.h"
30c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/ui/views/profiles/user_manager_view.h"
315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/ui/webui/signin/login_ui_service.h"
325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/common/pref_names.h"
344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/common/url_constants.h"
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/chromium_strings.h"
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/generated_resources.h"
37effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/signin/core/browser/mutable_profile_oauth2_token_service.h"
38effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/signin/core/browser/profile_oauth2_token_service.h"
39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/signin/core/browser/signin_error_controller.h"
40e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "components/signin/core/browser/signin_manager.h"
410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "components/signin/core/common/profile_management_switches.h"
423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "grit/theme_resources.h"
4368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h"
447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h"
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/canvas.h"
477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/gfx/image/image.h"
487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/gfx/image/image_skia.h"
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/gfx/path.h"
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/gfx/skia_util.h"
51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/text_elider.h"
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/native_theme/native_theme.h"
53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/views/controls/button/blue_button.h"
54effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/views/controls/button/image_button.h"
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/button/label_button.h"
56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/views/controls/button/menu_button.h"
577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/controls/label.h"
587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/controls/link.h"
597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/controls/separator.h"
60c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ui/views/controls/styled_label.h"
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/views/controls/textfield/textfield.h"
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/views/controls/webview/webview.h"
637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/layout/grid_layout.h"
647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/layout/layout_constants.h"
657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/widget/widget.h"
667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace {
68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
6968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Helpers --------------------------------------------------------------------
7068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const int kFixedMenuWidth = 250;
725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const int kButtonHeight = 32;
7303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)const int kFixedGaiaViewHeight = 440;
74effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochconst int kFixedGaiaViewWidth = 360;
75effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochconst int kFixedAccountRemovalViewWidth = 280;
761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst int kFixedSwitchUserViewWidth = 320;
775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuconst int kLargeImageSide = 88;
78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst int kVerticalSpacing = 16;
801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
81d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Creates a GridLayout with a single column. This ensures that all the child
82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// views added get auto-expanded to fill the full width of the bubble.
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) {
84d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  views::GridLayout* layout = new views::GridLayout(view);
85d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  view->SetLayoutManager(layout);
86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  views::ColumnSet* columns = layout->AddColumnSet(0);
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     views::GridLayout::FIXED, width, width);
90d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return layout;
91d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
92d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
93f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)views::Link* CreateLink(const base::string16& link_text,
94d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                        views::LinkListener* listener) {
95d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  views::Link* link_button = new views::Link(link_text);
96d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  link_button->SetHorizontalAlignment(gfx::ALIGN_LEFT);
97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  link_button->SetUnderline(false);
98d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  link_button->set_listener(listener);
99d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return link_button;
100d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
101d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liugfx::ImageSkia CreateSquarePlaceholderImage(int size) {
1035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  SkBitmap bitmap;
104116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bitmap.allocPixels(SkImageInfo::MakeA8(size, size));
1055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  bitmap.eraseARGB(0, 0, 0, 0);
1065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
1075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}
10868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
109cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool HasAuthError(Profile* profile) {
110cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  const SigninErrorController* error =
111cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      profiles::GetSigninErrorController(profile);
112cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return error && error->HasError();
113cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
114cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
115cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)std::string GetAuthErrorAccountId(Profile* profile) {
116cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  const SigninErrorController* error =
117cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      profiles::GetSigninErrorController(profile);
118cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (!error)
119cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return std::string();
120cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
121cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return error->error_account_id();
122cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
123cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
124cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)std::string GetAuthErrorUsername(Profile* profile) {
125cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  const SigninErrorController* error =
126cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      profiles::GetSigninErrorController(profile);
127cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (!error)
128cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return std::string();
129cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
130cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return error->error_username();
131cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
132cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
133f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// BackgroundColorHoverButton -------------------------------------------------
13468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// A custom button that allows for setting a background color when hovered over.
1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class BackgroundColorHoverButton : public views::LabelButton {
13768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public:
138f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  BackgroundColorHoverButton(views::ButtonListener* listener,
139f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                             const base::string16& text,
1405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                             const gfx::ImageSkia& icon)
1415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      : views::LabelButton(listener, text) {
1426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    SetImageLabelSpacing(views::kItemLabelSpacing);
1435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    SetBorder(views::Border::CreateEmptyBorder(
1445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew));
1455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    SetMinSize(gfx::Size(0,
1465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        kButtonHeight + views::kRelatedControlVerticalSpacing));
1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    SetImage(STATE_NORMAL, icon);
14803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    SetFocusable(true);
1495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
1505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual ~BackgroundColorHoverButton() {}
15268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
15368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) private:
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // views::LabelButton:
1555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
1565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    if ((state() == STATE_PRESSED) ||
15734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)        (state() == STATE_HOVERED)) {
1585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      canvas->DrawColor(GetNativeTheme()->GetSystemColor(
1595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          ui::NativeTheme::kColorId_ButtonHoverBackgroundColor));
1605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    }
1615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    LabelButton::OnPaint(canvas);
1625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
16368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
164f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton);
16568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)};
16668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
167f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// SizedContainer -------------------------------------------------
168f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
169f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// A simple container view that takes an explicit preferred size.
170f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class SizedContainer : public views::View {
171f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) public:
172f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  explicit SizedContainer(const gfx::Size& preferred_size)
173f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      : preferred_size_(preferred_size) {}
174f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
175f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual gfx::Size GetPreferredSize() const OVERRIDE {
176f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return preferred_size_;
177f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
178f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
179f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) private:
180f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Size preferred_size_;
181f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)};
182f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
183f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace
184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// RightAlignedIconLabelButton -------------------------------------------------
1865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// A custom LabelButton that has a centered text and right aligned icon.
1885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class RightAlignedIconLabelButton : public views::LabelButton {
1895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) public:
1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  RightAlignedIconLabelButton(views::ButtonListener* listener,
1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                              const base::string16& text)
1925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      : views::LabelButton(listener, text) {
1935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
1945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) protected:
1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void Layout() OVERRIDE {
1975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    // This layout trick keeps the text left-aligned and the icon right-aligned.
1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    SetHorizontalAlignment(gfx::ALIGN_RIGHT);
1995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    views::LabelButton::Layout();
2005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    label()->SetHorizontalAlignment(gfx::ALIGN_CENTER);
2015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
2025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci private:
2045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(RightAlignedIconLabelButton);
2055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)};
206f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
207f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// EditableProfilePhoto -------------------------------------------------
208f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
209f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// A custom Image control that shows a "change" button when moused over.
21003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class EditableProfilePhoto : public views::LabelButton {
21168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public:
212a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EditableProfilePhoto(views::ButtonListener* listener,
213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                       const gfx::Image& icon,
2145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                       bool is_editing_allowed,
2155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                       const gfx::Rect& bounds)
21603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      : views::LabelButton(listener, base::string16()),
21703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        photo_overlay_(NULL) {
2180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    gfx::Image image = profiles::GetSizedAvatarIcon(
219010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        icon, true, kLargeImageSide, kLargeImageSide);
22003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia());
22103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    SetBorder(views::Border::NullBorder());
2225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    SetBoundsRect(bounds);
223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
224cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // Calculate the circular mask that will be used to display the photo.
225f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    circular_mask_.addCircle(SkIntToScalar(bounds.width() / 2),
226f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             SkIntToScalar(bounds.height() / 2),
227cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                             SkIntToScalar(bounds.width() / 2));
228010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
22903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (!is_editing_allowed) {
23003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      SetEnabled(false);
231a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return;
23203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    }
233a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
234f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    set_notify_enter_exit_on_child(true);
235f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
23603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // Photo overlay that appears when hovering over the button.
23703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    photo_overlay_ = new views::ImageView();
238f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
239010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255);
24003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    photo_overlay_->set_background(
241f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        views::Background::CreateSolidBackground(kBackgroundColor));
24203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    photo_overlay_->SetImage(*ui::ResourceBundle::GetSharedInstance().
24303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_CAMERA));
244010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
24503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    photo_overlay_->SetSize(bounds.size());
24603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    photo_overlay_->SetVisible(false);
24703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    AddChildView(photo_overlay_);
248f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
249f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
250cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
251cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // Display the profile picture as a circle.
252cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    canvas->ClipPath(circular_mask_, true);
25303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    views::LabelButton::OnPaint(canvas);
254cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
255cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
256cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void PaintChildren(gfx::Canvas* canvas,
257f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             const views::CullSet& cull_set) OVERRIDE {
258cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // Display any children (the "change photo" overlay) as a circle.
259cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    canvas->ClipPath(circular_mask_, true);
260cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    View::PaintChildren(canvas, cull_set);
261cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
262cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
26368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) private:
26403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // views::CustomButton:
26503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void StateChanged() OVERRIDE {
26603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    bool show_overlay =
26703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        (state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus());
26803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (photo_overlay_)
26903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      photo_overlay_->SetVisible(show_overlay);
270f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
27168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
27203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void OnFocus() OVERRIDE {
27303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    views::LabelButton::OnFocus();
27403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (photo_overlay_)
27503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      photo_overlay_->SetVisible(true);
27603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  }
27703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
27803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void OnBlur() OVERRIDE {
27903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    views::LabelButton::OnBlur();
28003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // Don't hide the overlay if it's being shown as a result of a mouseover.
28103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (photo_overlay_ && state() != STATE_HOVERED)
28203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      photo_overlay_->SetVisible(false);
283f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
28468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
285cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::Path circular_mask_;
286cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
28703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Image that is shown when hovering over the image button. Can be NULL if
288a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // the photo isn't allowed to be edited (e.g. for guest profiles).
28903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  views::ImageView* photo_overlay_;
290f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
291f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto);
29268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)};
29368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
294f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// EditableProfileName -------------------------------------------------
295f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
296f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// A custom text control that turns into a textfield for editing when clicked.
2975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class EditableProfileName : public RightAlignedIconLabelButton,
298f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                            public views::ButtonListener {
299f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public:
300f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EditableProfileName(views::TextfieldController* controller,
301a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                      const base::string16& text,
302a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                      bool is_editing_allowed)
3035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      : RightAlignedIconLabelButton(this, text),
304a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        profile_name_textfield_(NULL) {
305f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const gfx::FontList& medium_font_list =
3075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        rb->GetFontList(ui::ResourceBundle::MediumFont);
3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    SetFontList(medium_font_list);
3095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    SetHorizontalAlignment(gfx::ALIGN_CENTER);
310a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
311cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    if (!is_editing_allowed) {
312cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0));
313a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return;
314cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    }
315f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
3165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // Show an "edit" pencil icon when hovering over. In the default state,
3175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // we need to create an empty placeholder of the correct size, so that
3185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // the text doesn't jump around when the hovered icon appears.
3195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    gfx::ImageSkia hover_image =
3205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_HOVER);
3215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    SetImage(STATE_NORMAL, CreateSquarePlaceholderImage(hover_image.width()));
3225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    SetImage(STATE_HOVERED, hover_image);
3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    SetImage(STATE_PRESSED,
3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)             *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_PRESSED));
3255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // To center the text, we need to offest it by the width of the icon we
3265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    // are adding and its padding. We need to also add a small top/bottom
3275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    // padding to account for the textfield's border.
3285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const int kIconTextLabelButtonSpacing = 5;
3295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    SetBorder(views::Border::CreateEmptyBorder(
3305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        2, hover_image.width() + kIconTextLabelButtonSpacing, 2, 0));
331f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
332f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // Textfield that overlaps the button.
333f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    profile_name_textfield_ = new views::Textfield();
3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    profile_name_textfield_->set_controller(controller);
3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    profile_name_textfield_->SetFontList(medium_font_list);
3365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
3375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
338f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    profile_name_textfield_->SetVisible(false);
339f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    AddChildView(profile_name_textfield_);
340f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
341f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
342f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  views::Textfield* profile_name_textfield() {
343f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return profile_name_textfield_;
344f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
345f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Hide the editable textfield to show the profile name button instead.
347f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void ShowReadOnlyView() {
348a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (profile_name_textfield_)
349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      profile_name_textfield_->SetVisible(false);
350f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
351f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
352f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private:
353f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // views::ButtonListener:
354f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void ButtonPressed(views::Button* sender,
355f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                            const ui::Event& event) OVERRIDE {
356a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (profile_name_textfield_) {
357a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      profile_name_textfield_->SetVisible(true);
3585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      profile_name_textfield_->SetText(GetText());
359a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      profile_name_textfield_->SelectAll(false);
360a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      profile_name_textfield_->RequestFocus();
361a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    }
362f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
363f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
3645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // views::LabelButton:
365f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE {
366f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // Override CustomButton's implementation, which presses the button when
367f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // you press space and clicks it when you release space, as the space can be
368f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // part of the new profile name typed in the textfield.
369f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return false;
370f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
371f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
372f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void Layout() OVERRIDE {
373a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (profile_name_textfield_)
374a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      profile_name_textfield_->SetBounds(0, 0, width(), height());
3755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    RightAlignedIconLabelButton::Layout();
376f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
377f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
37803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void OnFocus() OVERRIDE {
37903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    RightAlignedIconLabelButton::OnFocus();
38003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    SetState(STATE_HOVERED);
38103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  }
38203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
38303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void OnBlur() OVERRIDE {
38403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    RightAlignedIconLabelButton::OnBlur();
38503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    SetState(STATE_NORMAL);
38603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  }
38703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
3885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Textfield that is shown when editing the profile name. Can be NULL if
389a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // the profile name isn't allowed to be edited (e.g. for guest profiles).
390f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  views::Textfield* profile_name_textfield_;
391f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
392f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(EditableProfileName);
393f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)};
394d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
395effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// A title card with one back button right aligned and one label center aligned.
396effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass TitleCard : public views::View {
397effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public:
3985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  TitleCard(const base::string16& message, views::ButtonListener* listener,
3995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)            views::ImageButton** back_button) {
400effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    back_button_ = new views::ImageButton(listener);
401effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    back_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
402effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                                    views::ImageButton::ALIGN_MIDDLE);
403effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
404effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    back_button_->SetImage(views::ImageButton::STATE_NORMAL,
405effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                           rb->GetImageSkiaNamed(IDR_BACK));
406effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    back_button_->SetImage(views::ImageButton::STATE_HOVERED,
407effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                           rb->GetImageSkiaNamed(IDR_BACK_H));
408effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    back_button_->SetImage(views::ImageButton::STATE_PRESSED,
409effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                           rb->GetImageSkiaNamed(IDR_BACK_P));
410effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    back_button_->SetImage(views::ImageButton::STATE_DISABLED,
411effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                           rb->GetImageSkiaNamed(IDR_BACK_D));
41203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    back_button_->SetFocusable(true);
413effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    *back_button = back_button_;
414effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
4155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    title_label_ = new views::Label(message);
416effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    title_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
417effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    const gfx::FontList& medium_font_list =
418effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch        rb->GetFontList(ui::ResourceBundle::MediumFont);
419effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    title_label_->SetFontList(medium_font_list);
420effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
421effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    AddChildView(back_button_);
422effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    AddChildView(title_label_);
423effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  }
424effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
4251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Creates a new view that has the |title_card| with horizontal padding at the
4261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // top, an edge-to-edge separator below, and the specified |view| at the
4271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // bottom.
428010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  static views::View* AddPaddedTitleCard(views::View* view,
429010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                         TitleCard* title_card,
430010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                         int width) {
431010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    views::View* titled_view = new views::View();
432010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    views::GridLayout* layout = new views::GridLayout(titled_view);
433010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    titled_view->SetLayoutManager(layout);
434010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
435010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    // Column set 0 is a single column layout with horizontal padding at left
436010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    // and right, and column set 1 is a single column layout with no padding.
437010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    views::ColumnSet* columns = layout->AddColumnSet(0);
438010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    columns->AddPaddingColumn(1, views::kButtonHEdgeMarginNew);
439010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    int available_width = width - 2 * views::kButtonHEdgeMarginNew;
440010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
441010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        views::GridLayout::FIXED, available_width, available_width);
442010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    columns->AddPaddingColumn(1, views::kButtonHEdgeMarginNew);
443010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    layout->AddColumnSet(1)->AddColumn(views::GridLayout::FILL,
444010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        views::GridLayout::FILL, 0,views::GridLayout::FIXED, width, width);
445010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
4461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    layout->StartRowWithPadding(1, 0, 0, kVerticalSpacing);
447010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    layout->AddView(title_card);
4481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    layout->StartRowWithPadding(1, 1, 0, kVerticalSpacing);
449010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
450010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
451010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    layout->StartRow(1, 1);
452010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    layout->AddView(view);
453010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
454010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    return titled_view;
455010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
456010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
457effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch private:
4581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void Layout() OVERRIDE {
45903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    int back_button_width = back_button_->GetPreferredSize().width();
46003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    back_button_->SetBounds(0, 0, back_button_width, height());
46103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    int label_padding = back_button_width + views::kButtonHEdgeMarginNew;
46203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    int label_width = width() - 2 * label_padding;
46303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    DCHECK_GT(label_width, 0);
46403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    title_label_->SetBounds(label_padding, 0, label_width, height());
465effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  }
466effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
4671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual gfx::Size GetPreferredSize() const OVERRIDE {
468010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    int height = std::max(title_label_->GetPreferredSize().height(),
469010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        back_button_->GetPreferredSize().height());
470effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    return gfx::Size(width(), height);
471effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  }
472effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
473effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  views::ImageButton* back_button_;
474effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  views::Label* title_label_;
475effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
476effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  DISALLOW_COPY_AND_ASSIGN(TitleCard);
477effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch};
478d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
479d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// ProfileChooserView ---------------------------------------------------------
480d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
4817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static
4827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL;
483f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool ProfileChooserView::close_on_deactivate_for_testing_ = true;
4847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
4857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static
4867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void ProfileChooserView::ShowBubble(
487cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    profiles::BubbleViewMode view_mode,
4886e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    profiles::TutorialMode tutorial_mode,
4896d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    const signin::ManageAccountsParams& manage_accounts_params,
4907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    views::View* anchor_view,
4917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    views::BubbleBorder::Arrow arrow,
4927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    views::BubbleBorder::BubbleAlignment border_alignment,
4937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    Browser* browser) {
4946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  if (IsShowing()) {
4956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) {
4966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      profile_bubble_->tutorial_mode_ = tutorial_mode;
4976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      profile_bubble_->ShowView(view_mode, profile_bubble_->avatar_menu_.get());
4986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    }
499cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return;
5006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
501cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
502f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  profile_bubble_ = new ProfileChooserView(anchor_view, arrow, browser,
5036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      view_mode, tutorial_mode, manage_accounts_params.service_type);
5047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  views::BubbleDelegateView::CreateBubble(profile_bubble_);
505f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  profile_bubble_->set_close_on_deactivate(close_on_deactivate_for_testing_);
5067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  profile_bubble_->SetAlignment(border_alignment);
5077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  profile_bubble_->GetWidget()->Show();
5088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
5097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
5107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
5117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static
5127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)bool ProfileChooserView::IsShowing() {
5137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  return profile_bubble_ != NULL;
5147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
5157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
5167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static
5177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void ProfileChooserView::Hide() {
5187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (IsShowing())
5197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    profile_bubble_->GetWidget()->Close();
5207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
5217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
522d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)ProfileChooserView::ProfileChooserView(views::View* anchor_view,
523d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                       views::BubbleBorder::Arrow arrow,
524a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                       Browser* browser,
525cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                       profiles::BubbleViewMode view_mode,
5266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                       profiles::TutorialMode tutorial_mode,
527cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                       signin::GAIAServiceType service_type)
5287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    : BubbleDelegateView(anchor_view, arrow),
529f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      browser_(browser),
530a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      view_mode_(view_mode),
5316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      tutorial_mode_(tutorial_mode),
532cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      gaia_service_type_(service_type) {
533d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Reset the default margins inherited from the BubbleDelegateView.
5346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Add a small bottom inset so that the bubble's rounded corners show up.
5356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  set_margins(gfx::Insets(0, 0, 1, 0));
536116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  set_background(views::Background::CreateSolidBackground(
537116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      GetNativeTheme()->GetSystemColor(
538116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch          ui::NativeTheme::kColorId_DialogBackground)));
539f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ResetView();
54068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
54168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  avatar_menu_.reset(new AvatarMenu(
5427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      &g_browser_process->profile_manager()->GetProfileInfoCache(),
54368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      this,
54468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      browser_));
54568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  avatar_menu_->RebuildMenu();
546f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
547f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ProfileOAuth2TokenService* oauth2_token_service =
548f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile());
549f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (oauth2_token_service)
550f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    oauth2_token_service->AddObserver(this);
5517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
5527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
5537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ProfileChooserView::~ProfileChooserView() {
554f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ProfileOAuth2TokenService* oauth2_token_service =
555f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile());
556f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (oauth2_token_service)
557f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    oauth2_token_service->RemoveObserver(this);
5587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
5597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
560f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ProfileChooserView::ResetView() {
5615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  open_other_profile_indexes_map_.clear();
5625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  delete_account_button_map_.clear();
5635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  reauth_account_button_map_.clear();
564d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  manage_accounts_link_ = NULL;
565d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  signin_current_profile_link_ = NULL;
5665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  auth_error_email_button_ = NULL;
5675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  current_profile_photo_ = NULL;
5685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  current_profile_name_ = NULL;
569d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  users_button_ = NULL;
5705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  go_incognito_button_ = NULL;
571effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  lock_button_ = NULL;
5725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  add_account_link_ = NULL;
5735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  gaia_signin_cancel_button_ = NULL;
574010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  remove_account_button_ = NULL;
575effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  account_removal_cancel_button_ = NULL;
5765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  add_person_button_ = NULL;
5775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  disconnect_button_ = NULL;
5785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  switch_user_cancel_button_ = NULL;
5795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  tutorial_sync_settings_ok_button_ = NULL;
58003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  tutorial_close_button_ = NULL;
5815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  tutorial_sync_settings_link_ = NULL;
5825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  tutorial_see_whats_new_button_ = NULL;
5835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  tutorial_not_you_link_ = NULL;
58403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  tutorial_learn_more_link_ = NULL;
5857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
5867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
587d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ProfileChooserView::Init() {
588cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // If view mode is PROFILE_CHOOSER but there is an auth error, force
589cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // ACCOUNT_MANAGEMENT mode.
590cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER &&
5915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      HasAuthError(browser_->profile()) &&
5925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      switches::IsEnableAccountConsistency() &&
5935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      avatar_menu_->GetItemAt(avatar_menu_->GetActiveProfileIndex()).
5945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          signed_in) {
595cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    view_mode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT;
596cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
597cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
5981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // The arrow keys can be used to tab between items.
5991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE));
6001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE));
6011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
602a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  ShowView(view_mode_, avatar_menu_.get());
6037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
6047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
60568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void ProfileChooserView::OnAvatarMenuChanged(
60668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    AvatarMenu* avatar_menu) {
6071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ||
6081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) {
6091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // Refresh the view with the new menu. We can't just update the local copy
6101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // as this may have been triggered by a sign out action, in which case
6111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // the view is being destroyed.
6121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ShowView(view_mode_, avatar_menu);
6135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
6147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
6157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
616f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ProfileChooserView::OnRefreshTokenAvailable(
617f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const std::string& account_id) {
618cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ||
619cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT ||
620cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) {
6215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    // The account management UI is only available through the
6225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    // --enable-account-consistency flag.
6235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ShowView(switches::IsEnableAccountConsistency() ?
6245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT :
6255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get());
626f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
627f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
628f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
629f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ProfileChooserView::OnRefreshTokenRevoked(const std::string& account_id) {
630f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Refresh the account management view when an account is removed from the
631f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // profile.
632cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT)
633cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get());
634f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
635f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
636cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void ProfileChooserView::ShowView(profiles::BubbleViewMode view_to_display,
63768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                                  AvatarMenu* avatar_menu) {
638d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // The account management view should only be displayed if the active profile
639d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // is signed in.
640cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (view_to_display == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) {
6415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    DCHECK(switches::IsEnableAccountConsistency());
6426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    const AvatarMenu::Item& active_item = avatar_menu->GetItemAt(
6436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        avatar_menu->GetActiveProfileIndex());
644d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    DCHECK(active_item.signed_in);
6457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
6467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
647116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (browser_->profile()->IsSupervised() &&
648116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      (view_to_display == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT ||
649116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch       view_to_display == profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL)) {
650116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    LOG(WARNING) << "Supervised user attempted to add/remove account";
651116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return;
652116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
653116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
654f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ResetView();
6557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RemoveAllChildViews(true);
656f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  view_mode_ = view_to_display;
6577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
658a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::GridLayout* layout;
659a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::View* sub_view;
660a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  switch (view_mode_) {
661cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN:
662cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT:
663cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH:
664a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      layout = CreateSingleColumnLayout(this, kFixedGaiaViewWidth);
665cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      sub_view = CreateGaiaSigninView();
666a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      break;
667cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL:
668a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      layout = CreateSingleColumnLayout(this, kFixedAccountRemovalViewWidth);
669a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      sub_view = CreateAccountRemovalView();
670a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      break;
6715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    case profiles::BUBBLE_VIEW_MODE_SWITCH_USER:
6725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth);
6736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      sub_view = CreateSwitchUserView();
6746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      ProfileMetrics::LogProfileNewAvatarMenuNotYou(
6756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW);
6765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      break;
677a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    default:
678a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      layout = CreateSingleColumnLayout(this, kFixedMenuWidth);
6796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      sub_view = CreateProfileChooserView(avatar_menu);
680effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  }
68103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Clears tutorial mode for all non-profile-chooser views.
68203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER)
68303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
68403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
6857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  layout->StartRow(1, 0);
686a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  layout->AddView(sub_view);
6877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  Layout();
6888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (GetBubbleFrameView())
6898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    SizeToContents();
6907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
6917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
692d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ProfileChooserView::WindowClosing() {
693d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DCHECK_EQ(profile_bubble_, this);
694d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  profile_bubble_ = NULL;
6955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
6965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (tutorial_mode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) {
6975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    LoginUIServiceFactory::GetForProfile(browser_->profile())->
6985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        SyncConfirmationUIClosed(false /* configure_sync_first */);
6995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
700d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
7017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool ProfileChooserView::AcceleratorPressed(
7031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    const ui::Accelerator& accelerator) {
7041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (accelerator.key_code() != ui::VKEY_DOWN &&
7051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      accelerator.key_code() != ui::VKEY_UP)
7061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return BubbleDelegateView::AcceleratorPressed(accelerator);
7071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Move the focus up or down.
7081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  GetFocusManager()->AdvanceFocus(accelerator.key_code() != ui::VKEY_DOWN);
7091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return true;
7101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
7111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
712d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ProfileChooserView::ButtonPressed(views::Button* sender,
713d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                       const ui::Event& event) {
714effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  if (sender == users_button_) {
7151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // If this is a guest session, close all the guest browser windows.
7166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    if (browser_->profile()->IsGuestSession()) {
7175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      profiles::CloseGuestProfileWindows();
7186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    } else {
7191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      UserManager::Show(base::FilePath(),
7201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                        profiles::USER_MANAGER_NO_TUTORIAL,
7211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                        profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
7226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    }
7236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER);
7245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  } else if (sender == go_incognito_button_) {
7255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    DCHECK(ShouldShowGoIncognito());
7265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    chrome::NewIncognitoWindow(browser_);
727effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  } else if (sender == lock_button_) {
728effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    profiles::LockProfile(browser_->profile());
729cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_LOCK);
7305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  } else if (sender == auth_error_email_button_) {
7315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH, avatar_menu_.get());
7325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  } else if (sender == tutorial_sync_settings_ok_button_) {
7335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    LoginUIServiceFactory::GetForProfile(browser_->profile())->
7345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        SyncConfirmationUIClosed(false /* configure_sync_first */);
73503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    DismissTutorial();
7366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    ProfileMetrics::LogProfileNewAvatarMenuSignin(
7376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_OK);
73803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  } else if (sender == tutorial_close_button_) {
73903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    DCHECK(tutorial_mode_ != profiles::TUTORIAL_MODE_NONE &&
74003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)           tutorial_mode_ != profiles::TUTORIAL_MODE_CONFIRM_SIGNIN);
74103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    DismissTutorial();
7425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  } else if (sender == tutorial_see_whats_new_button_) {
7436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
7446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_WHATS_NEW);
7451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    UserManager::Show(base::FilePath(),
7461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                      profiles::USER_MANAGER_TUTORIAL_OVERVIEW,
7471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                      profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
748010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  } else if (sender == remove_account_button_) {
749effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    RemoveAccount();
750effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  } else if (sender == account_removal_cancel_button_) {
751effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    account_id_to_remove_.clear();
752cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get());
753effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  } else if (sender == gaia_signin_cancel_button_) {
7545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    // The account management view is only available with the
7555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    // --enable-account-consistency flag.
7561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    bool account_management_available =
7571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        SigninManagerFactory::GetForProfile(browser_->profile())->
7581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            IsAuthenticated() &&
7595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        switches::IsEnableAccountConsistency();
7605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ShowView(account_management_available ?
7615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT :
7625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get());
76303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  } else if (sender == current_profile_photo_) {
764effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex());
765cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE);
7665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  } else if (sender == signin_current_profile_link_) {
7675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN, avatar_menu_.get());
7685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  } else if (sender == add_person_button_) {
7696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    ProfileMetrics::LogProfileNewAvatarMenuNotYou(
7706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON);
7711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    UserManager::Show(base::FilePath(),
7721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                      profiles::USER_MANAGER_NO_TUTORIAL,
7731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                      profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
7745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  } else if (sender == disconnect_button_) {
7756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    ProfileMetrics::LogProfileNewAvatarMenuNotYou(
7766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT);
7775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    chrome::ShowSettings(browser_);
7785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  } else if (sender == switch_user_cancel_button_) {
7795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get());
7806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    ProfileMetrics::LogProfileNewAvatarMenuNotYou(
7816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_BACK);
782d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  } else {
7835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // Either one of the "other profiles", or one of the profile accounts
7845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // buttons was pressed.
7855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    ButtonIndexes::const_iterator profile_match =
786d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        open_other_profile_indexes_map_.find(sender);
7875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    if (profile_match != open_other_profile_indexes_map_.end()) {
7885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      avatar_menu_->SwitchToProfile(
7895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu          profile_match->second,
7905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu          ui::DispositionFromEventFlags(event.flags()) == NEW_WINDOW,
7915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu          ProfileMetrics::SWITCH_PROFILE_ICON);
7925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    } else {
7935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // This was a profile accounts button.
7945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      AccountButtonIndexes::const_iterator account_match =
795cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)          delete_account_button_map_.find(sender);
796cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      if (account_match != delete_account_button_map_.end()) {
797cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        account_id_to_remove_ = account_match->second;
798cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL,
799cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)            avatar_menu_.get());
800cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      } else {
801cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        account_match = reauth_account_button_map_.find(sender);
802cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        DCHECK(account_match != reauth_account_button_map_.end());
803cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH, avatar_menu_.get());
804cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      }
8055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    }
806d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
8077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
8087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
809effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid ProfileChooserView::RemoveAccount() {
810effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  DCHECK(!account_id_to_remove_.empty());
8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  MutableProfileOAuth2TokenService* oauth2_token_service =
8125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile(
813effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      browser_->profile());
814cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (oauth2_token_service) {
815effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    oauth2_token_service->RevokeCredentials(account_id_to_remove_);
816cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT);
817cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
818effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  account_id_to_remove_.clear();
819effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
820cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get());
821f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
822f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
823d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) {
824d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (sender == manage_accounts_link_) {
8255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // This link can either mean show/hide the account management view,
8265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // depending on which view it is displayed. ShowView() will DCHECK if
8275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // the account management view is displayed for non signed-in users.
8285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    ShowView(
829cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ?
830cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)            profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER :
831cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)            profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT,
8325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        avatar_menu_.get());
8335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  } else if (sender == add_account_link_) {
834cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get());
835cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_ADD_ACCT);
8365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  } else if (sender == tutorial_sync_settings_link_) {
8375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    LoginUIServiceFactory::GetForProfile(browser_->profile())->
8385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        SyncConfirmationUIClosed(true /* configure_sync_first */);
8395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
8406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    ProfileMetrics::LogProfileNewAvatarMenuSignin(
8416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_SETTINGS);
8421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  } else if (sender == tutorial_not_you_link_) {
8436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
8446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_NOT_YOU);
8455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ShowView(profiles::BUBBLE_VIEW_MODE_SWITCH_USER, avatar_menu_.get());
84603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  } else {
84703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    DCHECK(sender == tutorial_learn_more_link_);
84803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    signin_ui_util::ShowSigninErrorLearnMorePage(browser_->profile());
849f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
850f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
851f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
852c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid ProfileChooserView::StyledLabelLinkClicked(
853c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    const gfx::Range& range, int event_flags) {
854c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  chrome::ShowSettings(browser_);
855c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}
856c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
857f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender,
858f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                        const ui::KeyEvent& key_event) {
859f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  views::Textfield* name_textfield =
860f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      current_profile_name_->profile_name_textfield();
861f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DCHECK(sender == name_textfield);
862f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
863f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (key_event.key_code() == ui::VKEY_RETURN ||
864f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      key_event.key_code() == ui::VKEY_TAB) {
865f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // Pressing Tab/Enter commits the new profile name, unless it's empty.
866f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    base::string16 new_profile_name = name_textfield->text();
86703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name);
868f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (new_profile_name.empty())
869f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      return true;
870f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
871f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const AvatarMenu::Item& active_item = avatar_menu_->GetItemAt(
87268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)        avatar_menu_->GetActiveProfileIndex());
873f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    Profile* profile = g_browser_process->profile_manager()->GetProfile(
874f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        active_item.profile_path);
875f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DCHECK(profile);
876f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
877f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    if (profile->IsSupervised())
878f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      return true;
879f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
880f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    profiles::UpdateProfileName(profile, new_profile_name);
881cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME);
882f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    current_profile_name_->ShowReadOnlyView();
883f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return true;
884d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
885f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return false;
886d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
8877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
888a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochviews::View* ProfileChooserView::CreateProfileChooserView(
8896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    AvatarMenu* avatar_menu) {
890a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::View* view = new views::View();
891a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
892a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Separate items into active and alternatives.
893a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  Indexes other_profiles;
894a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::View* tutorial_view = NULL;
895a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::View* current_profile_view = NULL;
896a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::View* current_profile_accounts = NULL;
897a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::View* option_buttons_view = NULL;
898a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
899a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
900a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    if (item.active) {
9015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      option_buttons_view = CreateOptionsView(
9025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          switches::IsNewProfileManagement() && item.signed_in);
9035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      current_profile_view = CreateCurrentProfileView(item, false);
904cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) {
9056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        switch (tutorial_mode_) {
9065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          case profiles::TUTORIAL_MODE_NONE:
9075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          case profiles::TUTORIAL_MODE_WELCOME_UPGRADE:
9085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)            tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded(
9096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE,
9105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                item);
9115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)            break;
9125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN:
9135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)            tutorial_view = CreateSigninConfirmationView();
9145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)            break;
9155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          case profiles::TUTORIAL_MODE_SHOW_ERROR:
91603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)            tutorial_view = CreateSigninErrorView();
91703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)            break;
9185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        }
919a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      } else {
920a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        current_profile_accounts = CreateCurrentProfileAccountsView(item);
921a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      }
922a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    } else {
923a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      other_profiles.push_back(i);
924a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    }
925a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
926a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
927a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (tutorial_view) {
9285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    // TODO(mlerman): update UMA stats for the new tutorial.
929a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    layout->StartRow(1, 0);
930a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    layout->AddView(tutorial_view);
9316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  } else {
9326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
933a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
934a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
935a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!current_profile_view) {
936a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    // Guest windows don't have an active profile.
937a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    current_profile_view = CreateGuestProfileView();
938a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    option_buttons_view = CreateOptionsView(false);
939a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
940a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
941a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  layout->StartRow(1, 0);
942a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  layout->AddView(current_profile_view);
943a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
944f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) {
945f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    DCHECK(current_profile_accounts);
946f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    layout->StartRow(0, 0);
947f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
948f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    layout->StartRow(1, 0);
949f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    layout->AddView(current_profile_accounts);
950f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
951f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
952f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (browser_->profile()->IsSupervised()) {
953cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    layout->StartRow(0, 0);
954cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
955cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    layout->StartRow(1, 0);
956cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    layout->AddView(CreateSupervisedUserDisclaimerView());
957cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
958cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
959cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) {
960a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    layout->StartRow(1, 0);
961a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    if (switches::IsFastUserSwitching())
962a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      layout->AddView(CreateOtherProfilesView(other_profiles));
963a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
964a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
965a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  layout->StartRow(0, 0);
966a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
967a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
968010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  if (option_buttons_view) {
9695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    layout->StartRow(0, 0);
9705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    layout->AddView(option_buttons_view);
9715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  }
972a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
973a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return view;
974a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
975a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
97603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void ProfileChooserView::DismissTutorial() {
97703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Never shows the upgrade tutorial again if manually closed.
97803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) {
97903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    browser_->profile()->GetPrefs()->SetInteger(
98003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        prefs::kProfileAvatarTutorialShown,
98103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1);
98203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  }
98303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
98403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
98503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get());
98603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
98703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
988a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochviews::View* ProfileChooserView::CreateTutorialView(
989cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    profiles::TutorialMode tutorial_mode,
990a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    const base::string16& title_text,
991a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    const base::string16& content_text,
992a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    const base::string16& link_text,
993a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    const base::string16& button_text,
99403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    bool stack_button,
995a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    views::Link** link,
99603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    views::LabelButton** button,
99703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    views::ImageButton** close_button) {
9985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  tutorial_mode_ = tutorial_mode;
9995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1000a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  views::View* view = new views::View();
1001c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  view->set_background(views::Background::CreateSolidBackground(
1002c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      profiles::kAvatarTutorialBackgroundColor));
1003a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  views::GridLayout* layout = CreateSingleColumnLayout(view,
1004a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew);
100503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Creates a second column set for buttons and links.
100603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  views::ColumnSet* button_columns = layout->AddColumnSet(1);
100703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  button_columns->AddColumn(views::GridLayout::LEADING,
100803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
100903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  button_columns->AddPaddingColumn(
101003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      1, views::kUnrelatedControlHorizontalSpacing);
101103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  button_columns->AddColumn(views::GridLayout::TRAILING,
101203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
1013a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  layout->SetInsets(views::kButtonVEdgeMarginNew,
1014a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                    views::kButtonHEdgeMarginNew,
1015a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                    views::kButtonVEdgeMarginNew,
1016a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                    views::kButtonHEdgeMarginNew);
1017a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
101803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Adds title and close button if needed.
1019a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::Label* title_label = new views::Label(title_text);
10206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  title_label->SetMultiLine(true);
1021a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1022c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  title_label->SetAutoColorReadabilityEnabled(false);
1023c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  title_label->SetEnabledColor(SK_ColorWHITE);
1024010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
1025c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      ui::ResourceBundle::MediumFont));
102603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
102703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (close_button) {
102803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    layout->StartRow(1, 1);
102903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    layout->AddView(title_label);
103003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    *close_button = new views::ImageButton(this);
103103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    (*close_button)->SetImageAlignment(views::ImageButton::ALIGN_RIGHT,
103203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                       views::ImageButton::ALIGN_MIDDLE);
103303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
103403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    (*close_button)->SetImage(views::ImageButton::STATE_NORMAL,
103503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                              rb->GetImageSkiaNamed(IDR_CLOSE_1));
103603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    (*close_button)->SetImage(views::ImageButton::STATE_HOVERED,
103703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                              rb->GetImageSkiaNamed(IDR_CLOSE_1_H));
103803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    (*close_button)->SetImage(views::ImageButton::STATE_PRESSED,
103903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                              rb->GetImageSkiaNamed(IDR_CLOSE_1_P));
104003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    layout->AddView(*close_button);
104103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  } else {
104203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    layout->StartRow(1, 0);
104303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    layout->AddView(title_label);
104403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  }
1045a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1046c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Adds body content.
1047a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  views::Label* content_label = new views::Label(content_text);
1048c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  content_label->SetMultiLine(true);
1049c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1050c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  content_label->SetAutoColorReadabilityEnabled(false);
1051c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  content_label->SetEnabledColor(profiles::kAvatarTutorialContentTextColor);
1052a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing);
1053c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  layout->AddView(content_label);
1054a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1055c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Adds links and buttons.
105603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  bool has_button = !button_text.empty();
105703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (has_button) {
105803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    *button = new views::LabelButton(this, button_text);
105903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    (*button)->SetHorizontalAlignment(gfx::ALIGN_CENTER);
106003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    (*button)->SetStyle(views::Button::STYLE_BUTTON);
106103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  }
1062a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
106303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  bool has_link = !link_text.empty();
106403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (has_link) {
10656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    *link = CreateLink(link_text, this);
10666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    (*link)->SetHorizontalAlignment(gfx::ALIGN_LEFT);
10676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    (*link)->SetAutoColorReadabilityEnabled(false);
10686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    (*link)->SetEnabledColor(SK_ColorWHITE);
10696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
1070a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
107103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (stack_button) {
107203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    DCHECK(has_button);
107303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    layout->StartRowWithPadding(
107403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        1, 0, 0, views::kUnrelatedControlVerticalSpacing);
107503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    layout->AddView(*button);
107603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (has_link) {
107703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      layout->StartRowWithPadding(
107803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)          1, 0, 0, views::kRelatedControlVerticalSpacing);
107903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      (*link)->SetHorizontalAlignment(gfx::ALIGN_CENTER);
108003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      layout->AddView(*link);
108103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    }
108203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  } else {
108303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    DCHECK(has_link || has_button);
108403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    layout->StartRowWithPadding(
108503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        1, 1, 0, views::kUnrelatedControlVerticalSpacing);
108603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (has_link)
108703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      layout->AddView(*link);
108803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    else
108903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      layout->SkipColumns(1);
109003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (has_button)
109103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      layout->AddView(*button);
109203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    else
109303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      layout->SkipColumns(1);
109403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  }
1095c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
10965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return view;
1097a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1098a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1099d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)views::View* ProfileChooserView::CreateCurrentProfileView(
110068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    const AvatarMenu::Item& avatar_item,
1101d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    bool is_guest) {
1102d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  views::View* view = new views::View();
11035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew;
11045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  views::GridLayout* layout = CreateSingleColumnLayout(view, column_width);
110568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  layout->SetInsets(views::kButtonVEdgeMarginNew,
1106d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                    views::kButtonHEdgeMarginNew,
1107010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                    views::kUnrelatedControlVerticalSpacing,
110868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                    views::kButtonHEdgeMarginNew);
11097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
11105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Profile icon, centered.
1111f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  int x_offset = (column_width - kLargeImageSide) / 2;
11125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  current_profile_photo_ = new EditableProfilePhoto(
11135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      this, avatar_item.icon, !is_guest,
11145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      gfx::Rect(x_offset, 0, kLargeImageSide, kLargeImageSide));
1115f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SizedContainer* profile_icon_container =
1116f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      new SizedContainer(gfx::Size(column_width, kLargeImageSide));
1117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  profile_icon_container->AddChildView(current_profile_photo_);
1118d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
11195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (browser_->profile()->IsSupervised()) {
112146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    views::ImageView* supervised_icon = new views::ImageView();
112246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    supervised_icon->SetImage(
112346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_SUPERVISED));
112446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    gfx::Size preferred_size = supervised_icon->GetPreferredSize();
112546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    gfx::Rect parent_bounds = current_profile_photo_->bounds();
112646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    supervised_icon->SetBounds(
112746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        parent_bounds.right() - preferred_size.width(),
112846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        parent_bounds.bottom() - preferred_size.height(),
112946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        preferred_size.width(),
113046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        preferred_size.height());
1131f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    profile_icon_container->AddChildView(supervised_icon);
113246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
113346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
11345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  layout->StartRow(1, 0);
1135f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  layout->AddView(profile_icon_container);
11367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
11375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Profile name, centered.
1138f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool editing_allowed = !is_guest && !browser_->profile()->IsSupervised();
1139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  current_profile_name_ = new EditableProfileName(
1140116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      this,
1141116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()),
1142116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      editing_allowed);
11435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  layout->StartRowWithPadding(1, 0, 0,
11445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                              views::kRelatedControlSmallVerticalSpacing);
1145d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  layout->StartRow(1, 0);
1146f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  layout->AddView(current_profile_name_);
11473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
11485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  if (is_guest)
11495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    return view;
11503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
11515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // The available links depend on the type of profile that is active.
11525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  if (avatar_item.signed_in) {
1153cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    layout->StartRow(1, 0);
11545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    if (switches::IsEnableAccountConsistency()) {
11555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      base::string16 link_title = l10n_util::GetStringUTF16(
1156cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)          view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ?
11575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu              IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON :
11585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu              IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
11595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      manage_accounts_link_ = CreateLink(link_title, this);
11605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
11615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      layout->AddView(manage_accounts_link_);
11625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    } else {
11636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      // Add a small padding between the email button and the profile name.
11646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      layout->StartRowWithPadding(1, 0, 0, 2);
11655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      // Badge the email address if there's an authentication error.
11665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      if (HasAuthError(browser_->profile())) {
11675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        const gfx::ImageSkia warning_image = *rb->GetImageNamed(
11685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)            IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia();
11695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        auth_error_email_button_ =
11705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)            new RightAlignedIconLabelButton(this, avatar_item.sync_state);
11715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        auth_error_email_button_->SetElideBehavior(gfx::ELIDE_EMAIL);
11725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        auth_error_email_button_->SetBorder(views::Border::NullBorder());
11735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        auth_error_email_button_->SetImage(
11745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)            views::LabelButton::STATE_NORMAL, warning_image);
1175