Commit d8e68201 authored by jam@chromium.org's avatar jam@chromium.org

Move the PluginDataRemover class to content, and remove the chrome pieces from...

Move the PluginDataRemover class to content, and remove the chrome pieces from it. This class really belongs in content because it's part of the web platform. I've also wrapped it with an interface that is used by chrome.

BUG=98716
Review URL: http://codereview.chromium.org/8590016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110530 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d87a94b
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/net/predictor.h" #include "chrome/browser/net/predictor.h"
#include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/plugin_data_remover.h"
#include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/prefs/pref_member.h"
#include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_manager_factory.h" #include "chrome/browser/prerender/prerender_manager_factory.h"
...@@ -47,6 +46,7 @@ ...@@ -47,6 +46,7 @@
#include "content/browser/user_metrics.h" #include "content/browser/user_metrics.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/browser/plugin_data_remover.h"
#include "net/base/cookie_monster.h" #include "net/base/cookie_monster.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/base/transport_security_state.h" #include "net/base/transport_security_state.h"
...@@ -236,8 +236,10 @@ void BrowsingDataRemover::Remove(int remove_mask) { ...@@ -236,8 +236,10 @@ void BrowsingDataRemover::Remove(int remove_mask) {
UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
waiting_for_clear_lso_data_ = true; waiting_for_clear_lso_data_ = true;
if (!plugin_data_remover_.get()) if (!plugin_data_remover_.get()) {
plugin_data_remover_ = new PluginDataRemover(profile_); plugin_data_remover_.reset(
content::PluginDataRemover::Create(profile_->GetResourceContext()));
}
base::WaitableEvent* event = base::WaitableEvent* event =
plugin_data_remover_->StartRemoving(delete_begin_); plugin_data_remover_->StartRemoving(delete_begin_);
watcher_.StartWatching(event, this); watcher_.StartWatching(event, this);
......
...@@ -21,9 +21,12 @@ ...@@ -21,9 +21,12 @@
class ExtensionSpecialStoragePolicy; class ExtensionSpecialStoragePolicy;
class IOThread; class IOThread;
class PluginDataRemover;
class Profile; class Profile;
namespace content {
class PluginDataRemover;
}
namespace disk_cache { namespace disk_cache {
class Backend; class Backend;
} }
...@@ -234,7 +237,7 @@ class BrowsingDataRemover : public content::NotificationObserver, ...@@ -234,7 +237,7 @@ class BrowsingDataRemover : public content::NotificationObserver,
scoped_refptr<net::URLRequestContextGetter> media_context_getter_; scoped_refptr<net::URLRequestContextGetter> media_context_getter_;
// Used to delete plugin data. // Used to delete plugin data.
scoped_refptr<PluginDataRemover> plugin_data_remover_; scoped_ptr<content::PluginDataRemover> plugin_data_remover_;
base::WaitableEventWatcher watcher_; base::WaitableEventWatcher watcher_;
// True if we're waiting for various data to be deleted. // True if we're waiting for various data to be deleted.
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/browsing_data_remover.h" #include "chrome/browser/browsing_data_remover.h"
#include "chrome/browser/extensions/extension_clear_api_constants.h" #include "chrome/browser/extensions/extension_clear_api_constants.h"
#include "chrome/browser/plugin_data_remover.h" #include "chrome/browser/plugin_data_remover_helper.h"
#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
...@@ -124,7 +124,7 @@ bool BrowsingDataExtensionFunction::RunImpl() { ...@@ -124,7 +124,7 @@ bool BrowsingDataExtensionFunction::RunImpl() {
void BrowsingDataExtensionFunction::CheckRemovingLSODataSupported( void BrowsingDataExtensionFunction::CheckRemovingLSODataSupported(
scoped_refptr<PluginPrefs> plugin_prefs) { scoped_refptr<PluginPrefs> plugin_prefs) {
if (!PluginDataRemover::IsSupported(plugin_prefs)) if (!PluginDataRemoverHelper::IsSupported(plugin_prefs))
removal_mask_ &= ~BrowsingDataRemover::REMOVE_LSO_DATA; removal_mask_ &= ~BrowsingDataRemover::REMOVE_LSO_DATA;
BrowserThread::PostTask( BrowserThread::PostTask(
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <string> #include <string>
#include "base/bind.h" #include "base/bind.h"
#include "chrome/browser/plugin_data_remover.h"
#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -15,6 +14,7 @@ ...@@ -15,6 +14,7 @@
#include "content/browser/plugin_service.h" #include "content/browser/plugin_service.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/browser/plugin_data_remover.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -35,6 +35,13 @@ void PluginDataRemoverHelper::Init(const char* pref_name, ...@@ -35,6 +35,13 @@ void PluginDataRemoverHelper::Init(const char* pref_name,
StartUpdate(); StartUpdate();
} }
// static
bool PluginDataRemoverHelper::IsSupported(PluginPrefs* plugin_prefs) {
webkit::WebPluginInfo plugin;
return content::PluginDataRemover::IsSupported(&plugin) &&
plugin_prefs->IsPluginEnabled(plugin);
}
void PluginDataRemoverHelper::Observe( void PluginDataRemoverHelper::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
...@@ -56,7 +63,7 @@ void PluginDataRemoverHelper::GotPlugins( ...@@ -56,7 +63,7 @@ void PluginDataRemoverHelper::GotPlugins(
scoped_refptr<PluginPrefs> plugin_prefs, scoped_refptr<PluginPrefs> plugin_prefs,
const std::vector<webkit::WebPluginInfo>& plugins) { const std::vector<webkit::WebPluginInfo>& plugins) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
bool supported = PluginDataRemover::IsSupported(plugin_prefs); bool supported = IsSupported(plugin_prefs);
// Set the value on the PrefService instead of through the PrefMember to // Set the value on the PrefService instead of through the PrefMember to
// notify observers if it changed. // notify observers if it changed.
profile_->GetPrefs()->SetBoolean(pref_.GetPrefName().c_str(), supported); profile_->GetPrefs()->SetBoolean(pref_.GetPrefName().c_str(), supported);
......
...@@ -41,6 +41,10 @@ class PluginDataRemoverHelper : public content::NotificationObserver { ...@@ -41,6 +41,10 @@ class PluginDataRemoverHelper : public content::NotificationObserver {
bool GetValue() const { return pref_.GetValue(); } bool GetValue() const { return pref_.GetValue(); }
// Like PluginDataRemover::IsSupported, but checks that the returned plugin
// is enabled by PluginPrefs
static bool IsSupported(PluginPrefs* plugin_prefs);
// content::NotificationObserver methods: // content::NotificationObserver methods:
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "content/browser/worker_host/worker_process_host.h" #include "content/browser/worker_host/worker_process_host.h"
#include "content/browser/worker_host/worker_service.h" #include "content/browser/worker_host/worker_service.h"
#include "content/browser/worker_host/worker_service_observer.h" #include "content/browser/worker_host/worker_service_observer.h"
#include "content/common/devtools_messages.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "grit/workers_resources.h" #include "grit/workers_resources.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
......
...@@ -1719,8 +1719,6 @@ ...@@ -1719,8 +1719,6 @@
'browser/platform_util_linux.cc', 'browser/platform_util_linux.cc',
'browser/platform_util_mac.mm', 'browser/platform_util_mac.mm',
'browser/platform_util_win.cc', 'browser/platform_util_win.cc',
'browser/plugin_data_remover.cc',
'browser/plugin_data_remover.h',
'browser/plugin_data_remover_helper.cc', 'browser/plugin_data_remover_helper.cc',
'browser/plugin_data_remover_helper.h', 'browser/plugin_data_remover_helper.h',
'browser/plugin_download_helper.cc', 'browser/plugin_download_helper.cc',
......
...@@ -2604,7 +2604,6 @@ ...@@ -2604,7 +2604,6 @@
'browser/notifications/desktop_notifications_unittest.cc', 'browser/notifications/desktop_notifications_unittest.cc',
'browser/notifications/desktop_notifications_unittest.h', 'browser/notifications/desktop_notifications_unittest.h',
'browser/oom_priority_manager_browsertest.cc', 'browser/oom_priority_manager_browsertest.cc',
'browser/plugin_data_remover_browsertest.cc',
'browser/policy/device_management_backend_mock.cc', 'browser/policy/device_management_backend_mock.cc',
'browser/policy/device_management_backend_mock.h', 'browser/policy/device_management_backend_mock.h',
'browser/policy/device_management_service_browsertest.cc', 'browser/policy/device_management_service_browsertest.cc',
...@@ -2725,6 +2724,7 @@ ...@@ -2725,6 +2724,7 @@
'../content/browser/file_system/file_system_browsertest.cc', '../content/browser/file_system/file_system_browsertest.cc',
'../content/browser/in_process_webkit/dom_storage_browsertest.cc', '../content/browser/in_process_webkit/dom_storage_browsertest.cc',
'../content/browser/in_process_webkit/indexed_db_browsertest.cc', '../content/browser/in_process_webkit/indexed_db_browsertest.cc',
'../content/browser/plugin_data_remover_impl_browsertest.cc',
'../content/browser/plugin_service_browsertest.cc', '../content/browser/plugin_service_browsertest.cc',
'../content/browser/renderer_host/render_process_host_browsertest.cc', '../content/browser/renderer_host/render_process_host_browsertest.cc',
'../content/browser/renderer_host/render_process_host_browsertest.h', '../content/browser/renderer_host/render_process_host_browsertest.h',
......
...@@ -761,9 +761,6 @@ const char kMessageLoopHistogrammer[] = "message-loop-histogrammer"; ...@@ -761,9 +761,6 @@ const char kMessageLoopHistogrammer[] = "message-loop-histogrammer";
// performance tests. // performance tests.
const char kMetricsRecordingOnly[] = "metrics-recording-only"; const char kMetricsRecordingOnly[] = "metrics-recording-only";
// The minimum version of Flash that implements the NPP_ClearSiteData API.
const char kMinClearSiteDataFlashVersion[] = "min-clearsitedata-flash-version";
// Enables multiprofile Chrome. // Enables multiprofile Chrome.
const char kMultiProfiles[] = "multi-profiles"; const char kMultiProfiles[] = "multi-profiles";
......
...@@ -210,7 +210,6 @@ extern const char kMediaCacheSize[]; ...@@ -210,7 +210,6 @@ extern const char kMediaCacheSize[];
extern const char kMemoryProfiling[]; extern const char kMemoryProfiling[];
extern const char kMessageLoopHistogrammer[]; extern const char kMessageLoopHistogrammer[];
extern const char kMetricsRecordingOnly[]; extern const char kMetricsRecordingOnly[];
extern const char kMinClearSiteDataFlashVersion[];
extern const char kMultiProfiles[]; extern const char kMultiProfiles[];
extern const char kNaClDebugIP[]; extern const char kNaClDebugIP[];
extern const char kNaClDebugPorts[]; extern const char kNaClDebugPorts[];
......
...@@ -195,6 +195,10 @@ void InProcessBrowserTest::TearDown() { ...@@ -195,6 +195,10 @@ void InProcessBrowserTest::TearDown() {
BrowserTestBase::TearDown(); BrowserTestBase::TearDown();
} }
const content::ResourceContext& InProcessBrowserTest::GetResourceContext() {
return browser_->profile()->GetResourceContext();
}
void InProcessBrowserTest::AddTabAtIndexToBrowser( void InProcessBrowserTest::AddTabAtIndexToBrowser(
Browser* browser, Browser* browser,
int index, int index,
......
...@@ -26,6 +26,7 @@ class Profile; ...@@ -26,6 +26,7 @@ class Profile;
namespace content { namespace content {
class ContentRendererClient; class ContentRendererClient;
class ResourceContext;
} }
namespace net { namespace net {
...@@ -88,6 +89,10 @@ class InProcessBrowserTest : public BrowserTestBase { ...@@ -88,6 +89,10 @@ class InProcessBrowserTest : public BrowserTestBase {
// Returns the browser created by CreateBrowser. // Returns the browser created by CreateBrowser.
Browser* browser() const { return browser_; } Browser* browser() const { return browser_; }
// Returns the ResourceContext from browser_. Needed because tests in content
// don't have access to Profile.
const content::ResourceContext& GetResourceContext();
// Convenience methods for adding tabs to a Browser. // Convenience methods for adding tabs to a Browser.
void AddTabAtIndexToBrowser(Browser* browser, void AddTabAtIndexToBrowser(Browser* browser,
int index, int index,
......
...@@ -2,26 +2,17 @@ ...@@ -2,26 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/plugin_data_remover.h" #include "content/browser/plugin_data_remover_impl.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop_proxy.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/version.h" #include "base/version.h"
#include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "content/browser/plugin_service.h" #include "content/browser/plugin_service.h"
#include "content/common/plugin_messages.h" #include "content/common/plugin_messages.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "webkit/plugins/npapi/plugin_group.h" #include "webkit/plugins/npapi/plugin_group.h"
#if defined(OS_POSIX)
#include "ipc/ipc_channel_posix.h"
#endif
using content::BrowserThread; using content::BrowserThread;
namespace { namespace {
...@@ -34,83 +25,104 @@ const uint64 kClearAllData = 0; ...@@ -34,83 +25,104 @@ const uint64 kClearAllData = 0;
} // namespace } // namespace
PluginDataRemover::PluginDataRemover(Profile* profile) namespace content {
// static
PluginDataRemover* PluginDataRemover::Create(
const content::ResourceContext& resource_context) {
return new PluginDataRemoverImpl(resource_context);
}
// static
bool PluginDataRemover::IsSupported(webkit::WebPluginInfo* plugin) {
bool allow_wildcard = false;
std::vector<webkit::WebPluginInfo> plugins;
PluginService::GetInstance()->GetPluginInfoArray(
GURL(), kFlashMimeType, allow_wildcard, &plugins, NULL);
std::vector<webkit::WebPluginInfo>::iterator plugin_it = plugins.begin();
if (plugin_it == plugins.end())
return false;
scoped_ptr<Version> version(
webkit::npapi::PluginGroup::CreateVersionFromString(plugin_it->version));
scoped_ptr<Version> min_version(
Version::GetVersionFromString(kMinFlashVersion));
bool rv = version.get() && min_version->CompareTo(*version) == -1;
if (rv)
*plugin = *plugin_it;
return rv;
}
}
PluginDataRemoverImpl::PluginDataRemoverImpl(
const content::ResourceContext& resource_context)
: mime_type_(kFlashMimeType), : mime_type_(kFlashMimeType),
is_starting_process_(false),
is_removing_(false), is_removing_(false),
context_(profile->GetResourceContext()), context_(resource_context),
event_(new base::WaitableEvent(true, false)), event_(new base::WaitableEvent(true, false)),
channel_(NULL) { channel_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
} }
PluginDataRemover::~PluginDataRemover() { PluginDataRemoverImpl::~PluginDataRemoverImpl() {
if (is_starting_process_)
PluginService::GetInstance()->CancelOpenChannelToNpapiPlugin(this);
DCHECK(!is_removing_); DCHECK(!is_removing_);
if (channel_) if (channel_)
BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_);
} }
base::WaitableEvent* PluginDataRemover::StartRemoving(base::Time begin_time) { base::WaitableEvent* PluginDataRemoverImpl::StartRemoving(
base::Time begin_time) {
DCHECK(!is_removing_); DCHECK(!is_removing_);
remove_start_time_ = base::Time::Now(); remove_start_time_ = base::Time::Now();
begin_time_ = begin_time; begin_time_ = begin_time;
is_starting_process_ = true;
is_removing_ = true; is_removing_ = true;
// Balanced in OnChannelOpened or OnError. Exactly one them will eventually be
// called, so we need to keep this object around until then.
AddRef();
PluginService::GetInstance()->OpenChannelToNpapiPlugin( PluginService::GetInstance()->OpenChannelToNpapiPlugin(
0, 0, GURL(), GURL(), mime_type_, this); 0, 0, GURL(), GURL(), mime_type_, this);
BrowserThread::PostDelayedTask( BrowserThread::PostDelayedTask(
BrowserThread::IO, BrowserThread::IO,
FROM_HERE, FROM_HERE,
base::Bind(&PluginDataRemover::OnTimeout, this), base::Bind(&PluginDataRemoverImpl::OnTimeout, weak_factory_.GetWeakPtr()),
kRemovalTimeoutMs); kRemovalTimeoutMs);
return event_.get(); return event_.get();
} }
void PluginDataRemover::Wait() { int PluginDataRemoverImpl::ID() {
base::Time start_time(base::Time::Now());
if (is_removing_)
event_->Wait();
UMA_HISTOGRAM_TIMES("ClearPluginData.wait_at_shutdown",
base::Time::Now() - start_time);
UMA_HISTOGRAM_TIMES("ClearPluginData.time_at_shutdown",
base::Time::Now() - remove_start_time_);
}
int PluginDataRemover::ID() {
// Generate a unique identifier for this PluginProcessHostClient. // Generate a unique identifier for this PluginProcessHostClient.
return ChildProcessInfo::GenerateChildProcessUniqueId(); return ChildProcessInfo::GenerateChildProcessUniqueId();
} }
bool PluginDataRemover::OffTheRecord() { bool PluginDataRemoverImpl::OffTheRecord() {
return false; return false;
} }
const content::ResourceContext& PluginDataRemover::GetResourceContext() { const content::ResourceContext& PluginDataRemoverImpl::GetResourceContext() {
return context_; return context_;
} }
void PluginDataRemover::SetPluginInfo( void PluginDataRemoverImpl::SetPluginInfo(
const webkit::WebPluginInfo& info) { const webkit::WebPluginInfo& info) {
} }
void PluginDataRemover::OnFoundPluginProcessHost( void PluginDataRemoverImpl::OnFoundPluginProcessHost(
PluginProcessHost* host) { PluginProcessHost* host) {
} }
void PluginDataRemover::OnSentPluginChannelRequest() { void PluginDataRemoverImpl::OnSentPluginChannelRequest() {
} }
void PluginDataRemover::OnChannelOpened(const IPC::ChannelHandle& handle) { void PluginDataRemoverImpl::OnChannelOpened(const IPC::ChannelHandle& handle) {
is_starting_process_ = false;
ConnectToChannel(handle); ConnectToChannel(handle);
// Balancing the AddRef call in StartRemoving.
Release();
} }
void PluginDataRemover::ConnectToChannel(const IPC::ChannelHandle& handle) { void PluginDataRemoverImpl::ConnectToChannel(const IPC::ChannelHandle& handle) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// If we timed out, don't bother connecting. // If we timed out, don't bother connecting.
...@@ -134,27 +146,25 @@ void PluginDataRemover::ConnectToChannel(const IPC::ChannelHandle& handle) { ...@@ -134,27 +146,25 @@ void PluginDataRemover::ConnectToChannel(const IPC::ChannelHandle& handle) {
} }
} }
void PluginDataRemover::OnError() { void PluginDataRemoverImpl::OnError() {
LOG(DFATAL) << "Couldn't open plugin channel"; LOG(DFATAL) << "Couldn't open plugin channel";
SignalDone(); SignalDone();
// Balancing the AddRef call in StartRemoving.
Release();
} }
void PluginDataRemover::OnClearSiteDataResult(bool success) { void PluginDataRemoverImpl::OnClearSiteDataResult(bool success) {
LOG_IF(ERROR, !success) << "ClearSiteData returned error"; LOG_IF(ERROR, !success) << "ClearSiteData returned error";
UMA_HISTOGRAM_TIMES("ClearPluginData.time", UMA_HISTOGRAM_TIMES("ClearPluginData.time",
base::Time::Now() - remove_start_time_); base::Time::Now() - remove_start_time_);
SignalDone(); SignalDone();
} }
void PluginDataRemover::OnTimeout() { void PluginDataRemoverImpl::OnTimeout() {
LOG_IF(ERROR, is_removing_) << "Timed out"; LOG_IF(ERROR, is_removing_) << "Timed out";
SignalDone(); SignalDone();
} }
bool PluginDataRemover::OnMessageReceived(const IPC::Message& msg) { bool PluginDataRemoverImpl::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(PluginDataRemover, msg) IPC_BEGIN_MESSAGE_MAP(PluginDataRemoverImpl, msg)
IPC_MESSAGE_HANDLER(PluginHostMsg_ClearSiteDataResult, IPC_MESSAGE_HANDLER(PluginHostMsg_ClearSiteDataResult,
OnClearSiteDataResult) OnClearSiteDataResult)
IPC_MESSAGE_UNHANDLED_ERROR() IPC_MESSAGE_UNHANDLED_ERROR()
...@@ -163,38 +173,18 @@ bool PluginDataRemover::OnMessageReceived(const IPC::Message& msg) { ...@@ -163,38 +173,18 @@ bool PluginDataRemover::OnMessageReceived(const IPC::Message& msg) {
return true; return true;
} }
void PluginDataRemover::OnChannelError() { void PluginDataRemoverImpl::OnChannelError() {
is_starting_process_ = false;
if (is_removing_) { if (is_removing_) {
NOTREACHED() << "Channel error"; NOTREACHED() << "Channel error";
SignalDone(); SignalDone();
} }
} }
void PluginDataRemover::SignalDone() { void PluginDataRemoverImpl::SignalDone() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!is_removing_) if (!is_removing_)
return; return;
is_removing_ = false; is_removing_ = false;
event_->Signal(); event_->Signal();
} }
// static
bool PluginDataRemover::IsSupported(PluginPrefs* plugin_prefs) {
bool allow_wildcard = false;
std::vector<webkit::WebPluginInfo> plugins;
PluginService::GetInstance()->GetPluginInfoArray(
GURL(), kFlashMimeType, allow_wildcard, &plugins, NULL);
std::vector<webkit::WebPluginInfo>::iterator plugin = plugins.begin();
if (plugin == plugins.end())
return false;
scoped_ptr<Version> version(
webkit::npapi::PluginGroup::CreateVersionFromString(plugin->version));
scoped_ptr<Version> min_version(Version::GetVersionFromString(
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kMinClearSiteDataFlashVersion)));
if (!min_version.get())
min_version.reset(Version::GetVersionFromString(kMinFlashVersion));
return plugin_prefs->IsPluginEnabled(*plugin) &&
version.get() &&
min_version->CompareTo(*version) == -1;
}
...@@ -2,50 +2,32 @@ ...@@ -2,50 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ #ifndef CONTENT_BROWSER_PLUGIN_DATA_REMOVER_IMPL_H_
#define CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ #define CONTENT_BROWSER_PLUGIN_DATA_REMOVER_IMPL_H_
#pragma once #pragma once
#include <string> #include <string>
#include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h"
#include "base/time.h"
#include "content/browser/plugin_process_host.h" #include "content/browser/plugin_process_host.h"
#include "content/public/browser/plugin_data_remover.h"
class PluginPrefs; class PluginDataRemoverImpl : public content::PluginDataRemover,
class Profile;
namespace base {
class WaitableEvent;
}
class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>,
public PluginProcessHost::Client, public PluginProcessHost::Client,
public IPC::Channel::Listener { public IPC::Channel::Listener {
public: public:
explicit PluginDataRemover(Profile* profile); explicit PluginDataRemoverImpl(
const content::ResourceContext& resource_context);
virtual ~PluginDataRemoverImpl();
// content::PluginDataRemover implementation:
virtual base::WaitableEvent* StartRemoving(base::Time begin_time) OVERRIDE;
// The plug-in whose data should be removed (usually Flash) is specified via // The plug-in whose data should be removed (usually Flash) is specified via
// its MIME type. This method sets a different MIME type in order to call a // its MIME type. This method sets a different MIME type in order to call a
// different plug-in (for example in tests). // different plug-in (for example in tests).
void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; }
// Starts removing plug-in data stored since |begin_time|.
base::WaitableEvent* StartRemoving(base::Time begin_time);
// Returns whether there is a plug-in installed that supports removing
// LSO data. This method will use cached plugin data. Call
// PluginService::GetPlugins() if the latest data is needed.
static bool IsSupported(PluginPrefs* plugin_prefs);
// Indicates whether we are still in the process of removing plug-in data.
bool is_removing() const { return is_removing_; }
// Wait until removing has finished. When the browser is still running (i.e.
// not during shutdown), you should use a WaitableEventWatcher in combination
// with the WaitableEvent returned by StartRemoving.
void Wait();
// PluginProcessHost::Client methods. // PluginProcessHost::Client methods.
virtual int ID() OVERRIDE; virtual int ID() OVERRIDE;
virtual bool OffTheRecord() OVERRIDE; virtual bool OffTheRecord() OVERRIDE;
...@@ -61,10 +43,6 @@ class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>, ...@@ -61,10 +43,6 @@ class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>,
virtual void OnChannelError() OVERRIDE; virtual void OnChannelError() OVERRIDE;
private: private:
friend class base::RefCountedThreadSafe<PluginDataRemover>;
friend class PluginDataRemoverTest;
virtual ~PluginDataRemover();
// Signals that we are finished with removing data (successful or not). This // Signals that we are finished with removing data (successful or not). This
// method is safe to call multiple times. // method is safe to call multiple times.
void SignalDone(); void SignalDone();
...@@ -77,6 +55,7 @@ class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>, ...@@ -77,6 +55,7 @@ class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>,
void OnTimeout(); void OnTimeout();
std::string mime_type_; std::string mime_type_;
bool is_starting_process_;
bool is_removing_; bool is_removing_;
// The point in time when we start removing data. // The point in time when we start removing data.
base::Time remove_start_time_; base::Time remove_start_time_;
...@@ -90,7 +69,9 @@ class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>, ...@@ -90,7 +69,9 @@ class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>,
// process. // process.
IPC::Channel* channel_; IPC::Channel* channel_;
DISALLOW_COPY_AND_ASSIGN(PluginDataRemover); base::WeakPtrFactory<PluginDataRemoverImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PluginDataRemoverImpl);
}; };
#endif // CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ #endif // CONTENT_BROWSER_PLUGIN_DATA_REMOVER_IMPL_H_
...@@ -2,18 +2,12 @@ ...@@ -2,18 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/plugin_data_remover.h" #include "base/base_paths.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/synchronization/waitable_event_watcher.h" #include "base/synchronization/waitable_event_watcher.h"
#include "chrome/browser/ui/browser.h" #include "content/browser/plugin_data_remover_impl.h"
#include "chrome/browser/browser_process.h" #include "content/public/common/content_switches.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
...@@ -33,7 +27,7 @@ class PluginDataRemoverTest : public InProcessBrowserTest, ...@@ -33,7 +27,7 @@ class PluginDataRemoverTest : public InProcessBrowserTest,
virtual void SetUpCommandLine(CommandLine* command_line) { virtual void SetUpCommandLine(CommandLine* command_line) {
#ifdef OS_MACOSX #ifdef OS_MACOSX
FilePath browser_directory; FilePath browser_directory;
PathService::Get(chrome::DIR_APP, &browser_directory); PathService::Get(base::DIR_MODULE, &browser_directory);
command_line->AppendSwitchPath(switches::kExtraPluginDir, command_line->AppendSwitchPath(switches::kExtraPluginDir,
browser_directory.AppendASCII("plugins")); browser_directory.AppendASCII("plugins"));
#endif #endif
...@@ -41,12 +35,11 @@ class PluginDataRemoverTest : public InProcessBrowserTest, ...@@ -41,12 +35,11 @@ class PluginDataRemoverTest : public InProcessBrowserTest,
}; };
IN_PROC_BROWSER_TEST_F(PluginDataRemoverTest, RemoveData) { IN_PROC_BROWSER_TEST_F(PluginDataRemoverTest, RemoveData) {
scoped_refptr<PluginDataRemover> plugin_data_remover( PluginDataRemoverImpl plugin_data_remover(GetResourceContext());
new PluginDataRemover(browser()->profile())); plugin_data_remover.set_mime_type(kNPAPITestPluginMimeType);
plugin_data_remover->set_mime_type(kNPAPITestPluginMimeType);
base::WaitableEventWatcher watcher; base::WaitableEventWatcher watcher;
base::WaitableEvent* event = base::WaitableEvent* event =
plugin_data_remover->StartRemoving(base::Time()); plugin_data_remover.StartRemoving(base::Time());
watcher.StartWatching(event, this); watcher.StartWatching(event, this);
ui_test_utils::RunMessageLoop(); ui_test_utils::RunMessageLoop();
} }
...@@ -25,6 +25,21 @@ ...@@ -25,6 +25,21 @@
'<(INTERMEDIATE_DIR)', '<(INTERMEDIATE_DIR)',
], ],
'sources': [ 'sources': [
'public/browser/browser_main_parts.h',
'public/browser/browser_thread.h',
'public/browser/content_browser_client.h',
'public/browser/download_manager_delegate.h',
'public/browser/native_web_keyboard_event.h',
'public/browser/navigation_types.h',
'public/browser/notification_details.h',
'public/browser/notification_observer.h',
'public/browser/notification_registrar.cc',
'public/browser/notification_registrar.h',
'public/browser/notification_service.h',
'public/browser/notification_source.h',
'public/browser/notification_types.h',
'public/browser/plugin_data_remover.h',
'public/browser/resource_dispatcher_host_delegate.h',
'browser/accessibility/browser_accessibility.cc', 'browser/accessibility/browser_accessibility.cc',
'browser/accessibility/browser_accessibility.h', 'browser/accessibility/browser_accessibility.h',
'browser/accessibility/browser_accessibility_cocoa.h', 'browser/accessibility/browser_accessibility_cocoa.h',
...@@ -283,6 +298,8 @@ ...@@ -283,6 +298,8 @@
'browser/net/url_request_slow_http_job.h', 'browser/net/url_request_slow_http_job.h',
'browser/notification_service_impl.cc', 'browser/notification_service_impl.cc',
'browser/notification_service_impl.h', 'browser/notification_service_impl.h',
'browser/plugin_data_remover_impl.cc',
'browser/plugin_data_remover_impl.h',
'browser/plugin_loader_posix.cc', 'browser/plugin_loader_posix.cc',
'browser/plugin_loader_posix.h', 'browser/plugin_loader_posix.h',
'browser/plugin_process_host.cc', 'browser/plugin_process_host.cc',
...@@ -584,20 +601,6 @@ ...@@ -584,20 +601,6 @@
'browser/zygote_host_linux.cc', 'browser/zygote_host_linux.cc',
'browser/zygote_host_linux.h', 'browser/zygote_host_linux.h',
'browser/zygote_main_linux.cc', 'browser/zygote_main_linux.cc',
'public/browser/browser_main_parts.h',
'public/browser/browser_thread.h',
'public/browser/content_browser_client.h',
'public/browser/download_manager_delegate.h',
'public/browser/native_web_keyboard_event.h',
'public/browser/navigation_types.h',
'public/browser/notification_details.h',
'public/browser/notification_observer.h',
'public/browser/notification_registrar.cc',
'public/browser/notification_registrar.h',
'public/browser/notification_service.h',
'public/browser/notification_source.h',
'public/browser/notification_types.h',
'public/browser/resource_dispatcher_host_delegate.h',
], ],
'conditions': [ 'conditions': [
['p2p_apis==1', { ['p2p_apis==1', {
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_BROWSER_PLUGIN_DATA_REMOVER_H_
#define CONTENT_PUBLIC_BROWSER_PLUGIN_DATA_REMOVER_H_
#pragma once
#include "base/time.h"
#include "content/common/content_export.h"
namespace base {
class WaitableEvent;
}
namespace content {
class ResourceContext;
}
namespace webkit {
struct WebPluginInfo;
}
namespace content {
class CONTENT_EXPORT PluginDataRemover {
public:
static PluginDataRemover* Create(
const content::ResourceContext& resource_context);
virtual ~PluginDataRemover() {}
// Starts removing plug-in data stored since |begin_time|.
virtual base::WaitableEvent* StartRemoving(base::Time begin_time) = 0;
// Returns whether there is a plug-in installed that supports removing LSO
// data. If it returns true |plugin| is also set to that plugin. This method
// will use cached plugin data. Call PluginService::GetPlugins() if the latest
// data is needed.
static bool IsSupported(webkit::WebPluginInfo* plugin);
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_PLUGIN_DATA_REMOVER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment