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

Unified Diff: remoting/host/host_signaling_manager.h

Issue 719983002: Reporting of policy errors via host-offline-reason: part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hor-nohoststatussender
Patch Set: Better callback currying. Created 6 years 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
Index: remoting/host/host_signaling_manager.h
diff --git a/remoting/host/host_signaling_manager.h b/remoting/host/host_signaling_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..42160880654004b0c84636fb467902a88d4f9594
--- /dev/null
+++ b/remoting/host/host_signaling_manager.h
@@ -0,0 +1,104 @@
+// Copyright 2014 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.
+
+#ifndef REMOTING_HOST_HOST_SIGNALING_MANAGER_H_
+#define REMOTING_HOST_HOST_SIGNALING_MANAGER_H_
+
+#include <string>
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "remoting/base/auto_thread_task_runner.h"
+#include "remoting/base/rsa_key_pair.h"
+#include "remoting/host/heartbeat_sender.h"
+#include "remoting/signaling/xmpp_signal_strategy.h"
+
+namespace base {
+class TimeDelta;
+}
+
+namespace net {
+class NetworkChangeNotifier;
+}
+
+namespace remoting {
+
+class ChromotingHostContext;
+class DnsBlackholeChecker;
+class HeartbeatSender;
+class OAuthTokenGetter;
+class SignalStrategy;
+class SignalingConnector;
+
+// HostSignalingManager has 2 functions:
+// 1. Keep sending regular heartbeats to the service.
Wez 2014/12/18 00:46:22 You mean to the Chromoting Directory, I think?
Łukasz Anforowicz 2014/12/18 19:02:33 To Talk, Chromoting Directory and Chromoting Bot.
Wez 2014/12/19 22:05:37 We only send the heartbeat to the directory - it j
Łukasz Anforowicz 2015/01/07 01:24:04 Got it - done (s/service/Chromoting Directory/).
+// 2. Keep the host process alive while sending host-offline-reason heartbeat.
Wez 2014/12/18 00:46:22 nit: The second function is to make a best-effort
Łukasz Anforowicz 2014/12/18 19:02:34 I think I'll leave it as-is. The ref-counting tri
Wez 2014/12/19 22:05:37 Acknowledged.
+class HostSignalingManager {
+ public:
+ // TODO(lukasza): Refactor to limit the number of parameters below.
+ // Probably necessitates refactoring HostProcess to extract a new
+ // class to read and store config/policy/cmdline values.
Wez 2014/12/18 00:46:21 The parameters need documenting.
Łukasz Anforowicz 2014/12/18 19:02:34 I documented some of the parameters. I didn't d
Wez 2014/12/19 22:05:37 Please document the paremeters in the Create() met
Łukasz Anforowicz 2015/01/07 01:24:04 Done.
+ static scoped_ptr<HostSignalingManager> Create(
+ const base::Closure& on_heartbeat_successful_callback,
+ const base::Closure& on_unknown_host_id_error_callback,
+ const base::Closure& on_auth_failed_callback,
Wez 2014/12/18 00:46:21 As previously commented, these should be combined
Łukasz Anforowicz 2014/12/18 19:02:34 Nooooo. As I pointed out earlier, this results in
Wez 2014/12/19 22:05:37 I disagree; the callback-based implementation has
Łukasz Anforowicz 2015/01/07 01:24:04 I think the lifetime semantics are cleaner with ca
Wez 2015/01/09 02:55:45 Not really; it becomes a perfectly straightforward
Łukasz Anforowicz 2015/01/09 19:00:13 Ok.
+ const ChromotingHostContext& host_context,
Wez 2014/12/18 00:46:21 Ick... do you really need this? The ChromotingHost
Łukasz Anforowicz 2014/12/18 19:02:34 I think it is ok / not icky... 1. HostSignalingMan
Wez 2014/12/19 22:05:37 HostProcess is a special-case in that it is an imp
Łukasz Anforowicz 2015/01/07 01:24:04 Done.
+ const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
+ const std::string& talkgadget_prefix,
+ const std::string& host_id,
+ const scoped_refptr<const RsaKeyPair>& key_pair,
+ const std::string& directory_bot_jid,
Wez 2014/12/18 00:46:21 what's this?
Łukasz Anforowicz 2014/12/18 19:02:34 It's a JID to use when talking to Directory Bot.
Wez 2014/12/19 22:05:37 Right; the question is not _what_ is the parameter
Łukasz Anforowicz 2015/01/07 01:24:04 Got it. As Feynman says (https://www.youtube.com/
+ const std::string& oauth_refresh_token,
+ bool use_service_account);
Wez 2014/12/18 00:46:21 What does "use_service_account" mean?
Łukasz Anforowicz 2014/12/18 19:02:34 I don't know - I am just moving an already working
Wez 2014/12/19 22:05:37 Yeah, that parameter is super badly documented; yo
Łukasz Anforowicz 2015/01/07 01:24:04 I've added the comment you suggested to the constr
+
+ ~HostSignalingManager();
+
+ // Gets signal strategy used for talking to the Chromoting bot.
Wez 2014/12/18 00:46:22 "Get the SignalStrategy to use to talk to..."
Łukasz Anforowicz 2014/12/18 19:02:34 Done.
+ // Return value is valid until |this| gets deleted.
Wez 2014/12/18 00:46:21 nit: Suggest: "The SignalStrategy remains owned by
Łukasz Anforowicz 2014/12/18 19:02:34 Done.
+ SignalStrategy* signal_strategy() { return signal_strategy_.get(); }
+
+ // Kicks off sending a heartbeat containing a host-offline-reason attribute.
+ //
+ // Will delete |this| once either the bot acks receiving the
+ // |host_offline_reason|, or the |timeout| is reached. Deleting
+ // |this| will release |network_task_runner_| and allow the host
+ // process to exit.
Wez 2014/12/18 00:46:21 You don't need the sentence re the task-runner. T
Łukasz Anforowicz 2014/12/18 19:02:34 ...
Wez 2014/12/19 22:05:37 Acknowledged.
+ void SendHostOfflineReasonAndDelete(const std::string& host_offline_reason,
+ const base::TimeDelta& timeout);
+
+ private:
+ HostSignalingManager(
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner,
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier,
+ scoped_ptr<SignalStrategy> signal_strategy,
+ scoped_ptr<SignalingConnector> signaling_connector,
+ scoped_ptr<HeartbeatSender> heartbeat_sender);
+
+ void OnAckOrTimeout(HeartbeatSender::AckOrTimeout ack_or_timeout);
+
+ // Order of fields below is important for destructing them in the right order.
Wez 2014/12/18 00:46:21 That cannot be true of |network_task_runner_|, so
Łukasz Anforowicz 2014/12/18 19:02:34 Arrrrgh... I had the teardown done explicitly in t
+ // - |heartbeat_sender_| and |signaling_connector_| have to be destructed
Wez 2014/12/18 00:46:22 s/destructed/destroyed/
Łukasz Anforowicz 2014/12/18 19:02:34 Done.
+ // before |signal_strategy_| because their destructors need to call
+ // signal_strategy_->RemoveListener(this)
+ // - |signaling_connector_| has to be destructed before
+ // |network_change_notifier_| because its destructor needs to deregister
+ // network change notifications
+ // - |network_task_runner_| is used by all the other fields and has to be
+ // destructed last.
Wez 2014/12/18 00:46:21 This comment doesn't make sense, since all you're
Łukasz Anforowicz 2014/12/18 19:02:34 Dropping a ref-count to network_task_runner will d
Wez 2014/12/19 22:05:37 That case should be safe - the AutoThreadTaskRunne
Łukasz Anforowicz 2015/01/07 01:24:04 Okay, I think I get it - dropping the reference wi
Wez 2015/01/09 02:55:45 Yes; sounds like we could have explained that more
Łukasz Anforowicz 2015/01/09 19:00:13 Acknowledged.
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
Wez 2014/12/18 00:46:21 You need to clarify what this task-runner is used
Łukasz Anforowicz 2014/12/18 19:02:34 This field keeps the process alive. I've added a
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
+ scoped_ptr<SignalStrategy> signal_strategy_;
+ scoped_ptr<SignalingConnector> signaling_connector_;
+ scoped_ptr<HeartbeatSender> heartbeat_sender_;
+
+ // HostSignalingManager object owns itself via |self_| field while
+ // SendHostOfflineReasonAndDelete is waiting for an ack or timeout.
+ HostSignalingManager* self_;
Wez 2014/12/18 00:46:21 This is a bare pointer so it doesn't have any effe
Łukasz Anforowicz 2014/12/18 19:02:34 Yes, I don't know what I was thinking... :-(
Wez 2014/12/19 22:05:37 Yeah, we all have code-review moments like that. :
Łukasz Anforowicz 2015/01/07 01:24:04 Acknowledged.
+
+ DISALLOW_COPY_AND_ASSIGN(HostSignalingManager);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698