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/pref_names.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profile.h" |
| 13 |
| 14 class PluginDataRemoverHelper::Internal |
| 15 : public base::RefCountedThreadSafe<PluginDataRemoverHelper::Internal> { |
| 16 public: |
| 17 explicit Internal(const char* pref_name, PrefService* prefs) |
| 18 : pref_name_(pref_name), prefs_(prefs) {} |
| 19 |
| 20 void StartUpdate() { |
| 21 BrowserThread::PostTask( |
| 22 BrowserThread::FILE, |
| 23 FROM_HERE, |
| 24 NewRunnableMethod( |
| 25 this, |
| 26 &PluginDataRemoverHelper::Internal::UpdateOnFileThread)); |
| 27 } |
| 28 |
| 29 void Invalidate() { |
| 30 prefs_ = NULL; |
| 31 } |
| 32 |
| 33 private: |
| 34 friend class base::RefCountedThreadSafe<Internal>; |
| 35 |
| 36 ~Internal() {} |
| 37 |
| 38 void UpdateOnFileThread() { |
| 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 40 bool result = PluginDataRemover::IsSupported(); |
| 41 BrowserThread::PostTask( |
| 42 BrowserThread::UI, |
| 43 FROM_HERE, |
| 44 NewRunnableMethod(this, |
| 45 &PluginDataRemoverHelper::Internal::SetPrefOnUIThread, |
| 46 result)); |
| 47 } |
| 48 |
| 49 void SetPrefOnUIThread(bool value) { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 51 if (prefs_) |
| 52 prefs_->SetBoolean(pref_name_.c_str(), value); |
| 53 } |
| 54 |
| 55 std::string pref_name_; |
| 56 // Weak pointer. |
| 57 PrefService* prefs_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(Internal); |
| 60 }; |
| 61 |
| 62 PluginDataRemoverHelper::PluginDataRemoverHelper() {} |
| 63 |
| 64 PluginDataRemoverHelper::~PluginDataRemoverHelper() { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 66 if (internal_) |
| 67 internal_->Invalidate(); |
| 68 } |
| 69 |
| 70 void PluginDataRemoverHelper::Init(const char* pref_name, |
| 71 PrefService* prefs, |
| 72 NotificationObserver* observer) { |
| 73 pref_.Init(pref_name, prefs, observer); |
| 74 internal_ = make_scoped_refptr(new Internal(pref_name, prefs)); |
| 75 internal_->StartUpdate(); |
| 76 } |
OLD | NEW |