blob: 4adc1360d6ec157f034a3d8865f79d3e74c1e357 [file] [log] [blame]
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001// 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"
Ben Murdochbb1529c2013-08-08 10:24:53 +010013#include "base/memory/scoped_vector.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010014#include "base/observer_list.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000015#include "chrome/browser/extensions/app_icon_loader.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000016#include "chrome/common/content_settings.h"
Ben Murdochbb1529c2013-08-08 10:24:53 +010017#include "content/public/browser/notification_details.h"
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010018#include "content/public/browser/notification_observer.h"
19#include "content/public/browser/notification_registrar.h"
Ben Murdochbb1529c2013-08-08 10:24:53 +010020#include "content/public/browser/notification_source.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000021#include "ui/message_center/notifier_settings.h"
22
23class CancelableTaskTracker;
Ben Murdochbb1529c2013-08-08 10:24:53 +010024class ProfileInfoCache;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000025
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010026namespace chrome {
27struct FaviconImageResult;
28}
29
Ben Murdochbb1529c2013-08-08 10:24:53 +010030namespace message_center {
31class ProfileNotifierGroup;
32}
33
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000034// The class to bridge between the settings UI of notifiers and the preference
35// storage.
36class MessageCenterSettingsController
37 : public message_center::NotifierSettingsProvider,
Ben Murdochbb1529c2013-08-08 10:24:53 +010038 public content::NotificationObserver,
39 public extensions::AppIconLoader::Delegate {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000040 public:
Ben Murdochbb1529c2013-08-08 10:24:53 +010041 explicit MessageCenterSettingsController(
42 ProfileInfoCache* profile_info_cache);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000043 virtual ~MessageCenterSettingsController();
44
Ben Murdocheb525c52013-07-10 11:40:50 +010045 // Overridden from message_center::NotifierSettingsProvider.
46 virtual void AddObserver(
47 message_center::NotifierSettingsObserver* observer) OVERRIDE;
48 virtual void RemoveObserver(
49 message_center::NotifierSettingsObserver* observer) OVERRIDE;
Ben Murdochbb1529c2013-08-08 10:24:53 +010050 virtual size_t GetNotifierGroupCount() const OVERRIDE;
51 virtual const message_center::NotifierGroup& GetNotifierGroupAt(
52 size_t index) const OVERRIDE;
53 virtual void SwitchToNotifierGroup(size_t index) OVERRIDE;
54 virtual const message_center::NotifierGroup& GetActiveNotifierGroup() const
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000055 OVERRIDE;
Ben Murdochbb1529c2013-08-08 10:24:53 +010056 virtual void GetNotifierList(
57 std::vector<message_center::Notifier*>* notifiers) OVERRIDE;
58 virtual void SetNotifierEnabled(const message_center::Notifier& notifier,
59 bool enabled) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000060 virtual void OnNotifierSettingsClosing() OVERRIDE;
61
62 // Overridden from extensions::AppIconLoader::Delegate.
63 virtual void SetAppImage(const std::string& id,
64 const gfx::ImageSkia& image) OVERRIDE;
65
66 private:
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010067 // Overridden from content::NotificationObserver.
68 virtual void Observe(int type,
69 const content::NotificationSource& source,
70 const content::NotificationDetails& details) OVERRIDE;
71
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000072 void OnFaviconLoaded(const GURL& url,
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010073 const chrome::FaviconImageResult& favicon_result);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000074
Ben Murdochbb1529c2013-08-08 10:24:53 +010075 void RebuildNotifierGroups();
76
Ben Murdocheb525c52013-07-10 11:40:50 +010077 // The views displaying notifier settings.
78 ObserverList<message_center::NotifierSettingsObserver> observers_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000079
80 // The task tracker for loading favicons.
81 scoped_ptr<CancelableTaskTracker> favicon_tracker_;
82
83 scoped_ptr<extensions::AppIconLoader> app_icon_loader_;
84
85 std::map<string16, ContentSettingsPattern> patterns_;
86
Ben Murdochbb1529c2013-08-08 10:24:53 +010087 // The list of all configurable notifier groups. This is each profile that is
88 // loaded (and in the ProfileInfoCache - so no incognito profiles go here).
89 ScopedVector<message_center::ProfileNotifierGroup> notifier_groups_;
90 size_t current_notifier_group_;
91
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010092 content::NotificationRegistrar registrar_;
93
Ben Murdochbb1529c2013-08-08 10:24:53 +010094 ProfileInfoCache* profile_info_cache_;
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010095
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000096 DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsController);
97};
98
99#endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_