Remove srpcgen-diff test from scons
[chromium-blink-merge.git] / chrome_frame / cfproxy_factory.cc
blob35694afdfdc08f1503ca2a6c2b35f3985d40ddbd
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);
11 if (c)
12 c->Connect(); // must be called on the IPC thread.
13 return c;
16 void CFProxyTraits::CloseChannel(IPC::Message::Sender* s) {
17 IPC::Channel *c = static_cast<IPC::Channel*>(s);
18 delete c;
21 bool CFProxyTraits::LaunchApp(const std::wstring& cmd_line) {
22 return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL);
25 //////////////////////////////////////////////////////////
26 // ChromeProxyFactory
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;
36 delete proxy;
38 proxies_.clear();
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();
49 proxy->Init(params);
50 proxies_.insert(make_pair(params.profile, proxy));
51 } else {
52 proxy = it->second;
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())
64 return false;
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.
72 return true;
75 static CFProxyTraits g_default_traits;
76 ChromeProxy* ChromeProxyFactory::CreateProxy() {
77 ChromeProxy* p = new CFProxy(&g_default_traits);
78 return p;