1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/plugin_data_remover.h"
#include "base/message_loop_proxy.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/plugin_service.h"
#include "chrome/common/plugin_messages.h"
#include "ipc/ipc_channel.h"
#if defined(OS_POSIX)
#include "ipc/ipc_channel_posix.h"
#endif
namespace {
const std::string flash_mime_type = "application/x-shockwave-flash";
const int64 timeout_ms = 10000;
}
PluginDataRemover::PluginDataRemover()
: channel_(NULL),
method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
PluginDataRemover::~PluginDataRemover() {
DCHECK(!done_task_.get());
if (!BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_))
delete channel_;
}
void PluginDataRemover::StartRemoving(base::Time begin_time, Task* done_task) {
DCHECK(!done_task_.get());
begin_time_ = begin_time;
message_loop_ = base::MessageLoopProxy::CreateForCurrentThread();
done_task_.reset(done_task);
PluginService::GetInstance()->OpenChannelToPlugin(
GURL(), flash_mime_type, this);
BrowserThread::PostDelayedTask(
BrowserThread::IO,
FROM_HERE,
method_factory_.NewRunnableMethod(&PluginDataRemover::OnTimeout),
timeout_ms);
}
int PluginDataRemover::ID() {
// Generate an ID for the browser process.
return ChildProcessInfo::GenerateChildProcessUniqueId();
}
bool PluginDataRemover::OffTheRecord() {
return false;
}
void PluginDataRemover::SetPluginInfo(const WebPluginInfo& info) {
}
void PluginDataRemover::OnChannelOpened(const IPC::ChannelHandle& handle) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(!channel_);
channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this);
if (!channel_->Connect()) {
NOTREACHED() << "Couldn't connect to plugin";
SignalDone();
return;
}
if (!channel_->Send(
new PluginMsg_ClearSiteData(0, std::string(), begin_time_))) {
NOTREACHED() << "Couldn't send ClearSiteData message";
SignalDone();
}
}
void PluginDataRemover::OnError() {
NOTREACHED() << "Couldn't open plugin channel";
SignalDone();
}
void PluginDataRemover::OnClearSiteDataResult(bool success) {
DCHECK(success) << "ClearSiteData returned error";
SignalDone();
}
void PluginDataRemover::OnTimeout() {
NOTREACHED() << "Timed out";
SignalDone();
}
void PluginDataRemover::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(PluginDataRemover, msg)
IPC_MESSAGE_HANDLER(PluginHostMsg_ClearSiteDataResult,
OnClearSiteDataResult)
IPC_MESSAGE_UNHANDLED_ERROR()
IPC_END_MESSAGE_MAP()
}
void PluginDataRemover::OnChannelError() {
NOTREACHED() << "Channel error";
SignalDone();
}
void PluginDataRemover::SignalDone() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!done_task_.get())
return;
message_loop_->PostTask(FROM_HERE, done_task_.release());
message_loop_ = NULL;
}
|