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