Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_FETCHER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_FETCHER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "net/url_request/url_fetcher_delegate.h" | |
| 13 | |
| 14 class GURL; | |
| 15 class Profile; | |
| 16 | |
| 17 namespace net { | |
| 18 class URLFetcher; | |
| 19 } // namespace net | |
| 20 | |
| 21 namespace arc { | |
| 22 | |
| 23 // Fetches ARC auth code. Fetching process starts automatically on creation. | |
| 24 class ArcAuthFetcher : public net::URLFetcherDelegate { | |
|
xiyuan
2016/01/26 23:37:05
Is it possible to extend GaiaAuthFetcher to suppor
khmel
2016/01/27 22:36:21
Honestly speaking I was thinking about this possib
| |
| 25 public: | |
| 26 // Returns a result of ARC auth code fetching. | |
| 27 class Delegate { | |
| 28 public: | |
| 29 // Called when code was fetched. | |
| 30 virtual void OnAuthCodeFetched(const std::string& code) = 0; | |
| 31 // Called when additional UI authorization is required. | |
| 32 virtual void OnAuthCodeNeedUI() = 0; | |
| 33 // Called when auth code cannot be received. | |
| 34 virtual void OnAuthCodeFailed() = 0; | |
| 35 }; | |
| 36 | |
| 37 ArcAuthFetcher(Profile* profile, Delegate* delegate); | |
| 38 ~ArcAuthFetcher() override; | |
| 39 | |
| 40 // net::URLFetcherDelegate overrides. | |
| 41 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 42 | |
| 43 // Helper function to compose target URL, also is used in test. | |
| 44 static GURL CreateURL(Profile* profile); | |
| 45 | |
| 46 private: | |
| 47 void FetchAuthCode(); | |
| 48 // Finds auth code in cookies. | |
| 49 static bool ParseAuthCode(const net::URLFetcher* source, std::string* code); | |
| 50 | |
| 51 // Unowned pointers. | |
| 52 Profile* profile_; | |
| 53 Delegate* delegate_; | |
| 54 | |
| 55 scoped_ptr<net::URLFetcher> auth_fetcher_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(ArcAuthFetcher); | |
| 58 }; | |
| 59 | |
| 60 } // namespace arc | |
| 61 | |
| 62 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_FETCHER_H_ | |
| OLD | NEW |