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/threading/thread_checker.h"
13 #include "chrome/browser/extensions/extension_action_icon_factory.h"
14 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "extensions/browser/event_router.h"
19 class ExtensionAction
;
23 FORWARD_DECLARE_TEST(SystemIndicatorApiTest
, SystemIndicator
);
25 namespace extensions
{
27 class ExtensionIndicatorIcon
;
29 // Keeps track of all the systemIndicator icons created for a given Profile
30 // that are currently visible in the UI. Use SystemIndicatorManagerFactory to
31 // create a SystemIndicatorManager object.
32 class SystemIndicatorManager
: public content::NotificationObserver
,
33 public BrowserContextKeyedService
{
35 SystemIndicatorManager(Profile
* profile
, StatusTray
* status_tray
);
36 virtual ~SystemIndicatorManager();
38 // BrowserContextKeyedService implementation.
39 virtual void Shutdown() OVERRIDE
;
41 // content::NotificationDelegate implementation.
42 virtual void Observe(int type
,
43 const content::NotificationSource
& source
,
44 const content::NotificationDetails
& details
) OVERRIDE
;
47 FRIEND_TEST_ALL_PREFIXES(::SystemIndicatorApiTest
, SystemIndicator
);
49 // Determines whether the indicator should be hidden or shown and calls the
50 // appropriate function.
51 void OnSystemIndicatorChanged(const ExtensionAction
* extension_action
);
53 // Causes a call to OnStatusIconClicked for the specified extension_id.
54 // Returns false if no ExtensionIndicatorIcon is found for the extension.
55 bool SendClickEventToExtensionForTest(const std::string extension_id
);
57 // Causes an indicator to be shown for the given extension_action. Creates
58 // the indicator if necessary.
59 void CreateOrUpdateIndicator(
60 const Extension
* extension
,
61 const ExtensionAction
* extension_action
);
63 // Causes the indicator for the given extension to be hidden.
64 void RemoveIndicator(const std::string
&extension_id
);
66 typedef std::map
<const std::string
, linked_ptr
<ExtensionIndicatorIcon
> >
70 StatusTray
* status_tray_
;
71 SystemIndicatorMap system_indicators_
;
72 content::NotificationRegistrar registrar_
;
73 base::ThreadChecker thread_checker_
;
75 DISALLOW_COPY_AND_ASSIGN(SystemIndicatorManager
);
78 } // namespace extensions
80 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_