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

Unified Diff: remoting/jingle_glue/jingle_test_client.cc

Issue 3167047: Jingle_glue bugfixes. (Closed)
Patch Set: - Created 10 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/jingle_glue/jingle_client_unittest.cc ('k') | remoting/jingle_glue/jingle_thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/jingle_glue/jingle_test_client.cc
diff --git a/remoting/jingle_glue/jingle_test_client.cc b/remoting/jingle_glue/jingle_test_client.cc
index 255a931ad497f7e00bcad2a9dbc706fd9138e50a..4157930bf59845f9fb1f923e761f6182935b5a04 100644
--- a/remoting/jingle_glue/jingle_test_client.cc
+++ b/remoting/jingle_glue/jingle_test_client.cc
@@ -14,6 +14,8 @@ extern "C" {
#include <list>
#include "base/at_exit.h"
+#include "base/nss_util.h"
+#include "base/time.h"
#include "media/base/data_buffer.h"
#include "remoting/base/constants.h"
#include "remoting/jingle_glue/jingle_channel.h"
@@ -25,13 +27,17 @@ using remoting::JingleChannel;
using remoting::kChromotingTokenServiceName;
class JingleTestClient : public JingleChannel::Callback,
- public JingleClient::Callback {
+ public JingleClient::Callback,
+ public base::RefCountedThreadSafe<JingleTestClient> {
public:
+ JingleTestClient()
+ : closed_event_(true, false) {
+ }
+
virtual ~JingleTestClient() {}
void Run(const std::string& username, const std::string& auth_token,
const std::string& host_jid) {
- // TODO(hclam): Fix the threading problem.
remoting::JingleThread jingle_thread;
jingle_thread.Start();
client_ = new JingleClient(&jingle_thread);
@@ -63,7 +69,12 @@ class JingleTestClient : public JingleChannel::Callback,
}
while (!channels_.empty()) {
- channels_.front()->Close();
+ closed_event_.Reset();
+ channels_.front()->Close(
+ NewRunnableMethod(this, &JingleTestClient::OnClosed));
+ // Wait until channel is closed. If it is not closed within 0.1 seconds
+ // continue closing everything else.
+ closed_event_.TimedWait(base::TimeDelta::FromMilliseconds(100));
channels_.pop_front();
}
@@ -106,12 +117,17 @@ class JingleTestClient : public JingleChannel::Callback,
channels_.push_back(channel);
}
+ void OnClosed() {
+ closed_event_.Signal();
+ }
+
private:
typedef std::list<scoped_refptr<JingleChannel> > ChannelsList;
scoped_refptr<JingleClient> client_;
ChannelsList channels_;
Lock channels_lock_;
+ base::WaitableEvent closed_event_;
};
int main(int argc, char** argv) {
@@ -120,6 +136,9 @@ int main(int argc, char** argv) {
base::AtExitManager exit_manager;
+ base::EnsureNSPRInit();
+ base::EnsureNSSInit();
+
std::string host_jid = argc == 2 ? argv[1] : "";
std::string username;
@@ -130,9 +149,9 @@ int main(int argc, char** argv) {
std::cout << "Auth token: ";
std::cin >> auth_token;
- JingleTestClient client;
+ scoped_refptr<JingleTestClient> client = new JingleTestClient();
- client.Run(username, auth_token, host_jid);
+ client->Run(username, auth_token, host_jid);
return 0;
}
« no previous file with comments | « remoting/jingle_glue/jingle_client_unittest.cc ('k') | remoting/jingle_glue/jingle_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698