summaryrefslogtreecommitdiffstats
path: root/chrome_frame/cfproxy_factory.cc
diff options
context:
space:
mode:
authorstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-06 17:34:43 +0000
committerstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-06 17:34:43 +0000
commit5a8db8040f8f1e4e320f882b1ffea89b6f32d5ea (patch)
treeb29c31cc55b6fec96d9b34e543d9425fce26153d /chrome_frame/cfproxy_factory.cc
parent85fb807c92bcf07512d12bff47dd5a9e22c03161 (diff)
downloadchromium_src-5a8db8040f8f1e4e320f882b1ffea89b6f32d5ea.zip
chromium_src-5a8db8040f8f1e4e320f882b1ffea89b6f32d5ea.tar.gz
chromium_src-5a8db8040f8f1e4e320f882b1ffea89b6f32d5ea.tar.bz2
Reland http://codereview.chromium.org/3528004/
Initial skeleton for refactored ChromeFrameAutomationClient and AutomationProxy for the needs of ChromeFrame. TBR=amit Review URL: http://codereview.chromium.org/3567019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61665 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/cfproxy_factory.cc')
-rw-r--r--chrome_frame/cfproxy_factory.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/chrome_frame/cfproxy_factory.cc b/chrome_frame/cfproxy_factory.cc
new file mode 100644
index 0000000..c936873
--- /dev/null
+++ b/chrome_frame/cfproxy_factory.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome_frame/cfproxy_private.h"
+#include "base/process_util.h"
+
+IPC::Message::Sender* CFProxyTraits::CreateChannel(const std::string& id,
+ IPC::Channel::Listener* listener) {
+ IPC::Channel* c = new IPC::Channel(id, IPC::Channel::MODE_SERVER, listener);
+ if (c)
+ c->Connect(); // must be called on the IPC thread.
+ return c;
+}
+
+void CFProxyTraits::CloseChannel(IPC::Message::Sender* s) {
+ IPC::Channel *c = static_cast<IPC::Channel*>(s);
+ delete c;
+}
+
+bool CFProxyTraits::LaunchApp(const std::wstring& cmd_line) {
+ bool ok = base::LaunchApp(cmd_line, false, false, NULL);
+ return ok;
+}
+
+//////////////////////////////////////////////////////////
+// ChromeProxyFactory
+
+ChromeProxyFactory::ChromeProxyFactory() {
+}
+
+ChromeProxyFactory::~ChromeProxyFactory() {
+ AutoLock lock(lock_);
+ ProxyMap::iterator it = proxies_.begin();
+ for (; it != proxies_.end(); ++it) {
+ delete it->second;
+ }
+ proxies_.clear();
+}
+
+void ChromeProxyFactory::GetProxy(ChromeProxyDelegate* delegate,
+ const ProxyParams& params) {
+ AutoLock lock(lock_);
+ ChromeProxy* proxy = NULL;
+ // TODO(stoyan): consider extra_params/timeout
+ ProxyMap::iterator it = proxies_.find(params.profile);
+ if (it == proxies_.end()) {
+ proxy = CreateProxy();
+ proxy->Init(params);
+ proxies_.insert(make_pair(params.profile, proxy));
+ } else {
+ proxy = it->second;
+ }
+
+ proxy->AddDelegate(delegate);
+ // TODO(stoyan): ::DeleteTimerQueueTimer (if any).
+}
+
+bool ChromeProxyFactory::ReleaseProxy(ChromeProxyDelegate* delegate,
+ const std::string& profile) {
+ AutoLock lock(lock_);
+ ProxyMap::iterator it = proxies_.find(profile);
+ if (it == proxies_.end())
+ return false;
+
+ if (0 == it->second->RemoveDelegate(delegate)) {
+ // This was the last delegate for this proxy.
+ // TODO(stoyan): Use ::CreateTimerQueueTimer to schedule destroy of
+ // the proxy in a reasonable timeout.
+ }
+
+ return true;
+}
+
+static CFProxyTraits g_default_traits;
+ChromeProxy* ChromeProxyFactory::CreateProxy() {
+ ChromeProxy* p = new CFProxy(&g_default_traits);
+ return p;
+}