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

Side by Side Diff: chrome/test/automation/automation_proxy.cc

Issue 6012006: Revert 68944 - Revert "Add named testing interface." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 12 months 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/test/automation/automation_proxy.h" 5 #include "chrome/test/automation/automation_proxy.h"
6 6
7 #include <gtest/gtest.h> 7 #include <gtest/gtest.h>
8 8
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 perform_version_check_(false), 100 perform_version_check_(false),
101 disconnect_on_failure_(disconnect_on_failure), 101 disconnect_on_failure_(disconnect_on_failure),
102 command_execution_timeout_( 102 command_execution_timeout_(
103 TimeDelta::FromMilliseconds(command_execution_timeout_ms)), 103 TimeDelta::FromMilliseconds(command_execution_timeout_ms)),
104 listener_thread_id_(0) { 104 listener_thread_id_(0) {
105 // base::WaitableEvent::TimedWait() will choke if we give it a negative value. 105 // base::WaitableEvent::TimedWait() will choke if we give it a negative value.
106 // Zero also seems unreasonable, since we need to wait for IPC, but at 106 // Zero also seems unreasonable, since we need to wait for IPC, but at
107 // least it is legal... ;-) 107 // least it is legal... ;-)
108 DCHECK_GE(command_execution_timeout_ms, 0); 108 DCHECK_GE(command_execution_timeout_ms, 0);
109 listener_thread_id_ = PlatformThread::CurrentId(); 109 listener_thread_id_ = PlatformThread::CurrentId();
110 InitializeChannelID();
111 InitializeHandleTracker(); 110 InitializeHandleTracker();
112 InitializeThread(); 111 InitializeThread();
113 InitializeChannel();
114 } 112 }
115 113
116 AutomationProxy::~AutomationProxy() { 114 AutomationProxy::~AutomationProxy() {
117 // Destruction order is important. Thread has to outlive the channel and 115 // Destruction order is important. Thread has to outlive the channel and
118 // tracker has to outlive the thread since we access the tracker inside 116 // tracker has to outlive the thread since we access the tracker inside
119 // AutomationMessageFilter::OnMessageReceived. 117 // AutomationMessageFilter::OnMessageReceived.
120 Disconnect(); 118 Disconnect();
121 thread_.reset(); 119 thread_.reset();
122 tracker_.reset(); 120 tracker_.reset();
123 } 121 }
124 122
125 void AutomationProxy::InitializeChannelID() { 123 std::string AutomationProxy::GenerateChannelID() {
126 // The channel counter keeps us out of trouble if we create and destroy 124 // The channel counter keeps us out of trouble if we create and destroy
127 // several AutomationProxies sequentially over the course of a test run. 125 // several AutomationProxies sequentially over the course of a test run.
128 // (Creating the channel sometimes failed before when running a lot of 126 // (Creating the channel sometimes failed before when running a lot of
129 // tests in sequence, and our theory is that sometimes the channel ID 127 // tests in sequence, and our theory is that sometimes the channel ID
130 // wasn't getting freed up in time for the next test.) 128 // wasn't getting freed up in time for the next test.)
131 static int channel_counter = 0; 129 static int channel_counter = 0;
132 130
133 std::ostringstream buf; 131 std::ostringstream buf;
134 buf << "ChromeTestingInterface:" << base::GetCurrentProcId() << 132 buf << "ChromeTestingInterface:" << base::GetCurrentProcId() <<
135 "." << ++channel_counter; 133 "." << ++channel_counter;
136 channel_id_ = buf.str(); 134 return buf.str();
137 } 135 }
138 136
139 void AutomationProxy::InitializeThread() { 137 void AutomationProxy::InitializeThread() {
140 scoped_ptr<base::Thread> thread( 138 scoped_ptr<base::Thread> thread(
141 new base::Thread("AutomationProxy_BackgroundThread")); 139 new base::Thread("AutomationProxy_BackgroundThread"));
142 base::Thread::Options options; 140 base::Thread::Options options;
143 options.message_loop_type = MessageLoop::TYPE_IO; 141 options.message_loop_type = MessageLoop::TYPE_IO;
144 bool thread_result = thread->StartWithOptions(options); 142 bool thread_result = thread->StartWithOptions(options);
145 DCHECK(thread_result); 143 DCHECK(thread_result);
146 thread_.swap(thread); 144 thread_.swap(thread);
147 } 145 }
148 146
149 void AutomationProxy::InitializeChannel() { 147 void AutomationProxy::InitializeChannel(const std::string& channel_id,
148 bool use_named_interface) {
150 DCHECK(shutdown_event_.get() != NULL); 149 DCHECK(shutdown_event_.get() != NULL);
151 150
152 // TODO(iyengar) 151 // TODO(iyengar)
153 // The shutdown event could be global on the same lines as the automation 152 // The shutdown event could be global on the same lines as the automation
154 // provider, where we use the shutdown event provided by the chrome browser 153 // provider, where we use the shutdown event provided by the chrome browser
155 // process. 154 // process.
156 channel_.reset(new IPC::SyncChannel( 155 channel_.reset(new IPC::SyncChannel(
157 channel_id_, 156 channel_id,
158 IPC::Channel::MODE_SERVER, 157 use_named_interface ? IPC::Channel::MODE_NAMED_CLIENT
158 : IPC::Channel::MODE_SERVER,
159 this, // we are the listener 159 this, // we are the listener
160 thread_->message_loop(), 160 thread_->message_loop(),
161 true, 161 true,
162 shutdown_event_.get())); 162 shutdown_event_.get()));
163 channel_->AddFilter(new AutomationMessageFilter(this)); 163 channel_->AddFilter(new AutomationMessageFilter(this));
164 } 164 }
165 165
166 void AutomationProxy::InitializeHandleTracker() { 166 void AutomationProxy::InitializeHandleTracker() {
167 tracker_.reset(new AutomationHandleTracker()); 167 tracker_.reset(new AutomationHandleTracker());
168 } 168 }
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 password, 543 password,
544 &success)); 544 &success));
545 // If message sending unsuccessful or test failed, return false. 545 // If message sending unsuccessful or test failed, return false.
546 return sent && success; 546 return sent && success;
547 } 547 }
548 #endif 548 #endif
549 549
550 bool AutomationProxy::ResetToDefaultTheme() { 550 bool AutomationProxy::ResetToDefaultTheme() {
551 return Send(new AutomationMsg_ResetToDefaultTheme(0)); 551 return Send(new AutomationMsg_ResetToDefaultTheme(0));
552 } 552 }
OLDNEW
« no previous file with comments | « chrome/test/automation/automation_proxy.h ('k') | chrome/test/automation/automation_proxy_uitest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698