| 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 #ifndef CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ | 5 #ifndef CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ |
| 6 #define CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ | 6 #define CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "content/browser/plugin_process_host.h" | 11 #include "content/browser/plugin_process_host.h" |
| 12 | 12 |
| 13 class Profile; |
| 13 class Task; | 14 class Task; |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class MessageLoopProxy; | 17 class MessageLoopProxy; |
| 17 class WaitableEvent; | 18 class WaitableEvent; |
| 18 } | 19 } |
| 19 | 20 |
| 20 class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>, | 21 class PluginDataRemover : public base::RefCountedThreadSafe<PluginDataRemover>, |
| 21 public PluginProcessHost::Client, | 22 public PluginProcessHost::Client, |
| 22 public IPC::Channel::Listener { | 23 public IPC::Channel::Listener { |
| 23 public: | 24 public: |
| 24 PluginDataRemover(); | 25 explicit PluginDataRemover(Profile* profile); |
| 25 | 26 |
| 26 // The plug-in whose data should be removed (usually Flash) is specified via | 27 // The plug-in whose data should be removed (usually Flash) is specified via |
| 27 // its MIME type. This method sets a different MIME type in order to call a | 28 // its MIME type. This method sets a different MIME type in order to call a |
| 28 // different plug-in (for example in tests). | 29 // different plug-in (for example in tests). |
| 29 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } | 30 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } |
| 30 | 31 |
| 31 // Starts removing plug-in data stored since |begin_time|. | 32 // Starts removing plug-in data stored since |begin_time|. |
| 32 base::WaitableEvent* StartRemoving(base::Time begin_time); | 33 base::WaitableEvent* StartRemoving(base::Time begin_time); |
| 33 | 34 |
| 34 // Returns whether there is a plug-in installed that supports removing | 35 // Returns whether there is a plug-in installed that supports removing |
| 35 // LSO data. Because this method possibly has to load the plug-in list, it | 36 // LSO data. Because this method possibly has to load the plug-in list, it |
| 36 // should only be called on the FILE thread. | 37 // should only be called on the FILE thread. |
| 37 static bool IsSupported(); | 38 static bool IsSupported(); |
| 38 | 39 |
| 39 // Indicates whether we are still in the process of removing plug-in data. | 40 // Indicates whether we are still in the process of removing plug-in data. |
| 40 bool is_removing() const { return is_removing_; } | 41 bool is_removing() const { return is_removing_; } |
| 41 | 42 |
| 42 // Wait until removing has finished. When the browser is still running (i.e. | 43 // Wait until removing has finished. When the browser is still running (i.e. |
| 43 // not during shutdown), you should use a WaitableEventWatcher in combination | 44 // not during shutdown), you should use a WaitableEventWatcher in combination |
| 44 // with the WaitableEvent returned by StartRemoving. | 45 // with the WaitableEvent returned by StartRemoving. |
| 45 void Wait(); | 46 void Wait(); |
| 46 | 47 |
| 47 // PluginProcessHost::Client methods. | 48 // PluginProcessHost::Client methods. |
| 48 virtual int ID(); | 49 virtual int ID(); |
| 49 virtual bool OffTheRecord(); | 50 virtual bool OffTheRecord(); |
| 51 virtual const content::ResourceContext* GetResourceContext(); |
| 50 virtual void SetPluginInfo(const webkit::npapi::WebPluginInfo& info); | 52 virtual void SetPluginInfo(const webkit::npapi::WebPluginInfo& info); |
| 51 virtual void OnChannelOpened(const IPC::ChannelHandle& handle); | 53 virtual void OnChannelOpened(const IPC::ChannelHandle& handle); |
| 52 virtual void OnError(); | 54 virtual void OnError(); |
| 53 | 55 |
| 54 // IPC::Channel::Listener methods. | 56 // IPC::Channel::Listener methods. |
| 55 virtual bool OnMessageReceived(const IPC::Message& message); | 57 virtual bool OnMessageReceived(const IPC::Message& message); |
| 56 virtual void OnChannelError(); | 58 virtual void OnChannelError(); |
| 57 | 59 |
| 58 private: | 60 private: |
| 59 friend class base::RefCountedThreadSafe<PluginDataRemover>; | 61 friend class base::RefCountedThreadSafe<PluginDataRemover>; |
| 60 friend class PluginDataRemoverTest; | 62 friend class PluginDataRemoverTest; |
| 61 virtual ~PluginDataRemover(); | 63 virtual ~PluginDataRemover(); |
| 62 | 64 |
| 63 // Signals that we are finished with removing data (successful or not). This | 65 // Signals that we are finished with removing data (successful or not). This |
| 64 // method is safe to call multiple times. | 66 // method is safe to call multiple times. |
| 65 void SignalDone(); | 67 void SignalDone(); |
| 68 // Starts opening a new channel to the plug-in. |
| 69 void OpenChannel(); |
| 66 // Connects the client side of a newly opened plug-in channel. | 70 // Connects the client side of a newly opened plug-in channel. |
| 67 void ConnectToChannel(const IPC::ChannelHandle& handle); | 71 void ConnectToChannel(const IPC::ChannelHandle& handle); |
| 68 // Handles the PluginHostMsg_ClearSiteDataResult message. | 72 // Handles the PluginHostMsg_ClearSiteDataResult message. |
| 69 void OnClearSiteDataResult(bool success); | 73 void OnClearSiteDataResult(bool success); |
| 70 // Called when a timeout happens in order not to block the client | 74 // Called when a timeout happens in order not to block the client |
| 71 // indefinitely. | 75 // indefinitely. |
| 72 void OnTimeout(); | 76 void OnTimeout(); |
| 73 | 77 |
| 74 std::string mime_type_; | 78 std::string mime_type_; |
| 75 bool is_removing_; | 79 bool is_removing_; |
| 76 // The point in time when we start removing data. | 80 // The point in time when we start removing data. |
| 77 base::Time remove_start_time_; | 81 base::Time remove_start_time_; |
| 78 // The point in time from which on we remove data. | 82 // The point in time from which on we remove data. |
| 79 base::Time begin_time_; | 83 base::Time begin_time_; |
| 84 // The resource context for the profile. |
| 85 const content::ResourceContext& context_; |
| 80 scoped_ptr<base::WaitableEvent> event_; | 86 scoped_ptr<base::WaitableEvent> event_; |
| 81 // We own the channel, but it's used on the IO thread, so it needs to be | 87 // We own the channel, but it's used on the IO thread, so it needs to be |
| 82 // deleted there. It's NULL until we have opened a connection to the plug-in | 88 // deleted there. It's NULL until we have opened a connection to the plug-in |
| 83 // process. | 89 // process. |
| 84 IPC::Channel* channel_; | 90 IPC::Channel* channel_; |
| 85 | 91 |
| 86 DISALLOW_COPY_AND_ASSIGN(PluginDataRemover); | 92 DISALLOW_COPY_AND_ASSIGN(PluginDataRemover); |
| 87 }; | 93 }; |
| 88 | 94 |
| 89 #endif // CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ | 95 #endif // CHROME_BROWSER_PLUGIN_DATA_REMOVER_H_ |
| OLD | NEW |