summaryrefslogtreecommitdiffstats
path: root/chrome/service/remoting/remoting_directory_service.h
blob: 43807bdda151ae131e1cbd4a5641d100ebc3f175 (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
// Copyright (c) 2010 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 CHROME_SERVICE_REMOTING_REMOTING_DIRECTORY_SERVICE_H_
#define CHROME_SERVICE_REMOTING_REMOTING_DIRECTORY_SERVICE_H_

#include <string>

#include "base/scoped_ptr.h"
#include "chrome/common/net/url_fetcher.h"
#include "googleurl/src/gurl.h"

namespace remoting {
class HostKeyPair;
}  // namespace remoting

// A class to provide access to the remoting directory service.
// TODO(hclam): Should implement this in Javascript.
class RemotingDirectoryService : public URLFetcher::Delegate {
 public:
  // Client to receive events from the directory service.
  class Client {
   public:
    virtual ~Client() {}

    // Called when a remoting host was added.
    virtual void OnRemotingHostAdded() {}

    // Called when the last operation has failed.
    virtual void OnRemotingDirectoryError() {}
  };

  RemotingDirectoryService(Client* client);
  ~RemotingDirectoryService();

  // Add this computer as host. Use the token for authentication.
  // TODO(hclam): Need more information for this method call.
  void AddHost(const std::string& token);

  // Cancel the last requested operation.
  void CancelRequest();

  // URLFetcher::Delegate implementation.
  virtual void OnURLFetchComplete(const URLFetcher* source,
                                  const GURL& url,
                                  const URLRequestStatus& status,
                                  int response_code,
                                  const ResponseCookies& cookies,
                                  const std::string& data);

  const std::string& host_id() const { return host_id_; }
  const std::string& host_name() const { return host_name_; }
  remoting::HostKeyPair* host_key_pair() const {
    return host_key_pair_.get();
  }

 private:
  Client* client_;
  scoped_ptr<URLFetcher> fetcher_;

  // True if a URL request has made and response is pending.
  bool request_pending_;

  // Host key generated during host registration.
  scoped_ptr<remoting::HostKeyPair> host_key_pair_;

  // Host info used for registration.
  std::string host_id_;
  std::string host_name_;

  DISALLOW_COPY_AND_ASSIGN(RemotingDirectoryService);
};

#endif // CHROME_SERVICE_REMOTING_REMOTING_DIRECTORY_SERVICE_H_