1// Copyright (c) 2011 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_PLUGIN_UPDATER_H_
6#define CHROME_BROWSER_PLUGIN_UPDATER_H_
7#pragma once
8
9#include <set>
10#include <vector>
11
12#include "base/basictypes.h"
13#include "base/file_path.h"
14#include "base/memory/singleton.h"
15#include "content/common/notification_observer.h"
16
17class DictionaryValue;
18class ListValue;
19class NotificationDetails;
20class NotificationSource;
21class Profile;
22
23namespace webkit {
24namespace npapi {
25class PluginGroup;
26struct WebPluginInfo;
27}
28}
29
30class PluginUpdater : public NotificationObserver {
31 public:
32  // Get a list of all the plugin groups. The caller should take ownership
33  // of the returned ListValue.
34  static ListValue* GetPluginGroupsData();
35
36  // Enable or disable a plugin group.
37  void EnablePluginGroup(bool enable, const string16& group_name);
38
39  // Enable or disable a specific plugin file.
40  void EnablePlugin(bool enable, const FilePath::StringType& file_path);
41
42  // Enable or disable plugin groups as defined by the user's preference file.
43  void UpdatePluginGroupsStateFromPrefs(Profile* profile);
44
45  // Write the enable/disable status to the user's preference file.
46  void UpdatePreferences(Profile* profile, int delay_ms);
47
48  // NotificationObserver method overrides
49  virtual void Observe(NotificationType type,
50                       const NotificationSource& source,
51                       const NotificationDetails& details);
52
53  static PluginUpdater* GetInstance();
54
55 private:
56  PluginUpdater();
57  virtual ~PluginUpdater() {}
58
59  // Called on the file thread to get the data necessary to update the saved
60  // preferences.  The profile pointer is only to be passed to the UI thread.
61  static void GetPreferencesDataOnFileThread(void* profile);
62
63  // Called on the UI thread with the plugin data to save the preferences.
64  static void OnUpdatePreferences(
65      Profile* profile,
66      const std::vector<webkit::npapi::WebPluginInfo>& plugins,
67      const std::vector<webkit::npapi::PluginGroup>& groups);
68
69  // Queues sending the notification that plugin data has changed.  This is done
70  // so that if a bunch of changes happen, we only send one notification.
71  void NotifyPluginStatusChanged();
72
73  // Used for the post task to notify that plugin enabled status changed.
74  static void OnNotifyPluginStatusChanged();
75
76  static DictionaryValue* CreatePluginFileSummary(
77      const webkit::npapi::WebPluginInfo& plugin);
78
79  // Force plugins to be enabled or disabled due to policy.
80  // |disabled_list| contains the list of StringValues of the names of the
81  // policy-disabled plugins, |exceptions_list| the policy-allowed plugins,
82  // and |enabled_list| the policy-enabled plugins.
83  void UpdatePluginsStateFromPolicy(const ListValue* disabled_list,
84                                    const ListValue* exceptions_list,
85                                    const ListValue* enabled_list);
86
87  void ListValueToStringSet(const ListValue* src, std::set<string16>* dest);
88
89  // Needed to allow singleton instantiation using private constructor.
90  friend struct DefaultSingletonTraits<PluginUpdater>;
91
92  bool notify_pending_;
93
94  DISALLOW_COPY_AND_ASSIGN(PluginUpdater);
95};
96
97#endif  // CHROME_BROWSER_PLUGIN_UPDATER_H_
98