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
3 // found in the LICENSE file.
5 #include "chrome_frame/cfproxy_private.h"
6 #include "base/process_util.h"
8 IPC::Message::Sender
* CFProxyTraits::CreateChannel(const std::string
& id
,
9 IPC::Channel::Listener
* listener
) {
10 IPC::Channel
* c
= new IPC::Channel(id
, IPC::Channel::MODE_SERVER
, listener
);
12 c
->Connect(); // must be called on the IPC thread.
16 void CFProxyTraits::CloseChannel(IPC::Message::Sender
* s
) {
17 IPC::Channel
*c
= static_cast<IPC::Channel
*>(s
);
21 bool CFProxyTraits::LaunchApp(const std::wstring
& cmd_line
) {
22 return base::LaunchProcess(cmd_line
, base::LaunchOptions(), NULL
);
25 //////////////////////////////////////////////////////////
28 ChromeProxyFactory::ChromeProxyFactory() {
31 ChromeProxyFactory::~ChromeProxyFactory() {
32 base::AutoLock
lock(lock_
);
33 ProxyMap::iterator it
= proxies_
.begin();
34 for (; it
!= proxies_
.end(); ++it
) {
35 ChromeProxy
* proxy
= it
->second
;
41 void ChromeProxyFactory::GetProxy(ChromeProxyDelegate
* delegate
,
42 const ProxyParams
& params
) {
43 base::AutoLock
lock(lock_
);
44 ChromeProxy
* proxy
= NULL
;
45 // TODO(stoyan): consider extra_params/timeout
46 ProxyMap::iterator it
= proxies_
.find(params
.profile
);
47 if (it
== proxies_
.end()) {
48 proxy
= CreateProxy();
50 proxies_
.insert(make_pair(params
.profile
, proxy
));
55 proxy
->AddDelegate(delegate
);
56 // TODO(stoyan): ::DeleteTimerQueueTimer (if any).
59 bool ChromeProxyFactory::ReleaseProxy(ChromeProxyDelegate
* delegate
,
60 const std::string
& profile
) {
61 base::AutoLock
lock(lock_
);
62 ProxyMap::iterator it
= proxies_
.find(profile
);
63 if (it
== proxies_
.end())
66 if (0 == it
->second
->RemoveDelegate(delegate
)) {
67 // This was the last delegate for this proxy.
68 // TODO(stoyan): Use ::CreateTimerQueueTimer to schedule destroy of
69 // the proxy in a reasonable timeout.
75 static CFProxyTraits g_default_traits
;
76 ChromeProxy
* ChromeProxyFactory::CreateProxy() {
77 ChromeProxy
* p
= new CFProxy(&g_default_traits
);