Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome_frame/cfproxy_proxy.cc

Issue 8591009: ChromeFrame: Convert TaskMarshallerThroughMessageQueue to new Callback system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/cfproxy_private.h ('k') | chrome_frame/external_tab.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome_frame/cfproxy_private.h" 5 #include "chrome_frame/cfproxy_private.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/tuple.h" 9 #include "base/tuple.h"
8 #include "ipc/ipc_sync_message.h" 10 #include "ipc/ipc_sync_message.h"
9 #include "chrome/common/automation_messages.h" 11 #include "chrome/common/automation_messages.h"
10 12
11 CFProxy::CFProxy(CFProxyTraits* api) : ipc_thread_("ipc"), 13 CFProxy::CFProxy(CFProxyTraits* api) : ipc_thread_("ipc"),
12 sync_dispatcher_(&tab2delegate_), 14 sync_dispatcher_(&tab2delegate_),
13 ipc_sender_(NULL), 15 ipc_sender_(NULL),
14 api_(api), 16 api_(api),
15 delegate_count_(0), 17 delegate_count_(0),
16 is_connected_(false) { 18 is_connected_(false) {
17 } 19 }
18 20
19 CFProxy::~CFProxy() { 21 CFProxy::~CFProxy() {
20 ipc_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, 22 ipc_thread_.message_loop()->PostTask(
21 &CFProxy::CleanupOnIoThread)); 23 FROM_HERE,
24 base::Bind(&CFProxy::CleanupOnIoThread, base::Unretained(this)));
22 // ipc_thread destructor will do the Stop anyway. this is for debug :) 25 // ipc_thread destructor will do the Stop anyway. this is for debug :)
23 ipc_thread_.Stop(); 26 ipc_thread_.Stop();
24 } 27 }
25 28
26
27 void CFProxy::Init(const ProxyParams& params) { 29 void CFProxy::Init(const ProxyParams& params) {
28 ipc_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); 30 ipc_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0));
29 ipc_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, 31 ipc_thread_.message_loop()->PostTask(
30 &CFProxy::InitInIoThread, params)); 32 FROM_HERE,
33 base::Bind(&CFProxy::InitInIoThread, base::Unretained(this), params));
31 } 34 }
32 35
33 int CFProxy::AddDelegate(ChromeProxyDelegate* delegate) { 36 int CFProxy::AddDelegate(ChromeProxyDelegate* delegate) {
34 ipc_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, 37 ipc_thread_.message_loop()->PostTask(
35 &CFProxy::AddDelegateOnIoThread, delegate)); 38 FROM_HERE, base::Bind(&CFProxy::AddDelegateOnIoThread,
39 base::Unretained(this), delegate));
36 return ++delegate_count_; 40 return ++delegate_count_;
37 } 41 }
38 42
39 int CFProxy::RemoveDelegate(ChromeProxyDelegate* delegate) { 43 int CFProxy::RemoveDelegate(ChromeProxyDelegate* delegate) {
40 ipc_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, 44 ipc_thread_.message_loop()->PostTask(
41 &CFProxy::RemoveDelegateOnIoThread, delegate)); 45 FROM_HERE, base::Bind(&CFProxy::RemoveDelegateOnIoThread,
46 base::Unretained(this), delegate));
42 return --delegate_count_; 47 return --delegate_count_;
43 } 48 }
44 49
45 void CFProxy::AddDelegateOnIoThread(ChromeProxyDelegate* delegate) { 50 void CFProxy::AddDelegateOnIoThread(ChromeProxyDelegate* delegate) {
46 DCHECK(CalledOnIpcThread()); 51 DCHECK(CalledOnIpcThread());
47 DelegateHolder::AddDelegate(delegate); 52 DelegateHolder::AddDelegate(delegate);
48 if (is_connected_) { 53 if (is_connected_) {
49 delegate->Connected(this); 54 delegate->Connected(this);
50 } 55 }
51 } 56 }
52 57
53 void CFProxy::RemoveDelegateOnIoThread(ChromeProxyDelegate* delegate) { 58 void CFProxy::RemoveDelegateOnIoThread(ChromeProxyDelegate* delegate) {
54 DCHECK(CalledOnIpcThread()); 59 DCHECK(CalledOnIpcThread());
55 // Cancel any calls in progress. 60 // Cancel any calls in progress.
56 sync_dispatcher_.Cancel(delegate); 61 sync_dispatcher_.Cancel(delegate);
57 DelegateHolder::RemoveDelegate(delegate); 62 DelegateHolder::RemoveDelegate(delegate);
58 delegate->Disconnected(); 63 delegate->Disconnected();
59 } 64 }
60 65
61 void CFProxy::InitInIoThread(const ProxyParams& params) { 66 void CFProxy::InitInIoThread(const ProxyParams& params) {
62 DCHECK(CalledOnIpcThread()); 67 DCHECK(CalledOnIpcThread());
63 std::string channel_id = GenerateChannelId(); 68 std::string channel_id = GenerateChannelId();
64 ipc_sender_ = api_->CreateChannel(channel_id, this); 69 ipc_sender_ = api_->CreateChannel(channel_id, this);
65 std::wstring cmd_line = BuildCmdLine(channel_id, params.profile_path, 70 std::wstring cmd_line = BuildCmdLine(channel_id, params.profile_path,
66 params.extra_params); 71 params.extra_params);
67 if (!cmd_line.empty() && api_->LaunchApp(cmd_line)) { 72 if (!cmd_line.empty() && api_->LaunchApp(cmd_line)) {
68 CancelableTask* launch_timeout = NewRunnableMethod(this, 73 ipc_thread_.message_loop()->PostDelayedTask(
69 &CFProxy::LaunchTimeOut); 74 FROM_HERE, base::Bind(&CFProxy::LaunchTimeOut, base::Unretained(this)),
70 ipc_thread_.message_loop()->PostDelayedTask(FROM_HERE, launch_timeout,
71 params.timeout.InMilliseconds()); 75 params.timeout.InMilliseconds());
72 } else { 76 } else {
73 OnPeerLost(ChromeProxyDelegate::CHROME_EXE_LAUNCH_FAILED); 77 OnPeerLost(ChromeProxyDelegate::CHROME_EXE_LAUNCH_FAILED);
74 } 78 }
75 } 79 }
76 80
77 void CFProxy::CleanupOnIoThread() { 81 void CFProxy::CleanupOnIoThread() {
78 DCHECK(CalledOnIpcThread()); 82 DCHECK(CalledOnIpcThread());
79 if (ipc_sender_) { 83 if (ipc_sender_) {
80 api_->CloseChannel(ipc_sender_); 84 api_->CloseChannel(ipc_sender_);
(...skipping 22 matching lines...) Expand all
103 ipc_sender_ = NULL; 107 ipc_sender_ = NULL;
104 } 108 }
105 109
106 for (DelegateList::iterator it = delegate_list_.begin(); 110 for (DelegateList::iterator it = delegate_list_.begin();
107 it != delegate_list_.end(); ++it) { 111 it != delegate_list_.end(); ++it) {
108 (*it)->PeerLost(this, reason); 112 (*it)->PeerLost(this, reason);
109 } 113 }
110 } 114 }
111 115
112 void CFProxy::SendIpcMessage(IPC::Message* m) { 116 void CFProxy::SendIpcMessage(IPC::Message* m) {
113 ipc_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, 117 ipc_thread_.message_loop()->PostTask(
114 &CFProxy::SendIpcMessageOnIoThread, m)); 118 FROM_HERE, base::Bind(&CFProxy::SendIpcMessageOnIoThread,
119 base::Unretained(this), m));
115 } 120 }
116 121
117 void CFProxy::SendIpcMessageOnIoThread(IPC::Message* m) { 122 void CFProxy::SendIpcMessageOnIoThread(IPC::Message* m) {
118 DCHECK(CalledOnIpcThread()); 123 DCHECK(CalledOnIpcThread());
119 if (ipc_sender_) { 124 if (ipc_sender_) {
120 ipc_sender_->Send(m); 125 ipc_sender_->Send(m);
121 } else { 126 } else {
122 delete m; 127 delete m;
123 } 128 }
124 } 129 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 void CFProxy::OnChannelError() { 217 void CFProxy::OnChannelError() {
213 is_connected_ = false; 218 is_connected_ = false;
214 219
215 // Inform the sync message callbacks that there are not going to see 220 // Inform the sync message callbacks that there are not going to see
216 // any reply. 221 // any reply.
217 sync_dispatcher_.OnChannelClosed(); 222 sync_dispatcher_.OnChannelClosed();
218 OnPeerLost(ChromeProxyDelegate::CHANNEL_ERROR); 223 OnPeerLost(ChromeProxyDelegate::CHANNEL_ERROR);
219 224
220 // TODO(stoyan): Relaunch? 225 // TODO(stoyan): Relaunch?
221 } 226 }
OLDNEW
« no previous file with comments | « chrome_frame/cfproxy_private.h ('k') | chrome_frame/external_tab.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698