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