OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/plugin_data_remover.h" | 5 #include "chrome/browser/plugin_data_remover.h" |
6 | 6 |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
8 #include "base/metrics/histogram.h" | |
9 #include "base/version.h" | |
8 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
9 #include "chrome/browser/plugin_service.h" | 11 #include "chrome/browser/plugin_service.h" |
10 #include "chrome/common/plugin_messages.h" | 12 #include "chrome/common/plugin_messages.h" |
11 #include "ipc/ipc_channel.h" | 13 #include "ipc/ipc_channel.h" |
jam
2010/12/14 17:34:19
nit: i dont think this include is needed
Bernhard Bauer
2010/12/14 20:38:37
Done.
| |
14 #include "webkit/glue/plugins/plugin_group.h" | |
15 #include "webkit/glue/plugins/plugin_list.h" | |
12 | 16 |
13 #if defined(OS_POSIX) | 17 #if defined(OS_POSIX) |
14 #include "ipc/ipc_channel_posix.h" | 18 #include "ipc/ipc_channel_posix.h" |
15 #endif | 19 #endif |
16 | 20 |
17 namespace { | 21 namespace { |
18 const std::string flash_mime_type = "application/x-shockwave-flash"; | 22 const char* g_flash_mime_type = "application/x-shockwave-flash"; |
19 const int64 timeout_ms = 10000; | 23 // TODO(bauerb): Update minimum required Flash version as soon as there is one |
20 } | 24 // implementing the API. |
25 const char* g_min_flash_version = "100"; | |
26 const int64 g_timeout_ms = 10000; | |
27 } // namespace | |
21 | 28 |
22 PluginDataRemover::PluginDataRemover() | 29 PluginDataRemover::PluginDataRemover() |
23 : channel_(NULL), | 30 : is_removing_(false), |
24 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 31 channel_(NULL) { } |
25 } | |
26 | 32 |
27 PluginDataRemover::~PluginDataRemover() { | 33 PluginDataRemover::~PluginDataRemover() { |
28 DCHECK(!done_task_.get()); | 34 DCHECK(!is_removing_); |
29 if (!BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_)) | 35 if (channel_) |
30 delete channel_; | 36 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); |
31 } | 37 } |
32 | 38 |
33 void PluginDataRemover::StartRemoving(base::Time begin_time, Task* done_task) { | 39 void PluginDataRemover::StartRemoving(base::Time begin_time, Task* done_task) { |
34 DCHECK(!done_task_.get()); | 40 DCHECK(!done_task_.get()); |
41 DCHECK(!is_removing_); | |
42 remove_start_time_ = base::Time::Now(); | |
35 begin_time_ = begin_time; | 43 begin_time_ = begin_time; |
36 | 44 |
37 message_loop_ = base::MessageLoopProxy::CreateForCurrentThread(); | 45 message_loop_ = base::MessageLoopProxy::CreateForCurrentThread(); |
38 done_task_.reset(done_task); | 46 done_task_.reset(done_task); |
47 is_removing_ = true; | |
39 | 48 |
49 AddRef(); | |
jam
2010/12/14 17:34:19
I don't understand why you keep a self reference b
Bernhard Bauer
2010/12/14 20:38:37
Even if the process never launches, eventually OnE
| |
40 PluginService::GetInstance()->OpenChannelToPlugin( | 50 PluginService::GetInstance()->OpenChannelToPlugin( |
41 GURL(), flash_mime_type, this); | 51 GURL(), g_flash_mime_type, this); |
42 | 52 |
43 BrowserThread::PostDelayedTask( | 53 BrowserThread::PostDelayedTask( |
44 BrowserThread::IO, | 54 BrowserThread::IO, |
45 FROM_HERE, | 55 FROM_HERE, |
46 method_factory_.NewRunnableMethod(&PluginDataRemover::OnTimeout), | 56 NewRunnableMethod(this, &PluginDataRemover::OnTimeout), |
47 timeout_ms); | 57 g_timeout_ms); |
48 } | 58 } |
49 | 59 |
50 int PluginDataRemover::ID() { | 60 int PluginDataRemover::ID() { |
51 // Generate an ID for the browser process. | 61 // Generate an ID for the browser process. |
52 return ChildProcessInfo::GenerateChildProcessUniqueId(); | 62 return ChildProcessInfo::GenerateChildProcessUniqueId(); |
53 } | 63 } |
54 | 64 |
55 bool PluginDataRemover::OffTheRecord() { | 65 bool PluginDataRemover::OffTheRecord() { |
56 return false; | 66 return false; |
57 } | 67 } |
58 | 68 |
59 void PluginDataRemover::SetPluginInfo(const WebPluginInfo& info) { | 69 void PluginDataRemover::SetPluginInfo(const WebPluginInfo& info) { |
60 } | 70 } |
61 | 71 |
62 void PluginDataRemover::OnChannelOpened(const IPC::ChannelHandle& handle) { | 72 void PluginDataRemover::OnChannelOpened(const IPC::ChannelHandle& handle) { |
73 ConnectToChannel(handle); | |
74 Release(); | |
75 } | |
76 | |
77 void PluginDataRemover::ConnectToChannel(const IPC::ChannelHandle& handle) { | |
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
79 | |
80 // If we timed out, don't bother connecting. | |
81 if (!is_removing_) | |
82 return; | |
83 | |
64 DCHECK(!channel_); | 84 DCHECK(!channel_); |
65 #if defined(OS_POSIX) | 85 #if defined(OS_POSIX) |
66 // If we received a ChannelHandle, register it now. | 86 // If we received a ChannelHandle, register it now. |
67 if (handle.socket.fd >= 0) | 87 if (handle.socket.fd >= 0) |
68 IPC::AddChannelSocket(handle.name, handle.socket.fd); | 88 IPC::AddChannelSocket(handle.name, handle.socket.fd); |
69 #endif | 89 #endif |
70 channel_ = new IPC::Channel(handle.name, IPC::Channel::MODE_CLIENT, this); | 90 channel_ = new IPC::Channel(handle.name, IPC::Channel::MODE_CLIENT, this); |
71 if (!channel_->Connect()) { | 91 if (!channel_->Connect()) { |
72 NOTREACHED() << "Couldn't connect to plugin"; | 92 LOG(DFATAL) << "Couldn't connect to plugin"; |
73 SignalDone(); | 93 SignalDone(); |
74 return; | 94 return; |
75 } | 95 } |
76 | 96 |
77 if (!channel_->Send( | 97 if (!channel_->Send( |
78 new PluginMsg_ClearSiteData(0, std::string(), begin_time_))) { | 98 new PluginMsg_ClearSiteData(0, std::string(), begin_time_))) { |
79 NOTREACHED() << "Couldn't send ClearSiteData message"; | 99 LOG(DFATAL) << "Couldn't send ClearSiteData message"; |
80 SignalDone(); | 100 SignalDone(); |
81 } | 101 } |
82 } | 102 } |
83 | 103 |
84 void PluginDataRemover::OnError() { | 104 void PluginDataRemover::OnError() { |
85 NOTREACHED() << "Couldn't open plugin channel"; | 105 NOTREACHED() << "Couldn't open plugin channel"; |
86 SignalDone(); | 106 SignalDone(); |
107 Release(); | |
87 } | 108 } |
88 | 109 |
89 void PluginDataRemover::OnClearSiteDataResult(bool success) { | 110 void PluginDataRemover::OnClearSiteDataResult(bool success) { |
90 DCHECK(success) << "ClearSiteData returned error"; | 111 if (!success) |
112 LOG(DFATAL) << "ClearSiteData returned error"; | |
113 UMA_HISTOGRAM_TIMES("ClearPluginData.time", | |
114 base::Time::Now() - remove_start_time_); | |
91 SignalDone(); | 115 SignalDone(); |
92 } | 116 } |
93 | 117 |
94 void PluginDataRemover::OnTimeout() { | 118 void PluginDataRemover::OnTimeout() { |
95 NOTREACHED() << "Timed out"; | 119 NOTREACHED() << "Timed out"; |
96 SignalDone(); | 120 SignalDone(); |
97 } | 121 } |
98 | 122 |
99 void PluginDataRemover::OnMessageReceived(const IPC::Message& msg) { | 123 void PluginDataRemover::OnMessageReceived(const IPC::Message& msg) { |
100 IPC_BEGIN_MESSAGE_MAP(PluginDataRemover, msg) | 124 IPC_BEGIN_MESSAGE_MAP(PluginDataRemover, msg) |
101 IPC_MESSAGE_HANDLER(PluginHostMsg_ClearSiteDataResult, | 125 IPC_MESSAGE_HANDLER(PluginHostMsg_ClearSiteDataResult, |
102 OnClearSiteDataResult) | 126 OnClearSiteDataResult) |
103 IPC_MESSAGE_UNHANDLED_ERROR() | 127 IPC_MESSAGE_UNHANDLED_ERROR() |
104 IPC_END_MESSAGE_MAP() | 128 IPC_END_MESSAGE_MAP() |
105 } | 129 } |
106 | 130 |
107 void PluginDataRemover::OnChannelError() { | 131 void PluginDataRemover::OnChannelError() { |
108 NOTREACHED() << "Channel error"; | 132 LOG(DFATAL) << "Channel error"; |
109 SignalDone(); | 133 SignalDone(); |
110 } | 134 } |
111 | 135 |
112 void PluginDataRemover::SignalDone() { | 136 void PluginDataRemover::SignalDone() { |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
114 if (!done_task_.get()) | 138 if (!is_removing_) |
115 return; | 139 return; |
116 message_loop_->PostTask(FROM_HERE, done_task_.release()); | 140 is_removing_ = false; |
117 message_loop_ = NULL; | 141 if (done_task_.get()) { |
142 message_loop_->PostTask(FROM_HERE, done_task_.release()); | |
143 message_loop_ = NULL; | |
144 } | |
118 } | 145 } |
146 | |
147 // static | |
148 bool PluginDataRemover::IsSupported() { | |
149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
150 bool allow_wildcard = false; | |
151 WebPluginInfo plugin; | |
152 std::string mime_type; | |
153 if (!NPAPI::PluginList::Singleton()->GetPluginInfo(GURL(), | |
154 g_flash_mime_type, | |
155 allow_wildcard, | |
156 &plugin, | |
157 &mime_type)) | |
158 return false; | |
159 scoped_ptr<Version> version( | |
160 PluginGroup::CreateVersionFromString(plugin.version)); | |
161 scoped_ptr<Version> min_version( | |
162 Version::GetVersionFromString(g_min_flash_version)); | |
163 return plugin.enabled && | |
164 version.get() | |
165 && min_version->CompareTo(*version) == -1; | |
jam
2010/12/14 17:34:19
nit: style is to have the && at the end of hte pre
Bernhard Bauer
2010/12/14 20:38:37
Done.
| |
166 } | |
OLD | NEW |