Chromium Code Reviews| 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 }; | |
|
jochen (gone - plz use gerrit)
2010/11/24 19:03:07
disallow copy and assign
Bernhard Bauer
2010/11/29 10:45:23
Done.
| |
| 59 | |
| 60 PluginDataRemoverHelper::PluginDataRemoverHelper() {} | |
| 61 | |
| 62 PluginDataRemoverHelper::~PluginDataRemoverHelper() { | |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 64 if (internal_) | |
| 65 internal_->Invalidate(); | |
| 66 } | |
| 67 | |
| 68 void PluginDataRemoverHelper::Init(const char* pref_name, | |
| 69 PrefService* prefs, | |
| 70 NotificationObserver* observer) { | |
| 71 pref_.Init(pref_name, prefs, observer); | |
| 72 internal_ = make_scoped_refptr(new Internal(pref_name, prefs)); | |
| 73 internal_->StartUpdate(); | |
| 74 } | |
| OLD | NEW |