OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome_frame/cfproxy_private.h" | |
6 #include "base/process_util.h" | |
7 | |
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; | |
14 } | |
15 | |
16 void CFProxyTraits::CloseChannel(IPC::Message::Sender* s) { | |
17 IPC::Channel *c = static_cast<IPC::Channel*>(s); | |
18 delete c; | |
19 } | |
20 | |
21 bool CFProxyTraits::LaunchApp(const std::wstring& cmd_line) { | |
22 return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL); | |
23 } | |
24 | |
25 ////////////////////////////////////////////////////////// | |
26 // ChromeProxyFactory | |
27 | |
28 ChromeProxyFactory::ChromeProxyFactory() { | |
29 } | |
30 | |
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; | |
37 } | |
38 proxies_.clear(); | |
39 } | |
40 | |
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; | |
53 } | |
54 | |
55 proxy->AddDelegate(delegate); | |
56 // TODO(stoyan): ::DeleteTimerQueueTimer (if any). | |
57 } | |
58 | |
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; | |
65 | |
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. | |
70 } | |
71 | |
72 return true; | |
73 } | |
74 | |
75 static CFProxyTraits g_default_traits; | |
76 ChromeProxy* ChromeProxyFactory::CreateProxy() { | |
77 ChromeProxy* p = new CFProxy(&g_default_traits); | |
78 return p; | |
79 } | |
OLD | NEW |