OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 #include "chrome/browser/plugin_data_remover_helper.h" |
| 6 |
| 7 #include "base/ref_counted.h" |
| 8 #include "chrome/browser/browser_thread.h" |
| 9 #include "chrome/browser/plugin_data_remover.h" |
| 10 #include "chrome/common/notification_service.h" |
| 11 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profile.h" |
| 14 |
| 15 class PluginDataRemoverHelper::Internal |
| 16 : public base::RefCountedThreadSafe<PluginDataRemoverHelper::Internal> { |
| 17 public: |
| 18 explicit Internal(const char* pref_name, PrefService* prefs) |
| 19 : pref_name_(pref_name), prefs_(prefs) {} |
| 20 |
| 21 void StartUpdate() { |
| 22 BrowserThread::PostTask( |
| 23 BrowserThread::FILE, |
| 24 FROM_HERE, |
| 25 NewRunnableMethod( |
| 26 this, |
| 27 &PluginDataRemoverHelper::Internal::UpdateOnFileThread)); |
| 28 } |
| 29 |
| 30 void Invalidate() { |
| 31 prefs_ = NULL; |
| 32 } |
| 33 |
| 34 private: |
| 35 friend class base::RefCountedThreadSafe<Internal>; |
| 36 |
| 37 ~Internal() {} |
| 38 |
| 39 void UpdateOnFileThread() { |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 41 bool result = PluginDataRemover::IsSupported(); |
| 42 BrowserThread::PostTask( |
| 43 BrowserThread::UI, |
| 44 FROM_HERE, |
| 45 NewRunnableMethod(this, |
| 46 &PluginDataRemoverHelper::Internal::SetPrefOnUIThread, |
| 47 result)); |
| 48 } |
| 49 |
| 50 void SetPrefOnUIThread(bool value) { |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 52 if (prefs_) |
| 53 prefs_->SetBoolean(pref_name_.c_str(), value); |
| 54 } |
| 55 |
| 56 std::string pref_name_; |
| 57 // Weak pointer. |
| 58 PrefService* prefs_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(Internal); |
| 61 }; |
| 62 |
| 63 PluginDataRemoverHelper::PluginDataRemoverHelper() {} |
| 64 |
| 65 PluginDataRemoverHelper::~PluginDataRemoverHelper() { |
| 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 67 if (internal_) |
| 68 internal_->Invalidate(); |
| 69 } |
| 70 |
| 71 void PluginDataRemoverHelper::Init(const char* pref_name, |
| 72 PrefService* prefs, |
| 73 NotificationObserver* observer) { |
| 74 pref_.Init(pref_name, prefs, observer); |
| 75 registrar_.Add(this, NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, |
| 76 NotificationService::AllSources()); |
| 77 internal_ = make_scoped_refptr(new Internal(pref_name, prefs)); |
| 78 internal_->StartUpdate(); |
| 79 } |
| 80 |
| 81 void PluginDataRemoverHelper::Observe(NotificationType type, |
| 82 const NotificationSource& source, |
| 83 const NotificationDetails& details) { |
| 84 if (type.value == NotificationType::PLUGIN_ENABLE_STATUS_CHANGED) { |
| 85 internal_->StartUpdate(); |
| 86 } else { |
| 87 NOTREACHED(); |
| 88 } |
| 89 } |
OLD | NEW |