Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / system_indicator / system_indicator_manager.h
blob040c216f8e649433634d4ee98c3633e1afa3f39b
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_
8 #include <map>
9 #include <string>
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/api/extension_action/extension_action_api.h"
15 #include "chrome/browser/extensions/extension_action_icon_factory.h"
16 #include "components/keyed_service/core/keyed_service.h"
17 #include "extensions/browser/extension_registry_observer.h"
19 class ExtensionAction;
20 class Profile;
21 class StatusTray;
23 FORWARD_DECLARE_TEST(SystemIndicatorApiTest, SystemIndicator);
25 namespace extensions {
26 class ExtensionIndicatorIcon;
27 class ExtensionRegistry;
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 ExtensionRegistryObserver,
33 public ExtensionActionAPI::Observer,
34 public KeyedService {
35 public:
36 SystemIndicatorManager(Profile* profile, StatusTray* status_tray);
37 ~SystemIndicatorManager() override;
39 // KeyedService implementation.
40 void Shutdown() override;
42 private:
43 FRIEND_TEST_ALL_PREFIXES(::SystemIndicatorApiTest, SystemIndicator);
45 // ExtensionRegistryObserver implementation.
46 void OnExtensionUnloaded(content::BrowserContext* browser_context,
47 const Extension* extension,
48 UnloadedExtensionInfo::Reason reason) override;
50 // ExtensionActionAPI::Observer implementation.
51 void OnExtensionActionUpdated(
52 ExtensionAction* extension_action,
53 content::WebContents* web_contents,
54 content::BrowserContext* browser_context) override;
56 // Causes a call to OnStatusIconClicked for the specified extension_id.
57 // Returns false if no ExtensionIndicatorIcon is found for the extension.
58 bool SendClickEventToExtensionForTest(const std::string extension_id);
60 // Causes an indicator to be shown for the given extension_action. Creates
61 // the indicator if necessary.
62 void CreateOrUpdateIndicator(
63 const Extension* extension,
64 ExtensionAction* extension_action);
66 // Causes the indicator for the given extension to be hidden.
67 void RemoveIndicator(const std::string &extension_id);
69 typedef std::map<const std::string, linked_ptr<ExtensionIndicatorIcon> >
70 SystemIndicatorMap;
72 Profile* profile_;
73 StatusTray* status_tray_;
74 SystemIndicatorMap system_indicators_;
75 base::ThreadChecker thread_checker_;
77 ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer>
78 extension_action_observer_;
80 // Listen to extension unloaded notifications.
81 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
82 extension_registry_observer_;
84 DISALLOW_COPY_AND_ASSIGN(SystemIndicatorManager);
87 } // namespace extensions
89 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_