blob: 378cc6a579640b8f72485b8ded700f71b2242265 (
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
|
// Copyright (c) 2012 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_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_
#define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_
#include <map>
#include <string>
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "base/threading/thread_checker.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension_icon_set.h"
#include "extensions/common/extension_id.h"
#include "ui/gfx/image/image.h"
class Profile;
class StatusTray;
namespace extensions {
FORWARD_DECLARE_TEST(SystemIndicatorApiTest, SystemIndicatorUnloaded);
class ExtensionIndicatorIcon;
class ExtensionRegistry;
// Keeps track of all the systemIndicator icons created for a given Profile
// that are currently visible in the UI. Use SystemIndicatorManagerFactory to
// create a SystemIndicatorManager object.
class SystemIndicatorManager : public ExtensionRegistryObserver,
public KeyedService {
public:
SystemIndicatorManager(Profile* profile, StatusTray* status_tray);
~SystemIndicatorManager() override;
// Sets the icon of the system indicator for the given |extension| to
// |icon|.
void SetSystemIndicatorDynamicIcon(const Extension& extension,
gfx::Image icon);
// Sets whether the system indicator for the given |extension| is enabled.
void SetSystemIndicatorEnabled(const Extension& extension, bool is_enabled);
// KeyedService implementation.
void Shutdown() override;
private:
FRIEND_TEST_ALL_PREFIXES(SystemIndicatorApiTest, SystemIndicatorUnloaded);
// A structure representing the system indicator for an extension.
struct SystemIndicator {
SystemIndicator();
~SystemIndicator();
// A dynamically-set icon (through systemIndicator.setIcon()). Takes
// precedence over the |default_icon|.
gfx::Image dynamic_icon;
// The default system indicator icon specified in the manifest.
ExtensionIconSet manifest_icon_set;
// The system tray indicator. This is only non-null if the system indicator
// is enabled.
std::unique_ptr<ExtensionIndicatorIcon> system_tray_indicator;
DISALLOW_COPY_AND_ASSIGN(SystemIndicator);
};
// ExtensionRegistryObserver:
void OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) override;
void OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionReason reason) override;
// Causes a call to OnStatusIconClicked for the specified extension_id.
// Returns false if no ExtensionIndicatorIcon is found for the extension.
bool SendClickEventToExtensionForTest(const std::string& extension_id);
using SystemIndicatorMap = std::map<ExtensionId, SystemIndicator>;
Profile* profile_;
StatusTray* status_tray_;
SystemIndicatorMap system_indicators_;
base::ThreadChecker thread_checker_;
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
DISALLOW_COPY_AND_ASSIGN(SystemIndicatorManager);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_
|