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 CONTENT_BROWSER_PLUGIN_DATA_REMOVER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_PLUGIN_DATA_REMOVER_IMPL_H_ |
6 #define CONTENT_BROWSER_PLUGIN_DATA_REMOVER_IMPL_H_ | 6 #define CONTENT_BROWSER_PLUGIN_DATA_REMOVER_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/weak_ptr.h" | |
13 #include "content/browser/plugin_process_host.h" | 12 #include "content/browser/plugin_process_host.h" |
14 #include "content/public/browser/plugin_data_remover.h" | 13 #include "content/public/browser/plugin_data_remover.h" |
15 | 14 |
16 class CONTENT_EXPORT PluginDataRemoverImpl | 15 class CONTENT_EXPORT PluginDataRemoverImpl : public content::PluginDataRemover { |
17 : public content::PluginDataRemover, | |
18 public NON_EXPORTED_BASE(PluginProcessHost::Client), | |
19 public IPC::Channel::Listener { | |
20 public: | 16 public: |
21 explicit PluginDataRemoverImpl( | 17 explicit PluginDataRemoverImpl( |
22 const content::ResourceContext& resource_context); | 18 const content::ResourceContext& resource_context); |
23 virtual ~PluginDataRemoverImpl(); | 19 virtual ~PluginDataRemoverImpl(); |
24 | 20 |
25 // content::PluginDataRemover implementation: | 21 // content::PluginDataRemover implementation: |
26 virtual base::WaitableEvent* StartRemoving(base::Time begin_time) OVERRIDE; | 22 virtual base::WaitableEvent* StartRemoving(base::Time begin_time) OVERRIDE; |
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 // PluginProcessHost::Client methods. | 29 private: |
34 virtual int ID() OVERRIDE; | 30 class Context : public PluginProcessHost::Client, |
Bernhard Bauer
2011/11/21 14:33:59
Is there any advantage to using a inner Context cl
jam
2011/11/21 17:29:18
Yes, keeping this simpler for embedders. Now they
Bernhard Bauer
2011/11/21 18:07:09
OK. The destruction thing could be achieved with D
| |
35 virtual bool OffTheRecord() OVERRIDE; | 31 public IPC::Channel::Listener, |
36 virtual const content::ResourceContext& GetResourceContext() OVERRIDE; | 32 public base::RefCountedThreadSafe<Context> { |
37 virtual void SetPluginInfo(const webkit::WebPluginInfo& info) OVERRIDE; | 33 public: |
38 virtual void OnFoundPluginProcessHost(PluginProcessHost* host) OVERRIDE; | 34 Context(const std::string& mime_type, |
39 virtual void OnSentPluginChannelRequest() OVERRIDE; | 35 base::Time begin_time, |
40 virtual void OnChannelOpened(const IPC::ChannelHandle& handle) OVERRIDE; | 36 const content::ResourceContext& resource_context); |
41 virtual void OnError() OVERRIDE; | 37 virtual ~Context(); |
42 | 38 |
43 // IPC::Channel::Listener methods. | 39 // PluginProcessHost::Client methods. |
44 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 40 virtual int ID() OVERRIDE; |
45 virtual void OnChannelError() OVERRIDE; | 41 virtual bool OffTheRecord() OVERRIDE; |
42 virtual const content::ResourceContext& GetResourceContext() OVERRIDE; | |
43 virtual void SetPluginInfo(const webkit::WebPluginInfo& info) OVERRIDE; | |
44 virtual void OnFoundPluginProcessHost(PluginProcessHost* host) OVERRIDE; | |
45 virtual void OnSentPluginChannelRequest() OVERRIDE; | |
46 virtual void OnChannelOpened(const IPC::ChannelHandle& handle) OVERRIDE; | |
47 virtual void OnError() OVERRIDE; | |
46 | 48 |
47 private: | 49 // IPC::Channel::Listener methods. |
48 // Signals that we are finished with removing data (successful or not). This | 50 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
49 // method is safe to call multiple times. | 51 virtual void OnChannelError() OVERRIDE; |
50 void SignalDone(); | 52 |
51 // Connects the client side of a newly opened plug-in channel. | 53 base::WaitableEvent* event() { return event_.get(); } |
52 void ConnectToChannel(const IPC::ChannelHandle& handle); | 54 |
53 // Handles the PluginHostMsg_ClearSiteDataResult message. | 55 private: |
54 void OnClearSiteDataResult(bool success); | 56 // Initialize on the IO thread. |
55 // Called when a timeout happens in order not to block the client | 57 void Init(const std::string& mime_type); |
56 // indefinitely. | 58 |
57 void OnTimeout(); | 59 // Connects the client side of a newly opened plug-in channel. |
60 void ConnectToChannel(const IPC::ChannelHandle& handle); | |
61 // Handles the PluginHostMsg_ClearSiteDataResult message. | |
62 void OnClearSiteDataResult(bool success); | |
63 // Called when a timeout happens in order not to block the client | |
64 // indefinitely. | |
65 void OnTimeout(); | |
66 | |
67 // Signals that we are finished with removing data (successful or not). This | |
68 // method is safe to call multiple times. | |
69 void SignalDone(); | |
70 | |
71 scoped_ptr<base::WaitableEvent> event_; | |
72 // The point in time when we start removing data. | |
73 base::Time remove_start_time_; | |
74 // The point in time from which on we remove data. | |
75 base::Time begin_time_; | |
76 bool is_removing_; | |
77 | |
78 // The resource context for the profile. | |
79 const content::ResourceContext& resource_context_; | |
80 | |
81 // 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 | |
83 // process. | |
84 IPC::Channel* channel_; | |
85 }; | |
58 | 86 |
59 std::string mime_type_; | 87 std::string mime_type_; |
60 bool is_starting_process_; | |
61 bool is_removing_; | |
62 // The point in time when we start removing data. | |
63 base::Time remove_start_time_; | |
64 // The point in time from which on we remove data. | |
65 base::Time begin_time_; | |
66 // The resource context for the profile. | 88 // The resource context for the profile. |
67 const content::ResourceContext& context_; | 89 const content::ResourceContext& resource_context_; |
68 scoped_ptr<base::WaitableEvent> event_; | |
69 // We own the channel, but it's used on the IO thread, so it needs to be | |
70 // deleted there. It's NULL until we have opened a connection to the plug-in | |
71 // process. | |
72 IPC::Channel* channel_; | |
73 | 90 |
74 base::WeakPtrFactory<PluginDataRemoverImpl> weak_factory_; | 91 // This allows this object to be deleted on the UI thread while it's still |
92 // being used on the IO thread. | |
93 scoped_refptr<Context> context_; | |
75 | 94 |
76 DISALLOW_COPY_AND_ASSIGN(PluginDataRemoverImpl); | 95 DISALLOW_COPY_AND_ASSIGN(PluginDataRemoverImpl); |
77 }; | 96 }; |
78 | 97 |
79 #endif // CONTENT_BROWSER_PLUGIN_DATA_REMOVER_IMPL_H_ | 98 #endif // CONTENT_BROWSER_PLUGIN_DATA_REMOVER_IMPL_H_ |
OLD | NEW |