blob: 85abe85272a576758d8bb75069d94a6d8b877cb1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_
#define CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/string16.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/image/image.h"
class AvatarMenuModelObserver;
class Browser;
class ProfileInfoInterface;
// This class is the model for the menu-like interface that appears when the
// avatar icon is clicked in the browser window frame. This class will notify
// its observer when the backend data changes, and the controller/view for this
// model should forward actions back to it in response to user events.
class AvatarMenuModel : public content::NotificationObserver {
public:
// Represents an item in the menu.
struct Item {
Item(size_t model_index, const gfx::Image& icon);
~Item();
// The icon to be displayed next to the item.
gfx::Image icon;
// Whether or not the current browser is using this profile.
bool active;
// The name of this profile.
string16 name;
// A string representing the sync state of the profile.
string16 sync_state;
// The index in the |profile_cache| that this Item represents.
size_t model_index;
};
// Constructor. No parameters can be NULL in practice. |browser| can be NULL
// and a new one will be created if an action requires it.
AvatarMenuModel(ProfileInfoInterface* profile_cache,
AvatarMenuModelObserver* observer,
Browser* browser);
virtual ~AvatarMenuModel();
// Actions performed by the view that the controller forwards back to the
// model:
// Opens a Browser with the specified profile in response to the user
// selecting an item.
void SwitchToProfile(size_t index);
// Opens the profile settings in response to clicking the edit button next to
// an item.
void EditProfile(size_t index);
// Creates a new profile.
void AddNewProfile();
// Gets the number of profiles.
size_t GetNumberOfItems();
// Returns the index of the active profile.
size_t GetActiveProfileIndex();
// Gets the an Item at a specified index.
const Item& GetItemAt(size_t index);
// This model is also used for the always-present Mac system menubar. As the
// last active browser changes, the model needs to update accordingly.
void set_browser(Browser* browser) { browser_ = browser; }
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// True if avatar menu should be displayed.
static bool ShouldShowAvatarMenu();
private:
// Rebuilds the menu from the cache and notifies the |observer_|.
void RebuildMenu();
// Clears the list of items, deleting each.
void ClearMenu();
// The cache that provides the profile information. Weak.
ProfileInfoInterface* profile_info_;
// The observer of this model, which is notified of changes. Weak.
AvatarMenuModelObserver* observer_;
// Browser in which this avatar menu resides. Weak.
Browser* browser_;
// List of built "menu items."
std::vector<Item*> items_;
// Listens for notifications from the ProfileInfoCache.
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(AvatarMenuModel);
};
#endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_
|