Print Preview: Changing displayed error message when PDF Viewer is missing.
[chromium-blink-merge.git] / chrome / browser / plugin_data_remover_helper.cc
blob0f4df9dcf66d2020647edf6ccb995e7ccd68ab4d
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.
5 #include "chrome/browser/plugin_data_remover_helper.h"
7 #include <string>
9 #include "base/memory/ref_counted.h"
10 #include "chrome/browser/plugin_data_remover.h"
11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "content/browser/browser_thread.h"
14 #include "content/common/notification_service.h"
16 // The internal class is refcounted so it can outlive PluginDataRemoverHelper.
17 class PluginDataRemoverHelper::Internal
18 : public base::RefCountedThreadSafe<PluginDataRemoverHelper::Internal> {
19 public:
20 explicit Internal(const char* pref_name, PrefService* prefs)
21 : pref_name_(pref_name), prefs_(prefs) {}
23 void StartUpdate() {
24 BrowserThread::PostTask(
25 BrowserThread::FILE,
26 FROM_HERE,
27 NewRunnableMethod(
28 this,
29 &PluginDataRemoverHelper::Internal::UpdateOnFileThread));
32 void Invalidate() {
33 prefs_ = NULL;
36 private:
37 friend class base::RefCountedThreadSafe<Internal>;
39 ~Internal() {}
41 void UpdateOnFileThread() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
43 bool result = PluginDataRemover::IsSupported();
44 BrowserThread::PostTask(
45 BrowserThread::UI,
46 FROM_HERE,
47 NewRunnableMethod(this,
48 &PluginDataRemoverHelper::Internal::SetPrefOnUIThread,
49 result));
52 void SetPrefOnUIThread(bool value) {
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
54 if (prefs_)
55 prefs_->SetBoolean(pref_name_.c_str(), value);
58 std::string pref_name_;
59 // Weak pointer.
60 PrefService* prefs_;
62 DISALLOW_COPY_AND_ASSIGN(Internal);
65 PluginDataRemoverHelper::PluginDataRemoverHelper() {}
67 PluginDataRemoverHelper::~PluginDataRemoverHelper() {
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
69 if (internal_)
70 internal_->Invalidate();
73 void PluginDataRemoverHelper::Init(const char* pref_name,
74 PrefService* prefs,
75 NotificationObserver* observer) {
76 pref_.Init(pref_name, prefs, observer);
77 registrar_.Add(this, NotificationType::PLUGIN_ENABLE_STATUS_CHANGED,
78 NotificationService::AllSources());
79 internal_ = make_scoped_refptr(new Internal(pref_name, prefs));
80 internal_->StartUpdate();
83 void PluginDataRemoverHelper::Observe(NotificationType type,
84 const NotificationSource& source,
85 const NotificationDetails& details) {
86 if (type.value == NotificationType::PLUGIN_ENABLE_STATUS_CHANGED) {
87 internal_->StartUpdate();
88 } else {
89 NOTREACHED();