1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef REMOTING_HOST_SETUP_WIN_AUTH_CODE_GETTER_H
6#define REMOTING_HOST_SETUP_WIN_AUTH_CODE_GETTER_H
7
8#include <ole2.h>
9#include <exdisp.h>
10
11#include <string>
12
13#include "base/callback.h"
14#include "base/threading/non_thread_safe.h"
15#include "base/timer/timer.h"
16#include "base/win/scoped_comptr.h"
17
18namespace remoting {
19
20// A class for getting an OAuth authorization code.
21class AuthCodeGetter : public base::NonThreadSafe {
22 public:
23  AuthCodeGetter();
24  ~AuthCodeGetter();
25
26  // Starts a browser and navigates it to a URL that starts an Installed
27  // Application OAuth flow. |on_auth_code| will be called with an
28  // authorization code, or an empty string on error.
29  void GetAuthCode(base::Callback<void(const std::string&)> on_auth_code);
30
31 private:
32  // Starts a timer used to poll the browser's URL.
33  void StartTimer();
34  // Called when that timer fires.
35  void OnTimer();
36  // Returns whether to stop polling the browser's URL. If true, then
37  // |auth_code| is an authorization code, or the empty string on an error.
38  bool TestBrowserUrl(std::string* auth_code);
39  // Kills the browser.
40  void KillBrowser();
41
42  // The authorization code callback.
43  base::Callback<void(const std::string&)> on_auth_code_;
44  // The browser through which the user requests an authorization code.
45  base::win::ScopedComPtr<IWebBrowser2, &IID_IWebBrowser2> browser_;
46  // A timer used to poll the browser's URL.
47  base::OneShotTimer<AuthCodeGetter> timer_;
48  // The interval at which the timer fires.
49  base::TimeDelta timer_interval_;
50
51  DISALLOW_COPY_AND_ASSIGN(AuthCodeGetter);
52};
53
54}  // namespace remoting
55
56#endif  // REMOTING_HOST_SETUP_WIN_AUTH_CODE_GETTER_H
57