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 #include "content/ppapi_plugin/broker_process_dispatcher.h" | 5 #include "content/ppapi_plugin/broker_process_dispatcher.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
7 #include "content/common/child_process.h" | 9 #include "content/common/child_process.h" |
8 | 10 |
9 namespace { | 11 namespace { |
10 | 12 |
11 class BrokerReleaseTask : public Task { | |
12 public: | |
13 void Run() { | |
14 DVLOG(1) << "BrokerReleaseTask::Run()"; | |
15 ChildProcess::current()->ReleaseProcess(); | |
16 } | |
17 }; | |
18 | |
19 // How long we wait before releasing the broker process. | 13 // How long we wait before releasing the broker process. |
20 const int kBrokerReleaseTimeMs = 30 * 1000; // 30 seconds. | 14 const int kBrokerReleaseTimeMs = 30 * 1000; // 30 seconds. |
21 | 15 |
22 } // namespace | 16 } // namespace |
23 | 17 |
24 BrokerProcessDispatcher::BrokerProcessDispatcher( | 18 BrokerProcessDispatcher::BrokerProcessDispatcher( |
25 base::ProcessHandle remote_process_handle, | 19 base::ProcessHandle remote_process_handle, |
26 PP_ConnectInstance_Func connect_instance) | 20 PP_ConnectInstance_Func connect_instance) |
27 : ppapi::proxy::BrokerSideDispatcher(remote_process_handle, | 21 : ppapi::proxy::BrokerSideDispatcher(remote_process_handle, |
28 connect_instance) { | 22 connect_instance) { |
29 ChildProcess::current()->AddRefProcess(); | 23 ChildProcess::current()->AddRefProcess(); |
30 } | 24 } |
31 | 25 |
32 BrokerProcessDispatcher::~BrokerProcessDispatcher() { | 26 BrokerProcessDispatcher::~BrokerProcessDispatcher() { |
33 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()"; | 27 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()"; |
34 // Don't free the process right away. This timer allows the child process | 28 // Don't free the process right away. This timer allows the child process |
35 // to be re-used if the user rapidly goes to a new page that requires this | 29 // to be re-used if the user rapidly goes to a new page that requires this |
36 // plugin. This is the case for common plugins where they may be used on a | 30 // plugin. This is the case for common plugins where they may be used on a |
37 // source and destination page of a navigation. We don't want to tear down | 31 // source and destination page of a navigation. We don't want to tear down |
38 // and re-start processes each time in these cases. | 32 // and re-start processes each time in these cases. |
39 MessageLoop::current()->PostDelayedTask(FROM_HERE, new BrokerReleaseTask(), | 33 MessageLoop::current()->PostDelayedTask( |
40 kBrokerReleaseTimeMs); | 34 FROM_HERE, |
| 35 base::Bind(&ChildProcess::ReleaseProcess, |
| 36 base::Unretained(ChildProcess::current())), |
| 37 kBrokerReleaseTimeMs); |
41 } | 38 } |
OLD | NEW |