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