plugin_data_remover.h revision dc0f95d653279beabeb9817299e2902918ba123e
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ 6#define CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ 7#pragma once 8 9#include "base/ref_counted.h" 10#include "base/time.h" 11#include "content/browser/plugin_process_host.h" 12 13class Task; 14 15namespace base { 16class MessageLoopProxy; 17class WaitableEvent; 18} 19 20class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>, 21 public PluginProcessHost::Client, 22 public IPC::Channel::Listener { 23 public: 24 PluginDataRemover(); 25 26 // Used in tests to call a different plugin. 27 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } 28 29 // Starts removing plug-in data stored since |begin_time|. 30 base::WaitableEvent* StartRemoving(const base::Time& begin_time); 31 32 // Returns whether there is a plug-in installed that supports removing 33 // LSO data. Because this method possibly has to load the plug-in list, it 34 // should only be called on the FILE thread. 35 static bool IsSupported(); 36 37 bool is_removing() const { return is_removing_; } 38 39 // Wait until removing has finished. When the browser is still running (i.e. 40 // not during shutdown), you should use a WaitableEventWatcher in combination 41 // with the WaitableEvent returned by StartRemoving. 42 void Wait(); 43 44 // PluginProcessHost::Client methods 45 virtual int ID(); 46 virtual bool OffTheRecord(); 47 virtual void SetPluginInfo(const webkit::npapi::WebPluginInfo& info); 48 virtual void OnChannelOpened(const IPC::ChannelHandle& handle); 49 virtual void OnError(); 50 51 // IPC::Channel::Listener methods 52 virtual bool OnMessageReceived(const IPC::Message& message); 53 virtual void OnChannelError(); 54 55 private: 56 friend class base::RefCountedThreadSafe<PluginDataRemover>; 57 friend class PluginDataRemoverTest; 58 ~PluginDataRemover(); 59 60 void SignalDone(); 61 void ConnectToChannel(const IPC::ChannelHandle& handle); 62 void OnClearSiteDataResult(bool success); 63 void OnTimeout(); 64 65 std::string mime_type_; 66 bool is_removing_; 67 // The point in time when we start removing data. 68 base::Time remove_start_time_; 69 // The point in time from which on we remove data. 70 base::Time begin_time_; 71 scoped_ptr<base::WaitableEvent> event_; 72 // We own the channel, but it's used on the IO thread, so it needs to be 73 // deleted there as well. 74 IPC::Channel* channel_; 75}; 76 77#endif // CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ 78