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