summaryrefslogtreecommitdiffstats
path: root/chrome/service/gaia/service_gaia_authenticator.h
blob: 2010690dba0e0358135e9d8e810217b4ac54ddd1 (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
// Copyright (c) 2011 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_GAIA_SERVICE_GAIA_AUTHENTICATOR_H_
#define CHROME_SERVICE_GAIA_SERVICE_GAIA_AUTHENTICATOR_H_
#pragma once

#include <string>

#include "base/memory/ref_counted.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/common/net/url_fetcher.h"
#include "chrome/common/net/gaia/gaia_authenticator.h"

namespace base {
class MessageLoopProxy;
}

// A GaiaAuthenticator implementation to be used in the service process (where
// we cannot rely on the existence of a Profile)
class ServiceGaiaAuthenticator
    : public base::RefCountedThreadSafe<ServiceGaiaAuthenticator>,
      public URLFetcher::Delegate,
      public gaia::GaiaAuthenticator {
 public:
  ServiceGaiaAuthenticator(const std::string& user_agent,
                           const std::string& service_id,
                           const std::string& gaia_url,
                           base::MessageLoopProxy* io_message_loop_proxy);
  ~ServiceGaiaAuthenticator();

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

 protected:
  // GaiaAuthenticator overrides.
  virtual bool Post(const GURL& url, const std::string& post_body,
                    unsigned long* response_code, std::string* response_body);
  virtual int GetBackoffDelaySeconds(int current_backoff_delay);

 private:
  void DoPost(const GURL& post_url, const std::string& post_body);

  base::WaitableEvent http_post_completed_;
  scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
  int http_response_code_;
  std::string response_data_;

  DISALLOW_COPY_AND_ASSIGN(ServiceGaiaAuthenticator);
};

#endif  // CHROME_SERVICE_GAIA_SERVICE_GAIA_AUTHENTICATOR_H_