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"
131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/scoped_observer.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile_metrics.h"
164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h"
19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/public/browser/web_contents.h"
20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/public/browser/web_contents_observer.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(ENABLE_MANAGED_USERS)
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/supervised_user/supervised_user_service_observer.h"
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass AvatarMenuActions;
2868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)class AvatarMenuObserver;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Browser;
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class Profile;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ProfileInfoInterface;
3268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)class ProfileList;
331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass SupervisedUserService;
3468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
3568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// This class represents the menu-like interface used to select profiles,
3668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// such as the bubble that appears when the avatar icon is clicked in the
3768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// browser window frame. This class will notify its observer when the backend
3868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// data changes, and the view for this model should forward actions
3968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// back to it in response to user events.
401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass AvatarMenu :
411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(ENABLE_MANAGED_USERS)
421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    public SupervisedUserServiceObserver,
431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    public content::NotificationObserver {
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Represents an item in the menu.
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct Item {
4868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    Item(size_t menu_index, size_t profile_index, const gfx::Image& icon);
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ~Item();
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The icon to be displayed next to the item.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::Image icon;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Whether or not the current browser is using this profile.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool active;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The name of this profile.
58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    base::string16 name;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // A string representing the sync state of the profile.
61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    base::string16 sync_state;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Whether or not the current profile is signed in. If true, |sync_state| is
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // expected to be the email of the signed in user.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool signed_in;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // Whether or not the current profile requires sign-in before use.
68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    bool signin_required;
69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
70f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    // Whether or not the current profile is a supervised user
71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // (see SupervisedUserService).
72f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    bool supervised;
7368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
7468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // The index in the menu of this profile, used by views to refer to
7568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // profiles.
7668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    size_t menu_index;
7768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
7868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // The index in the |profile_cache| for this profile.
7968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    size_t profile_index;
800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // The path of this profile.
820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    base::FilePath profile_path;
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Constructor. |observer| can be NULL. |browser| can be NULL and a new one
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be created if an action requires it.
8768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  AvatarMenu(ProfileInfoInterface* profile_cache,
8868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)             AvatarMenuObserver* observer,
8968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)             Browser* browser);
9068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  virtual ~AvatarMenu();
9168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
9268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // True if avatar menu should be displayed.
9368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  static bool ShouldShowAvatarMenu();
9468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
9568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Sets |image| to the image corresponding to the given profile, and
9668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // sets |is_rectangle| to true unless |image| is a built-in profile avatar.
9768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  static void GetImageForMenuButton(Profile* profile,
9868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                                    gfx::Image* image,
9968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                                    bool* is_rectangle);
10068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
10168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Compare items by name.
10268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  static bool CompareItems(const Item* item1, const Item* item2);
10368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Opens a Browser with the specified profile in response to the user
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // selecting an item. If |always_create| is true then a new window is created
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // even if a window for that profile already exists.
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void SwitchToProfile(size_t index,
1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       bool always_create,
1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       ProfileMetrics::ProfileOpen metric);
11068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
11168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Creates a new profile.
11268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  void AddNewProfile(ProfileMetrics::ProfileAdd type);
11368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Opens the profile settings in response to clicking the edit button next to
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // an item.
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void EditProfile(size_t index);
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Rebuilds the menu from the cache.
11968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  void RebuildMenu();
120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets the number of profiles.
12268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  size_t GetNumberOfItems() const;
12368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
12468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Gets the Item at the specified index.
12568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const Item& GetItemAt(size_t index) const;
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the index of the active profile.
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size_t GetActiveProfileIndex();
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
130f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns information about a supervised user which will be displayed in the
131f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // avatar menu. If the profile does not belong to a supervised user, an empty
132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // string will be returned.
133f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  base::string16 GetSupervisedUserInformation() const;
134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
135f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns the icon for the supervised user which will be displayed in the
136868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // avatar menu.
137f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const gfx::Image& GetSupervisedUserIcon() const;
138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
13968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // This menu is also used for the always-present Mac system menubar. If the
14068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // last active browser changes, the menu will need to reference that browser.
14168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  void ActiveBrowserChanged(Browser* browser);
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Returns true if the add profile link should be shown.
14468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  bool ShouldShowAddNewProfileLink() const;
14568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
14668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Returns true if the edit profile link should be shown.
14768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  bool ShouldShowEditProfileLink() const;
14868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
14968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // content::NotificationObserver:
15068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  virtual void Observe(int type,
15168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                       const content::NotificationSource& source,
15268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
153c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(ENABLE_MANAGED_USERS)
1561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // SupervisedUserServiceObserver:
1571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnCustodianInfoChanged() OVERRIDE;
1581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
1591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
16068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // The model that provides the list of menu items.
16168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  scoped_ptr<ProfileList> profile_list_;
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // The controller for avatar menu actions.
16468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  scoped_ptr<AvatarMenuActions> menu_actions_;
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(ENABLE_MANAGED_USERS)
1671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Observes changes to a supervised user's custodian info.
1681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
1691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      supervised_user_observer_;
1701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
1711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The cache that provides the profile information. Weak.
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ProfileInfoInterface* profile_info_;
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The observer of this model, which is notified of changes. Weak.
17668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  AvatarMenuObserver* observer_;
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Browser in which this avatar menu resides. Weak.
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Browser* browser_;
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Listens for notifications from the ProfileInfoCache.
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationRegistrar registrar_;
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
18468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AvatarMenu);
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
18768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#endif  // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_
188