Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / system_indicator / system_indicator_manager.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_
7
8 #include <map>
9 #include <string>
10
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"
19
20 class ExtensionAction;
21 class Profile;
22 class StatusTray;
23
24 FORWARD_DECLARE_TEST(SystemIndicatorApiTest, SystemIndicator);
25
26 namespace extensions {
27 class ExtensionIndicatorIcon;
28 class ExtensionRegistry;
29
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,
35                                public KeyedService {
36  public:
37   SystemIndicatorManager(Profile* profile, StatusTray* status_tray);
38   virtual ~SystemIndicatorManager();
39
40   // KeyedService implementation.
41   virtual void Shutdown() OVERRIDE;
42
43  private:
44   FRIEND_TEST_ALL_PREFIXES(::SystemIndicatorApiTest, SystemIndicator);
45
46   // content::NotificationDelegate implementation.
47   virtual void Observe(int type,
48                        const content::NotificationSource& source,
49                        const content::NotificationDetails& details) OVERRIDE;
50
51   // ExtensionRegistryObserver implementation.
52   virtual void OnExtensionUnloaded(
53       content::BrowserContext* browser_context,
54       const Extension* extension,
55       UnloadedExtensionInfo::Reason reason) OVERRIDE;
56
57   // Determines whether the indicator should be hidden or shown and calls the
58   // appropriate function.
59   void OnSystemIndicatorChanged(const ExtensionAction* extension_action);
60
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);
64
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);
70
71   // Causes the indicator for the given extension to be hidden.
72   void RemoveIndicator(const std::string &extension_id);
73
74   typedef std::map<const std::string, linked_ptr<ExtensionIndicatorIcon> >
75       SystemIndicatorMap;
76
77   Profile* profile_;
78   StatusTray* status_tray_;
79   SystemIndicatorMap system_indicators_;
80   content::NotificationRegistrar registrar_;
81   base::ThreadChecker thread_checker_;
82
83   // Listen to extension unloaded notifications.
84   ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
85       extension_registry_observer_;
86
87   DISALLOW_COPY_AND_ASSIGN(SystemIndicatorManager);
88 };
89
90 }  // namespace extensions
91
92 #endif  // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_H_