1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_
11 #include "base/memory/linked_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "base/threading/thread_checker.h"
14 #include "chrome/browser/extensions/extension_action_icon_factory.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "extensions/browser/extension_registry_observer.h"
20 class ExtensionAction;
24 FORWARD_DECLARE_TEST(SystemIndicatorApiTest, SystemIndicator);
26 namespace extensions {
27 class ExtensionIndicatorIcon;
28 class ExtensionRegistry;
30 // Keeps track of all the systemIndicator icons created for a given Profile
31 // that are currently visible in the UI. Use SystemIndicatorManagerFactory to
32 // create a SystemIndicatorManager object.
33 class SystemIndicatorManager : public content::NotificationObserver,
34 public ExtensionRegistryObserver,
37 SystemIndicatorManager(Profile* profile, StatusTray* status_tray);
38 virtual ~SystemIndicatorManager();
40 // KeyedService implementation.
41 virtual void Shutdown() OVERRIDE;
44 FRIEND_TEST_ALL_PREFIXES(::SystemIndicatorApiTest, SystemIndicator);
46 // content::NotificationDelegate implementation.
47 virtual void Observe(int type,
48 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE;
51 // ExtensionRegistryObserver implementation.
52 virtual void OnExtensionUnloaded(
53 content::BrowserContext* browser_context,
54 const Extension* extension,
55 UnloadedExtensionInfo::Reason reason) OVERRIDE;
57 // Determines whether the indicator should be hidden or shown and calls the
58 // appropriate function.
59 void OnSystemIndicatorChanged(const ExtensionAction* extension_action);
61 // Causes a call to OnStatusIconClicked for the specified extension_id.
62 // Returns false if no ExtensionIndicatorIcon is found for the extension.
63 bool SendClickEventToExtensionForTest(const std::string extension_id);
65 // Causes an indicator to be shown for the given extension_action. Creates
66 // the indicator if necessary.
67 void CreateOrUpdateIndicator(
68 const Extension* extension,
69 const ExtensionAction* extension_action);
71 // Causes the indicator for the given extension to be hidden.
72 void RemoveIndicator(const std::string &extension_id);
74 typedef std::map<const std::string, linked_ptr<ExtensionIndicatorIcon> >
78 StatusTray* status_tray_;
79 SystemIndicatorMap system_indicators_;
80 content::NotificationRegistrar registrar_;
81 base::ThreadChecker thread_checker_;
83 // Listen to extension unloaded notifications.
84 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
85 extension_registry_observer_;
87 DISALLOW_COPY_AND_ASSIGN(SystemIndicatorManager);
90 } // namespace extensions
92 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_