15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#ifndef CHROME_BROWSER_PROFILES_AVATAR_MENU_H_
668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#define CHROME_BROWSER_PROFILES_AVATAR_MENU_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile_metrics.h"
154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h"
18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/public/browser/web_contents.h"
19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/public/browser/web_contents_observer.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)class AvatarMenuObserver;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Browser;
24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class Profile;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ProfileInfoInterface;
2668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)class ProfileList;
2768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)class AvatarMenuActions;
2868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
2968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// This class represents the menu-like interface used to select profiles,
3068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// such as the bubble that appears when the avatar icon is clicked in the
3168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// browser window frame. This class will notify its observer when the backend
3268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// data changes, and the view for this model should forward actions
3368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// back to it in response to user events.
3468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)class AvatarMenu : public content::NotificationObserver {
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Represents an item in the menu.
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct Item {
3868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    Item(size_t menu_index, size_t profile_index, const gfx::Image& icon);
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ~Item();
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The icon to be displayed next to the item.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::Image icon;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Whether or not the current browser is using this profile.
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool active;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The name of this profile.
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    base::string16 name;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // A string representing the sync state of the profile.
51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    base::string16 sync_state;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Whether or not the current profile is signed in. If true, |sync_state| is
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // expected to be the email of the signed in user.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool signed_in;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // Whether or not the current profile requires sign-in before use.
58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    bool signin_required;
59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
60f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    // Whether or not the current profile is a supervised user
6168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // (see ManagedUserService).
62f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    bool supervised;
6368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
6468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // The index in the menu of this profile, used by views to refer to
6568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // profiles.
6668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    size_t menu_index;
6768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
6868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // The index in the |profile_cache| for this profile.
6968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    size_t profile_index;
700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // The path of this profile.
720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    base::FilePath profile_path;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Constructor. |observer| can be NULL. |browser| can be NULL and a new one
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be created if an action requires it.
7768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  AvatarMenu(ProfileInfoInterface* profile_cache,
7868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)             AvatarMenuObserver* observer,
7968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)             Browser* browser);
8068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  virtual ~AvatarMenu();
8168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
8268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // True if avatar menu should be displayed.
8368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  static bool ShouldShowAvatarMenu();
8468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
8568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Sets |image| to the image corresponding to the given profile, and
8668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // sets |is_rectangle| to true unless |image| is a built-in profile avatar.
8768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  static void GetImageForMenuButton(Profile* profile,
8868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                                    gfx::Image* image,
8968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                                    bool* is_rectangle);
9068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
9168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Compare items by name.
9268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  static bool CompareItems(const Item* item1, const Item* item2);
9368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Opens a Browser with the specified profile in response to the user
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // selecting an item. If |always_create| is true then a new window is created
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // even if a window for that profile already exists.
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void SwitchToProfile(size_t index,
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       bool always_create,
995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       ProfileMetrics::ProfileOpen metric);
10068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
10168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Creates a new profile.
10268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  void AddNewProfile(ProfileMetrics::ProfileAdd type);
10368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Opens the profile settings in response to clicking the edit button next to
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // an item.
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void EditProfile(size_t index);
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Rebuilds the menu from the cache.
10968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  void RebuildMenu();
110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets the number of profiles.
11268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  size_t GetNumberOfItems() const;
11368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
11468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Gets the Item at the specified index.
11568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const Item& GetItemAt(size_t index) const;
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the index of the active profile.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size_t GetActiveProfileIndex();
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns information about a supervised user which will be displayed in the
121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // avatar menu. If the profile does not belong to a supervised user, an empty
122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // string will be returned.
123f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  base::string16 GetSupervisedUserInformation() const;
124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
125f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns the icon for the supervised user which will be displayed in the
126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // avatar menu.
127f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const gfx::Image& GetSupervisedUserIcon() const;
128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
12968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // This menu is also used for the always-present Mac system menubar. If the
13068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // last active browser changes, the menu will need to reference that browser.
13168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  void ActiveBrowserChanged(Browser* browser);
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Returns true if the add profile link should be shown.
13468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  bool ShouldShowAddNewProfileLink() const;
13568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
13668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Returns true if the edit profile link should be shown.
13768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  bool ShouldShowEditProfileLink() const;
13868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
13968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // content::NotificationObserver:
14068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  virtual void Observe(int type,
14168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                       const content::NotificationSource& source,
14268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
14568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // The model that provides the list of menu items.
14668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  scoped_ptr<ProfileList> profile_list_;
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // The controller for avatar menu actions.
14968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  scoped_ptr<AvatarMenuActions> menu_actions_;
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The cache that provides the profile information. Weak.
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ProfileInfoInterface* profile_info_;
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The observer of this model, which is notified of changes. Weak.
15568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  AvatarMenuObserver* observer_;
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Browser in which this avatar menu resides. Weak.
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Browser* browser_;
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Listens for notifications from the ProfileInfoCache.
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationRegistrar registrar_;
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AvatarMenu);
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#endif  // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_
167