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

Side by Side Diff: remoting/client/jni/chromoting_jni_instance.cc

Issue 2023113002: Fix bug of posting task inside constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "remoting/client/jni/chromoting_jni_instance.h" 5 #include "remoting/client/jni/chromoting_jni_instance.h"
6 6
7 #include <android/log.h> 7 #include <android/log.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 xmpp_config_.auth_token = auth_token; 72 xmpp_config_.auth_token = auth_token;
73 73
74 client_auth_config_.host_id = host_id; 74 client_auth_config_.host_id = host_id;
75 client_auth_config_.pairing_client_id = pairing_id; 75 client_auth_config_.pairing_client_id = pairing_id;
76 client_auth_config_.pairing_secret = pairing_secret; 76 client_auth_config_.pairing_secret = pairing_secret;
77 client_auth_config_.fetch_secret_callback = base::Bind( 77 client_auth_config_.fetch_secret_callback = base::Bind(
78 &ChromotingJniInstance::FetchSecret, weak_factory_.GetWeakPtr()); 78 &ChromotingJniInstance::FetchSecret, weak_factory_.GetWeakPtr());
79 client_auth_config_.fetch_third_party_token_callback = 79 client_auth_config_.fetch_third_party_token_callback =
80 base::Bind(&ChromotingJniInstance::FetchThirdPartyToken, 80 base::Bind(&ChromotingJniInstance::FetchThirdPartyToken,
81 weak_factory_.GetWeakPtr(), host_pubkey); 81 weak_factory_.GetWeakPtr(), host_pubkey);
82
83 // Post a task to start connection
84 jni_runtime_->network_task_runner()->PostTask(
85 FROM_HERE,
86 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, this));
87 } 82 }
88 83
89 ChromotingJniInstance::~ChromotingJniInstance() { 84 ChromotingJniInstance::~ChromotingJniInstance() {
90 // This object is ref-counted, so this dtor can execute on any thread. 85 // This object is ref-counted, so this dtor can execute on any thread.
91 // Ensure that all these objects have been freed already, so they are not 86 // Ensure that all these objects have been freed already, so they are not
92 // destroyed on some random thread. 87 // destroyed on some random thread.
93 DCHECK(!view_); 88 DCHECK(!view_);
94 DCHECK(!client_context_); 89 DCHECK(!client_context_);
95 DCHECK(!video_renderer_); 90 DCHECK(!video_renderer_);
96 DCHECK(!client_); 91 DCHECK(!client_);
97 DCHECK(!signaling_); 92 DCHECK(!signaling_);
98 } 93 }
99 94
95 void ChromotingJniInstance::Connect() {
96 if (jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
97 ConnectToHostOnNetworkThread();
98 } else {
99 jni_runtime_->network_task_runner()->PostTask(
100 FROM_HERE,
101 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, this));
102 }
103 }
104
100 void ChromotingJniInstance::Disconnect() { 105 void ChromotingJniInstance::Disconnect() {
101 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 106 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
102 jni_runtime_->network_task_runner()->PostTask( 107 jni_runtime_->network_task_runner()->PostTask(
103 FROM_HERE, 108 FROM_HERE,
104 base::Bind(&ChromotingJniInstance::Disconnect, this)); 109 base::Bind(&ChromotingJniInstance::Disconnect, this));
105 return; 110 return;
106 } 111 }
107 112
108 stats_logging_enabled_ = false; 113 stats_logging_enabled_ = false;
109 114
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 perf_tracker_->round_trip_ms().Max()); 524 perf_tracker_->round_trip_ms().Max());
520 525
521 jni_runtime_->logger()->LogStatistics(perf_tracker_.get()); 526 jni_runtime_->logger()->LogStatistics(perf_tracker_.get());
522 527
523 jni_runtime_->network_task_runner()->PostDelayedTask( 528 jni_runtime_->network_task_runner()->PostDelayedTask(
524 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), 529 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this),
525 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); 530 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs));
526 } 531 }
527 532
528 } // namespace remoting 533 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/jni/chromoting_jni_instance.h ('k') | remoting/client/jni/chromoting_jni_runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698