summaryrefslogtreecommitdiffstats
path: root/cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h
blob: 843ba89e32574e2dc9b93ebafa744d9eb7ea8d60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2013 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 CLOUD_PRINT_GCP20_PROTOTYPE_CLOUD_PRINT_XMPP_LISTENER_H_
#define CLOUD_PRINT_GCP20_PROTOTYPE_CLOUD_PRINT_XMPP_LISTENER_H_

#include <string>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "jingle/notifier/listener/push_client_observer.h"

namespace base {

class SingleThreadTaskRunner;

}  // namespace base

namespace net {

class URLRequestContextGetter;

}  // namespace net

namespace notifier {

class PushClient;

}  // namespace notifier

class CloudPrintXmppListener: public notifier::PushClientObserver {
 public:
  class Delegate {
   public:
    virtual ~Delegate() {}

    // Invoked when XMPP connection was established.
    virtual void OnXmppConnected() = 0;

    // Invoked when server rejected our credentials.
    virtual void OnXmppAuthError() = 0;

    // Invoked when server is unavailable.
    virtual void OnXmppNetworkError() = 0;

    // Invoked when new printjob was received.
    virtual void OnXmppNewPrintJob(const std::string& device_id) = 0;

    // Invoked when local settings was updated.
    virtual void OnXmppNewLocalSettings(const std::string& device_id) = 0;

    // Invoked when printer was deleted from server.
    virtual void OnXmppDeleteNotification(const std::string& device_id) = 0;
  };

  CloudPrintXmppListener(
      const std::string& robot_email,
      scoped_refptr<base::SingleThreadTaskRunner> task_runner,
      Delegate* delegate);

  virtual ~CloudPrintXmppListener();

  // Connects to the server.
  void Connect(const std::string& access_token);

 private:
  // notifier::PushClientObserver methods:
  virtual void OnNotificationsEnabled() OVERRIDE;
  virtual void OnNotificationsDisabled(
      notifier::NotificationsDisabledReason reason) OVERRIDE;
  virtual void OnIncomingNotification(
      const notifier::Notification& notification) OVERRIDE;
  virtual void OnPingResponse() OVERRIDE;

  // Is used for reconnection when number of retries is now exhausted.
  void ReconnectInternal();

  // Credentials:
  std::string robot_email_;
  std::string access_token_;

  scoped_refptr<net::URLRequestContextGetter> context_getter_;

  // Internal listener.
  scoped_ptr<notifier::PushClient> push_client_;

  Delegate* delegate_;

  DISALLOW_COPY_AND_ASSIGN(CloudPrintXmppListener);
};

#endif  // CLOUD_PRINT_GCP20_PROTOTYPE_CLOUD_PRINT_XMPP_LISTENER_H_