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 "content/browser/plugin_data_remover_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | |
9 #include "base/message_loop_proxy.h" | |
10 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
11 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
12 #include "base/version.h" | 10 #include "base/version.h" |
13 #include "chrome/browser/plugin_prefs.h" | |
14 #include "chrome/browser/profiles/profile.h" | |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "content/browser/plugin_service.h" | 11 #include "content/browser/plugin_service.h" |
17 #include "content/common/plugin_messages.h" | 12 #include "content/common/plugin_messages.h" |
18 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
19 #include "webkit/plugins/npapi/plugin_group.h" | 14 #include "webkit/plugins/npapi/plugin_group.h" |
20 | 15 |
21 #if defined(OS_POSIX) | |
22 #include "ipc/ipc_channel_posix.h" | |
23 #endif | |
24 | |
25 using content::BrowserThread; | 16 using content::BrowserThread; |
26 | 17 |
27 namespace { | 18 namespace { |
28 | 19 |
29 const char kFlashMimeType[] = "application/x-shockwave-flash"; | 20 const char kFlashMimeType[] = "application/x-shockwave-flash"; |
30 // The minimum Flash Player version that implements NPP_ClearSiteData. | 21 // The minimum Flash Player version that implements NPP_ClearSiteData. |
31 const char kMinFlashVersion[] = "10.3"; | 22 const char kMinFlashVersion[] = "10.3"; |
32 const int64 kRemovalTimeoutMs = 10000; | 23 const int64 kRemovalTimeoutMs = 10000; |
33 const uint64 kClearAllData = 0; | 24 const uint64 kClearAllData = 0; |
34 | 25 |
35 } // namespace | 26 } // namespace |
36 | 27 |
37 PluginDataRemover::PluginDataRemover(Profile* profile) | 28 namespace content { |
38 : mime_type_(kFlashMimeType), | 29 |
39 is_removing_(false), | 30 //static |
Bernhard Bauer
2011/11/17 10:41:10
Nit: Space after //
jam
2011/11/17 16:49:51
Done.
| |
40 context_(profile->GetResourceContext()), | 31 PluginDataRemover* PluginDataRemover::Create( |
41 event_(new base::WaitableEvent(true, false)), | 32 const content::ResourceContext& resource_context) { |
42 channel_(NULL) { | 33 return new PluginDataRemoverImpl(resource_context); |
43 } | 34 } |
44 | 35 |
45 PluginDataRemover::~PluginDataRemover() { | 36 // static |
37 bool PluginDataRemover::IsSupported(webkit::WebPluginInfo* plugin) { | |
38 bool allow_wildcard = false; | |
39 std::vector<webkit::WebPluginInfo> plugins; | |
40 PluginService::GetInstance()->GetPluginInfoArray( | |
41 GURL(), kFlashMimeType, allow_wildcard, &plugins, NULL); | |
42 std::vector<webkit::WebPluginInfo>::iterator plugin_it = plugins.begin(); | |
43 if (plugin_it == plugins.end()) | |
44 return false; | |
45 scoped_ptr<Version> version( | |
46 webkit::npapi::PluginGroup::CreateVersionFromString(plugin_it->version)); | |
47 scoped_ptr<Version> min_version( | |
48 Version::GetVersionFromString(kMinFlashVersion)); | |
49 bool rv = version.get() && min_version->CompareTo(*version) == -1; | |
50 if (rv) | |
51 *plugin = *plugin_it; | |
52 return rv; | |
53 } | |
54 | |
55 } | |
56 | |
57 PluginDataRemoverImpl::PluginDataRemoverImpl( | |
58 const content::ResourceContext& resource_context) | |
59 : mime_type_(kFlashMimeType), | |
60 is_starting_process_(false), | |
61 is_removing_(false), | |
62 context_(resource_context), | |
63 event_(new base::WaitableEvent(true, false)), | |
64 channel_(NULL), | |
65 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | |
66 } | |
67 | |
68 PluginDataRemoverImpl::~PluginDataRemoverImpl() { | |
69 if (is_starting_process_) | |
70 PluginService::GetInstance()->CancelOpenChannelToNpapiPlugin(this); | |
46 DCHECK(!is_removing_); | 71 DCHECK(!is_removing_); |
47 if (channel_) | 72 if (channel_) |
48 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); | 73 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); |
49 } | 74 } |
50 | 75 |
51 base::WaitableEvent* PluginDataRemover::StartRemoving(base::Time begin_time) { | 76 base::WaitableEvent* PluginDataRemoverImpl::StartRemoving( |
77 base::Time begin_time) { | |
52 DCHECK(!is_removing_); | 78 DCHECK(!is_removing_); |
53 remove_start_time_ = base::Time::Now(); | 79 remove_start_time_ = base::Time::Now(); |
54 begin_time_ = begin_time; | 80 begin_time_ = begin_time; |
55 | 81 |
82 is_starting_process_ = true; | |
56 is_removing_ = true; | 83 is_removing_ = true; |
57 | |
58 // Balanced in OnChannelOpened or OnError. Exactly one them will eventually be | |
59 // called, so we need to keep this object around until then. | |
60 AddRef(); | |
61 PluginService::GetInstance()->OpenChannelToNpapiPlugin( | 84 PluginService::GetInstance()->OpenChannelToNpapiPlugin( |
62 0, 0, GURL(), GURL(), mime_type_, this); | 85 0, 0, GURL(), GURL(), mime_type_, this); |
63 | 86 |
64 BrowserThread::PostDelayedTask( | 87 BrowserThread::PostDelayedTask( |
65 BrowserThread::IO, | 88 BrowserThread::IO, |
66 FROM_HERE, | 89 FROM_HERE, |
67 base::Bind(&PluginDataRemover::OnTimeout, this), | 90 base::Bind(&PluginDataRemoverImpl::OnTimeout, weak_factory_.GetWeakPtr()), |
68 kRemovalTimeoutMs); | 91 kRemovalTimeoutMs); |
69 | 92 |
70 return event_.get(); | 93 return event_.get(); |
71 } | 94 } |
72 | 95 |
73 void PluginDataRemover::Wait() { | 96 void PluginDataRemoverImpl::Wait() { |
Bernhard Bauer
2011/11/17 10:41:10
This method is not used anymore (it was used to wa
jam
2011/11/17 16:49:51
Done.
| |
74 base::Time start_time(base::Time::Now()); | 97 base::Time start_time(base::Time::Now()); |
75 if (is_removing_) | 98 if (is_removing_) |
76 event_->Wait(); | 99 event_->Wait(); |
77 UMA_HISTOGRAM_TIMES("ClearPluginData.wait_at_shutdown", | 100 UMA_HISTOGRAM_TIMES("ClearPluginData.wait_at_shutdown", |
78 base::Time::Now() - start_time); | 101 base::Time::Now() - start_time); |
79 UMA_HISTOGRAM_TIMES("ClearPluginData.time_at_shutdown", | 102 UMA_HISTOGRAM_TIMES("ClearPluginData.time_at_shutdown", |
80 base::Time::Now() - remove_start_time_); | 103 base::Time::Now() - remove_start_time_); |
81 } | 104 } |
82 | 105 |
83 int PluginDataRemover::ID() { | 106 int PluginDataRemoverImpl::ID() { |
84 // Generate a unique identifier for this PluginProcessHostClient. | 107 // Generate a unique identifier for this PluginProcessHostClient. |
85 return ChildProcessInfo::GenerateChildProcessUniqueId(); | 108 return ChildProcessInfo::GenerateChildProcessUniqueId(); |
86 } | 109 } |
87 | 110 |
88 bool PluginDataRemover::OffTheRecord() { | 111 bool PluginDataRemoverImpl::OffTheRecord() { |
89 return false; | 112 return false; |
90 } | 113 } |
91 | 114 |
92 const content::ResourceContext& PluginDataRemover::GetResourceContext() { | 115 const content::ResourceContext& PluginDataRemoverImpl::GetResourceContext() { |
93 return context_; | 116 return context_; |
94 } | 117 } |
95 | 118 |
96 void PluginDataRemover::SetPluginInfo( | 119 void PluginDataRemoverImpl::SetPluginInfo( |
97 const webkit::WebPluginInfo& info) { | 120 const webkit::WebPluginInfo& info) { |
98 } | 121 } |
99 | 122 |
100 void PluginDataRemover::OnFoundPluginProcessHost( | 123 void PluginDataRemoverImpl::OnFoundPluginProcessHost( |
101 PluginProcessHost* host) { | 124 PluginProcessHost* host) { |
102 } | 125 } |
103 | 126 |
104 void PluginDataRemover::OnSentPluginChannelRequest() { | 127 void PluginDataRemoverImpl::OnSentPluginChannelRequest() { |
105 } | 128 } |
106 | 129 |
107 void PluginDataRemover::OnChannelOpened(const IPC::ChannelHandle& handle) { | 130 void PluginDataRemoverImpl::OnChannelOpened(const IPC::ChannelHandle& handle) { |
131 is_starting_process_ = false; | |
108 ConnectToChannel(handle); | 132 ConnectToChannel(handle); |
109 // Balancing the AddRef call in StartRemoving. | |
110 Release(); | |
111 } | 133 } |
112 | 134 |
113 void PluginDataRemover::ConnectToChannel(const IPC::ChannelHandle& handle) { | 135 void PluginDataRemoverImpl::ConnectToChannel(const IPC::ChannelHandle& handle) { |
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
115 | 137 |
116 // If we timed out, don't bother connecting. | 138 // If we timed out, don't bother connecting. |
117 if (!is_removing_) | 139 if (!is_removing_) |
118 return; | 140 return; |
119 | 141 |
120 DCHECK(!channel_); | 142 DCHECK(!channel_); |
121 channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this); | 143 channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this); |
122 if (!channel_->Connect()) { | 144 if (!channel_->Connect()) { |
123 NOTREACHED() << "Couldn't connect to plugin"; | 145 NOTREACHED() << "Couldn't connect to plugin"; |
124 SignalDone(); | 146 SignalDone(); |
125 return; | 147 return; |
126 } | 148 } |
127 | 149 |
128 if (!channel_->Send(new PluginMsg_ClearSiteData(std::string(), | 150 if (!channel_->Send(new PluginMsg_ClearSiteData(std::string(), |
129 kClearAllData, | 151 kClearAllData, |
130 begin_time_))) { | 152 begin_time_))) { |
131 NOTREACHED() << "Couldn't send ClearSiteData message"; | 153 NOTREACHED() << "Couldn't send ClearSiteData message"; |
132 SignalDone(); | 154 SignalDone(); |
133 return; | 155 return; |
134 } | 156 } |
135 } | 157 } |
136 | 158 |
137 void PluginDataRemover::OnError() { | 159 void PluginDataRemoverImpl::OnError() { |
138 LOG(DFATAL) << "Couldn't open plugin channel"; | 160 LOG(DFATAL) << "Couldn't open plugin channel"; |
139 SignalDone(); | 161 SignalDone(); |
140 // Balancing the AddRef call in StartRemoving. | |
141 Release(); | |
142 } | 162 } |
143 | 163 |
144 void PluginDataRemover::OnClearSiteDataResult(bool success) { | 164 void PluginDataRemoverImpl::OnClearSiteDataResult(bool success) { |
145 LOG_IF(ERROR, !success) << "ClearSiteData returned error"; | 165 LOG_IF(ERROR, !success) << "ClearSiteData returned error"; |
146 UMA_HISTOGRAM_TIMES("ClearPluginData.time", | 166 UMA_HISTOGRAM_TIMES("ClearPluginData.time", |
147 base::Time::Now() - remove_start_time_); | 167 base::Time::Now() - remove_start_time_); |
148 SignalDone(); | 168 SignalDone(); |
149 } | 169 } |
150 | 170 |
151 void PluginDataRemover::OnTimeout() { | 171 void PluginDataRemoverImpl::OnTimeout() { |
152 LOG_IF(ERROR, is_removing_) << "Timed out"; | 172 LOG_IF(ERROR, is_removing_) << "Timed out"; |
153 SignalDone(); | 173 SignalDone(); |
154 } | 174 } |
155 | 175 |
156 bool PluginDataRemover::OnMessageReceived(const IPC::Message& msg) { | 176 bool PluginDataRemoverImpl::OnMessageReceived(const IPC::Message& msg) { |
157 IPC_BEGIN_MESSAGE_MAP(PluginDataRemover, msg) | 177 IPC_BEGIN_MESSAGE_MAP(PluginDataRemoverImpl, msg) |
158 IPC_MESSAGE_HANDLER(PluginHostMsg_ClearSiteDataResult, | 178 IPC_MESSAGE_HANDLER(PluginHostMsg_ClearSiteDataResult, |
159 OnClearSiteDataResult) | 179 OnClearSiteDataResult) |
160 IPC_MESSAGE_UNHANDLED_ERROR() | 180 IPC_MESSAGE_UNHANDLED_ERROR() |
161 IPC_END_MESSAGE_MAP() | 181 IPC_END_MESSAGE_MAP() |
162 | 182 |
163 return true; | 183 return true; |
164 } | 184 } |
165 | 185 |
166 void PluginDataRemover::OnChannelError() { | 186 void PluginDataRemoverImpl::OnChannelError() { |
187 is_starting_process_ = false; | |
167 if (is_removing_) { | 188 if (is_removing_) { |
168 NOTREACHED() << "Channel error"; | 189 NOTREACHED() << "Channel error"; |
169 SignalDone(); | 190 SignalDone(); |
170 } | 191 } |
171 } | 192 } |
172 | 193 |
173 void PluginDataRemover::SignalDone() { | 194 void PluginDataRemoverImpl::SignalDone() { |
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
175 if (!is_removing_) | 196 if (!is_removing_) |
176 return; | 197 return; |
177 is_removing_ = false; | 198 is_removing_ = false; |
178 event_->Signal(); | 199 event_->Signal(); |
179 } | 200 } |
180 | |
181 // static | |
182 bool PluginDataRemover::IsSupported(PluginPrefs* plugin_prefs) { | |
183 bool allow_wildcard = false; | |
184 std::vector<webkit::WebPluginInfo> plugins; | |
185 PluginService::GetInstance()->GetPluginInfoArray( | |
186 GURL(), kFlashMimeType, allow_wildcard, &plugins, NULL); | |
187 std::vector<webkit::WebPluginInfo>::iterator plugin = plugins.begin(); | |
188 if (plugin == plugins.end()) | |
189 return false; | |
190 scoped_ptr<Version> version( | |
191 webkit::npapi::PluginGroup::CreateVersionFromString(plugin->version)); | |
192 scoped_ptr<Version> min_version(Version::GetVersionFromString( | |
193 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
194 switches::kMinClearSiteDataFlashVersion))); | |
195 if (!min_version.get()) | |
196 min_version.reset(Version::GetVersionFromString(kMinFlashVersion)); | |
197 return plugin_prefs->IsPluginEnabled(*plugin) && | |
198 version.get() && | |
199 min_version->CompareTo(*version) == -1; | |
200 } | |
OLD | NEW |