Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / message_center_settings_controller.h
1 // Copyright (c) 2013 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_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_
7
8 #include <map>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h"
16 #include "chrome/browser/extensions/app_icon_loader.h"
17 #include "chrome/common/content_settings.h"
18 #include "components/favicon_base/favicon_types.h"
19 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_source.h"
23 #include "ui/message_center/notifier_settings.h"
24
25 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/chromeos/login/user_manager.h"
27 #endif
28
29 class Profile;
30 class ProfileInfoCache;
31
32 namespace base {
33 class CancelableTaskTracker;
34 }
35
36 namespace favicon_base {
37 struct FaviconImageResult;
38 }
39
40 namespace message_center {
41 class ProfileNotifierGroup;
42 }
43
44 // The class to bridge between the settings UI of notifiers and the preference
45 // storage.
46 class MessageCenterSettingsController
47     : public message_center::NotifierSettingsProvider,
48       public content::NotificationObserver,
49 #if defined(OS_CHROMEOS)
50       public chromeos::UserManager::UserSessionStateObserver,
51 #endif
52       public extensions::AppIconLoader::Delegate {
53  public:
54   explicit MessageCenterSettingsController(
55       ProfileInfoCache* profile_info_cache);
56   virtual ~MessageCenterSettingsController();
57
58   // Overridden from message_center::NotifierSettingsProvider.
59   virtual void AddObserver(
60       message_center::NotifierSettingsObserver* observer) OVERRIDE;
61   virtual void RemoveObserver(
62       message_center::NotifierSettingsObserver* observer) OVERRIDE;
63   virtual size_t GetNotifierGroupCount() const OVERRIDE;
64   virtual const message_center::NotifierGroup& GetNotifierGroupAt(
65       size_t index) const OVERRIDE;
66   virtual bool IsNotifierGroupActiveAt(size_t index) const OVERRIDE;
67   virtual void SwitchToNotifierGroup(size_t index) OVERRIDE;
68   virtual const message_center::NotifierGroup& GetActiveNotifierGroup() const
69       OVERRIDE;
70   virtual void GetNotifierList(
71       std::vector<message_center::Notifier*>* notifiers) OVERRIDE;
72   virtual void SetNotifierEnabled(const message_center::Notifier& notifier,
73                                   bool enabled) OVERRIDE;
74   virtual void OnNotifierSettingsClosing() OVERRIDE;
75   virtual bool NotifierHasAdvancedSettings(
76       const message_center::NotifierId& notifier_id) const OVERRIDE;
77   virtual void OnNotifierAdvancedSettingsRequested(
78       const message_center::NotifierId& notifier_id,
79       const std::string* notification_id) OVERRIDE;
80
81 #if defined(OS_CHROMEOS)
82   // Overridden from chromeos::UserManager::UserSessionStateObserver.
83   virtual void ActiveUserChanged(const chromeos::User* active_user) OVERRIDE;
84 #endif
85
86   // Overridden from extensions::AppIconLoader::Delegate.
87   virtual void SetAppImage(const std::string& id,
88                            const gfx::ImageSkia& image) OVERRIDE;
89
90  private:
91   // Overridden from content::NotificationObserver.
92   virtual void Observe(int type,
93                        const content::NotificationSource& source,
94                        const content::NotificationDetails& details) OVERRIDE;
95
96   void OnFaviconLoaded(const GURL& url,
97                        const favicon_base::FaviconImageResult& favicon_result);
98
99 #if defined(OS_CHROMEOS)
100   // Sets up the notifier group for the guest session. This needs to be
101   // separated from RebuildNotifierGroup() and called asynchronously to avoid
102   // the infinite loop of creating profile. See more the comment of
103   // RebuildNotifierGroups().
104   void CreateNotifierGroupForGuestLogin();
105 #endif
106
107   void RebuildNotifierGroups();
108
109   // The views displaying notifier settings.
110   ObserverList<message_center::NotifierSettingsObserver> observers_;
111
112   // The task tracker for loading favicons.
113   scoped_ptr<base::CancelableTaskTracker> favicon_tracker_;
114
115   scoped_ptr<extensions::AppIconLoader> app_icon_loader_;
116
117   std::map<base::string16, ContentSettingsPattern> patterns_;
118
119   // The list of all configurable notifier groups. This is each profile that is
120   // loaded (and in the ProfileInfoCache - so no incognito profiles go here).
121   ScopedVector<message_center::ProfileNotifierGroup> notifier_groups_;
122   size_t current_notifier_group_;
123
124   content::NotificationRegistrar registrar_;
125
126   ProfileInfoCache* profile_info_cache_;
127
128   base::WeakPtrFactory<MessageCenterSettingsController> weak_factory_;
129
130   DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsController);
131 };
132
133 #endif  // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_