| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/plugin_data_remover.h" | 5 #include "chrome/browser/plugin_data_remover.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/version.h" | 11 #include "base/version.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 13 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
| 14 #include "content/browser/plugin_service.h" | 15 #include "content/browser/plugin_service.h" |
| 15 #include "content/common/plugin_messages.h" | 16 #include "content/common/plugin_messages.h" |
| 16 #include "webkit/plugins/npapi/plugin_group.h" | 17 #include "webkit/plugins/npapi/plugin_group.h" |
| 17 #include "webkit/plugins/npapi/plugin_list.h" | 18 #include "webkit/plugins/npapi/plugin_list.h" |
| 18 | 19 |
| 19 #if defined(OS_POSIX) | 20 #if defined(OS_POSIX) |
| 20 #include "ipc/ipc_channel_posix.h" | 21 #include "ipc/ipc_channel_posix.h" |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const char* kFlashMimeType = "application/x-shockwave-flash"; | 26 const char* kFlashMimeType = "application/x-shockwave-flash"; |
| 26 // The minimum Flash Player version that implements NPP_ClearSiteData. | 27 // The minimum Flash Player version that implements NPP_ClearSiteData. |
| 27 const char* kMinFlashVersion = "10.3"; | 28 const char* kMinFlashVersion = "10.3"; |
| 28 const int64 kRemovalTimeoutMs = 10000; | 29 const int64 kRemovalTimeoutMs = 10000; |
| 29 const uint64 kClearAllData = 0; | 30 const uint64 kClearAllData = 0; |
| 30 | 31 |
| 31 } // namespace | 32 } // namespace |
| 32 | 33 |
| 33 PluginDataRemover::PluginDataRemover() | 34 PluginDataRemover::PluginDataRemover(Profile* profile) |
| 34 : mime_type_(kFlashMimeType), | 35 : mime_type_(kFlashMimeType), |
| 35 is_removing_(false), | 36 is_removing_(false), |
| 37 context_(profile->GetResourceContext()), |
| 36 event_(new base::WaitableEvent(true, false)), | 38 event_(new base::WaitableEvent(true, false)), |
| 37 channel_(NULL) { | 39 channel_(NULL) { |
| 38 } | 40 } |
| 39 | 41 |
| 40 PluginDataRemover::~PluginDataRemover() { | 42 PluginDataRemover::~PluginDataRemover() { |
| 41 DCHECK(!is_removing_); | 43 DCHECK(!is_removing_); |
| 42 if (channel_) | 44 if (channel_) |
| 43 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); | 45 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); |
| 44 } | 46 } |
| 45 | 47 |
| 46 base::WaitableEvent* PluginDataRemover::StartRemoving(base::Time begin_time) { | 48 base::WaitableEvent* PluginDataRemover::StartRemoving(base::Time begin_time) { |
| 47 DCHECK(!is_removing_); | 49 DCHECK(!is_removing_); |
| 48 remove_start_time_ = base::Time::Now(); | 50 remove_start_time_ = base::Time::Now(); |
| 49 begin_time_ = begin_time; | 51 begin_time_ = begin_time; |
| 50 | 52 |
| 51 is_removing_ = true; | 53 is_removing_ = true; |
| 52 | 54 |
| 53 // Balanced in OnChannelOpened or OnError. Exactly one them will eventually be | 55 BrowserThread::PostTask( |
| 54 // called, so we need to keep this object around until then. | 56 BrowserThread::IO, |
| 55 AddRef(); | 57 FROM_HERE, |
| 56 PluginService::GetInstance()->OpenChannelToNpapiPlugin( | 58 NewRunnableMethod(this, &PluginDataRemover::OpenChannel)); |
| 57 0, 0, GURL(), mime_type_, this); | |
| 58 | 59 |
| 59 BrowserThread::PostDelayedTask( | 60 BrowserThread::PostDelayedTask( |
| 60 BrowserThread::IO, | 61 BrowserThread::IO, |
| 61 FROM_HERE, | 62 FROM_HERE, |
| 62 NewRunnableMethod(this, &PluginDataRemover::OnTimeout), | 63 NewRunnableMethod(this, &PluginDataRemover::OnTimeout), |
| 63 kRemovalTimeoutMs); | 64 kRemovalTimeoutMs); |
| 64 | 65 |
| 65 return event_.get(); | 66 return event_.get(); |
| 66 } | 67 } |
| 67 | 68 |
| 69 void PluginDataRemover::OpenChannel() { |
| 70 // Balanced in OnChannelOpened or OnError. Exactly one them will eventually be |
| 71 // called, so we need to keep this object around until then. |
| 72 AddRef(); |
| 73 PluginService::GetInstance()->OpenChannelToNpapiPlugin( |
| 74 0, 0, GURL(), GURL(), mime_type_, this); |
| 75 } |
| 76 |
| 68 void PluginDataRemover::Wait() { | 77 void PluginDataRemover::Wait() { |
| 69 base::Time start_time(base::Time::Now()); | 78 base::Time start_time(base::Time::Now()); |
| 70 bool result = true; | 79 bool result = true; |
| 71 if (is_removing_) | 80 if (is_removing_) |
| 72 result = event_->Wait(); | 81 result = event_->Wait(); |
| 73 UMA_HISTOGRAM_TIMES("ClearPluginData.wait_at_shutdown", | 82 UMA_HISTOGRAM_TIMES("ClearPluginData.wait_at_shutdown", |
| 74 base::Time::Now() - start_time); | 83 base::Time::Now() - start_time); |
| 75 UMA_HISTOGRAM_TIMES("ClearPluginData.time_at_shutdown", | 84 UMA_HISTOGRAM_TIMES("ClearPluginData.time_at_shutdown", |
| 76 base::Time::Now() - remove_start_time_); | 85 base::Time::Now() - remove_start_time_); |
| 77 DCHECK(result) << "Error waiting for plugin process"; | 86 DCHECK(result) << "Error waiting for plugin process"; |
| 78 } | 87 } |
| 79 | 88 |
| 80 int PluginDataRemover::ID() { | 89 int PluginDataRemover::ID() { |
| 81 // Generate a unique identifier for this PluginProcessHostClient. | 90 // Generate a unique identifier for this PluginProcessHostClient. |
| 82 return ChildProcessInfo::GenerateChildProcessUniqueId(); | 91 return ChildProcessInfo::GenerateChildProcessUniqueId(); |
| 83 } | 92 } |
| 84 | 93 |
| 85 bool PluginDataRemover::OffTheRecord() { | 94 bool PluginDataRemover::OffTheRecord() { |
| 86 return false; | 95 return false; |
| 87 } | 96 } |
| 88 | 97 |
| 98 const content::ResourceContext* PluginDataRemover::GetResourceContext() { |
| 99 return &context_; |
| 100 } |
| 101 |
| 89 void PluginDataRemover::SetPluginInfo( | 102 void PluginDataRemover::SetPluginInfo( |
| 90 const webkit::npapi::WebPluginInfo& info) { | 103 const webkit::npapi::WebPluginInfo& info) { |
| 91 } | 104 } |
| 92 | 105 |
| 93 void PluginDataRemover::OnChannelOpened(const IPC::ChannelHandle& handle) { | 106 void PluginDataRemover::OnChannelOpened(const IPC::ChannelHandle& handle) { |
| 94 ConnectToChannel(handle); | 107 ConnectToChannel(handle); |
| 95 // Balancing the AddRef call in StartRemoving. | 108 // Balancing the AddRef call in StartRemoving. |
| 96 Release(); | 109 Release(); |
| 97 } | 110 } |
| 98 | 111 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 webkit::npapi::PluginGroup::CreateVersionFromString(plugin->version)); | 191 webkit::npapi::PluginGroup::CreateVersionFromString(plugin->version)); |
| 179 scoped_ptr<Version> min_version(Version::GetVersionFromString( | 192 scoped_ptr<Version> min_version(Version::GetVersionFromString( |
| 180 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 193 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 181 switches::kMinClearSiteDataFlashVersion))); | 194 switches::kMinClearSiteDataFlashVersion))); |
| 182 if (!min_version.get()) | 195 if (!min_version.get()) |
| 183 min_version.reset(Version::GetVersionFromString(kMinFlashVersion)); | 196 min_version.reset(Version::GetVersionFromString(kMinFlashVersion)); |
| 184 return webkit::npapi::IsPluginEnabled(*plugin) && | 197 return webkit::npapi::IsPluginEnabled(*plugin) && |
| 185 version.get() && | 198 version.get() && |
| 186 min_version->CompareTo(*version) == -1; | 199 min_version->CompareTo(*version) == -1; |
| 187 } | 200 } |
| OLD | NEW |