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