summaryrefslogtreecommitdiffstats
path: root/cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h
diff options
context:
space:
mode:
authormaksymb@chromium.org <maksymb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-07 06:01:27 +0000
committermaksymb@chromium.org <maksymb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-07 06:01:27 +0000
commit98fae91a816298249923d30172e55f434687e1f9 (patch)
treea898ac7360d0f90fc938ad88b4ed388044724bc9 /cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h
parent06fb2c0371b9cfb5980351d45665d41fdcfae3b5 (diff)
downloadchromium_src-98fae91a816298249923d30172e55f434687e1f9.zip
chromium_src-98fae91a816298249923d30172e55f434687e1f9.tar.gz
chromium_src-98fae91a816298249923d30172e55f434687e1f9.tar.bz2
GCP2.0 Device: XMPP pings.
BUG= Review URL: https://chromiumcodereview.appspot.com/21916003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216107 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h')
-rw-r--r--cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h42
1 files changed, 36 insertions, 6 deletions
diff --git a/cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h b/cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h
index 843ba89..7c612fe 100644
--- a/cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h
+++ b/cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h
@@ -11,6 +11,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "jingle/notifier/listener/push_client_observer.h"
namespace base {
@@ -31,7 +32,9 @@ class PushClient;
} // namespace notifier
-class CloudPrintXmppListener: public notifier::PushClientObserver {
+class CloudPrintXmppListener
+ : public base::SupportsWeakPtr<CloudPrintXmppListener>,
+ public notifier::PushClientObserver {
public:
class Delegate {
public:
@@ -52,12 +55,13 @@ class CloudPrintXmppListener: public notifier::PushClientObserver {
// Invoked when local settings was updated.
virtual void OnXmppNewLocalSettings(const std::string& device_id) = 0;
- // Invoked when printer was deleted from server.
+ // Invoked when printer was deleted from the server.
virtual void OnXmppDeleteNotification(const std::string& device_id) = 0;
};
CloudPrintXmppListener(
const std::string& robot_email,
+ int standard_ping_interval,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
Delegate* delegate);
@@ -66,6 +70,9 @@ class CloudPrintXmppListener: public notifier::PushClientObserver {
// Connects to the server.
void Connect(const std::string& access_token);
+ // Update ping interval when new local_settings was received.
+ void set_standard_ping_interval(int interval);
+
private:
// notifier::PushClientObserver methods:
virtual void OnNotificationsEnabled() OVERRIDE;
@@ -75,18 +82,41 @@ class CloudPrintXmppListener: public notifier::PushClientObserver {
const notifier::Notification& notification) OVERRIDE;
virtual void OnPingResponse() OVERRIDE;
- // Is used for reconnection when number of retries is now exhausted.
- void ReconnectInternal();
+ // Stops listening and sending pings.
+ void Disconnect();
+
+ // Schedules ping (unless it was already scheduled).
+ void SchedulePing();
+
+ // Sends ping.
+ void SendPing();
+
+ // Checks if ping was received.
+ void OnPingTimeoutReached();
// Credentials:
std::string robot_email_;
std::string access_token_;
- scoped_refptr<net::URLRequestContextGetter> context_getter_;
-
// Internal listener.
scoped_ptr<notifier::PushClient> push_client_;
+ // Interval between pings in regular workflow.
+ int standard_ping_interval_;
+
+ // Number of timeouts posted to MessageLoop. Is used for controlling "fake"
+ // timeout calls.
+ int ping_timeouts_posted_;
+
+ // Number of responses awaiting from XMPP server. Is used for controlling
+ // number of failed pings.
+ int ping_responses_pending_;
+
+ // Is used for preventing multiple pings at the moment.
+ bool ping_scheduled_;
+
+ scoped_refptr<net::URLRequestContextGetter> context_getter_;
+
Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(CloudPrintXmppListener);