| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/plugin_data_remover_impl.h" | 5 #include "content/browser/plugin_data_remover_impl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 public IPC::Listener, | 62 public IPC::Listener, |
| 63 public base::RefCountedThreadSafe<Context, | 63 public base::RefCountedThreadSafe<Context, |
| 64 BrowserThread::DeleteOnIOThread> { | 64 BrowserThread::DeleteOnIOThread> { |
| 65 public: | 65 public: |
| 66 Context(base::Time begin_time, BrowserContext* browser_context) | 66 Context(base::Time begin_time, BrowserContext* browser_context) |
| 67 : event_(new base::WaitableEvent(true, false)), | 67 : event_(new base::WaitableEvent(true, false)), |
| 68 begin_time_(begin_time), | 68 begin_time_(begin_time), |
| 69 is_removing_(false), | 69 is_removing_(false), |
| 70 browser_context_path_(browser_context->GetPath()), | 70 browser_context_path_(browser_context->GetPath()), |
| 71 resource_context_(browser_context->GetResourceContext()) { | 71 resource_context_(browser_context->GetResourceContext()) { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void Init(const std::string& mime_type) { | 75 void Init(const std::string& mime_type) { |
| 76 BrowserThread::PostTask( | 76 BrowserThread::PostTask( |
| 77 BrowserThread::IO, | 77 BrowserThread::IO, |
| 78 FROM_HERE, | 78 FROM_HERE, |
| 79 base::Bind(&Context::InitOnIOThread, this, mime_type)); | 79 base::Bind(&Context::InitOnIOThread, this, mime_type)); |
| 80 BrowserThread::PostDelayedTask( | 80 BrowserThread::PostDelayedTask( |
| 81 BrowserThread::IO, | 81 BrowserThread::IO, |
| 82 FROM_HERE, | 82 FROM_HERE, |
| 83 base::Bind(&Context::OnTimeout, this), | 83 base::Bind(&Context::OnTimeout, this), |
| 84 base::TimeDelta::FromMilliseconds(kRemovalTimeoutMs)); | 84 base::TimeDelta::FromMilliseconds(kRemovalTimeoutMs)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void InitOnIOThread(const std::string& mime_type) { | 87 void InitOnIOThread(const std::string& mime_type) { |
| 88 PluginServiceImpl* plugin_service = PluginServiceImpl::GetInstance(); | 88 PluginServiceImpl* plugin_service = PluginServiceImpl::GetInstance(); |
| 89 | 89 |
| 90 // Get the plugin file path. | 90 // Get the plugin file path. |
| 91 std::vector<WebPluginInfo> plugins; | 91 std::vector<WebPluginInfo> plugins; |
| 92 plugin_service->GetPluginInfoArray( | 92 plugin_service->GetPluginInfoArray( |
| 93 GURL(), mime_type, false, &plugins, NULL); | 93 GURL(), mime_type, false, &plugins, NULL); |
| 94 base::FilePath plugin_path; | 94 base::FilePath plugin_path; |
| 95 if (!plugins.empty()) // May be empty for some tests. | 95 if (!plugins.empty()) // May be empty for some tests. |
| 96 plugin_path = plugins[0].path; | 96 plugin_path = plugins[0].path; |
| 97 | 97 |
| 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 99 remove_start_time_ = base::Time::Now(); | 99 remove_start_time_ = base::Time::Now(); |
| 100 is_removing_ = true; | 100 is_removing_ = true; |
| 101 // Balanced in On[Ppapi]ChannelOpened or OnError. Exactly one them will | 101 // Balanced in On[Ppapi]ChannelOpened or OnError. Exactly one them will |
| 102 // eventually be called, so we need to keep this object around until then. | 102 // eventually be called, so we need to keep this object around until then. |
| 103 AddRef(); | 103 AddRef(); |
| 104 | 104 |
| 105 PepperPluginInfo* pepper_info = | 105 PepperPluginInfo* pepper_info = |
| 106 plugin_service->GetRegisteredPpapiPluginInfo(plugin_path); | 106 plugin_service->GetRegisteredPpapiPluginInfo(plugin_path); |
| 107 if (pepper_info) { | 107 if (pepper_info) { |
| 108 plugin_name_ = pepper_info->name; | 108 plugin_name_ = pepper_info->name; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 #else | 207 #else |
| 208 base::FilePath plugin_data_path = | 208 base::FilePath plugin_data_path = |
| 209 profile_path.Append(base::FilePath(plugin_name_)); | 209 profile_path.Append(base::FilePath(plugin_name_)); |
| 210 #endif // defined(OS_WIN) | 210 #endif // defined(OS_WIN) |
| 211 return new PpapiMsg_ClearSiteData(0u, plugin_data_path, std::string(), | 211 return new PpapiMsg_ClearSiteData(0u, plugin_data_path, std::string(), |
| 212 kClearAllData, max_age); | 212 kClearAllData, max_age); |
| 213 } | 213 } |
| 214 | 214 |
| 215 // Connects the client side of a newly opened plugin channel. | 215 // Connects the client side of a newly opened plugin channel. |
| 216 void ConnectToChannel(const IPC::ChannelHandle& handle, bool is_ppapi) { | 216 void ConnectToChannel(const IPC::ChannelHandle& handle, bool is_ppapi) { |
| 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 217 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 218 | 218 |
| 219 // If we timed out, don't bother connecting. | 219 // If we timed out, don't bother connecting. |
| 220 if (!is_removing_) | 220 if (!is_removing_) |
| 221 return; | 221 return; |
| 222 | 222 |
| 223 DCHECK(!channel_.get()); | 223 DCHECK(!channel_.get()); |
| 224 channel_ = IPC::Channel::CreateClient(handle, this); | 224 channel_ = IPC::Channel::CreateClient(handle, this); |
| 225 if (!channel_->Connect()) { | 225 if (!channel_->Connect()) { |
| 226 NOTREACHED() << "Couldn't connect to plugin"; | 226 NOTREACHED() << "Couldn't connect to plugin"; |
| 227 SignalDone(); | 227 SignalDone(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 257 void OnClearSiteDataResult(bool success) { | 257 void OnClearSiteDataResult(bool success) { |
| 258 LOG_IF(ERROR, !success) << "ClearSiteData returned error"; | 258 LOG_IF(ERROR, !success) << "ClearSiteData returned error"; |
| 259 UMA_HISTOGRAM_TIMES("ClearPluginData.time", | 259 UMA_HISTOGRAM_TIMES("ClearPluginData.time", |
| 260 base::Time::Now() - remove_start_time_); | 260 base::Time::Now() - remove_start_time_); |
| 261 SignalDone(); | 261 SignalDone(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // Signals that we are finished with removing data (successful or not). This | 264 // Signals that we are finished with removing data (successful or not). This |
| 265 // method is safe to call multiple times. | 265 // method is safe to call multiple times. |
| 266 void SignalDone() { | 266 void SignalDone() { |
| 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 267 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 268 if (!is_removing_) | 268 if (!is_removing_) |
| 269 return; | 269 return; |
| 270 is_removing_ = false; | 270 is_removing_ = false; |
| 271 event_->Signal(); | 271 event_->Signal(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 scoped_ptr<base::WaitableEvent> event_; | 274 scoped_ptr<base::WaitableEvent> event_; |
| 275 // The point in time when we start removing data. | 275 // The point in time when we start removing data. |
| 276 base::Time remove_start_time_; | 276 base::Time remove_start_time_; |
| 277 // The point in time from which on we remove data. | 277 // The point in time from which on we remove data. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 304 | 304 |
| 305 base::WaitableEvent* PluginDataRemoverImpl::StartRemoving( | 305 base::WaitableEvent* PluginDataRemoverImpl::StartRemoving( |
| 306 base::Time begin_time) { | 306 base::Time begin_time) { |
| 307 DCHECK(!context_.get()); | 307 DCHECK(!context_.get()); |
| 308 context_ = new Context(begin_time, browser_context_); | 308 context_ = new Context(begin_time, browser_context_); |
| 309 context_->Init(mime_type_); | 309 context_->Init(mime_type_); |
| 310 return context_->event(); | 310 return context_->event(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 } // namespace content | 313 } // namespace content |
| OLD | NEW |