Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_code_fetcher.h

Issue 2498363002: Remove delegates from ArcAuthCodeFetcher and ArcAuthContext. (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/BUILD.gn ('k') | chrome/browser/chromeos/arc/arc_auth_code_fetcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/chromeos/arc/arc_auth_context.h"
12 #include "google_apis/gaia/oauth2_token_service.h" 15 #include "google_apis/gaia/oauth2_token_service.h"
13 #include "net/url_request/url_fetcher_delegate.h" 16 #include "net/url_request/url_fetcher_delegate.h"
14 17
15 class Profile; 18 class Profile;
16 19
17 namespace net { 20 namespace net {
18 class URLFetcher; 21 class URLFetcher;
19 class URLRequestContextGetter; 22 class URLRequestContextGetter;
20 } 23 }
21 24
22 namespace arc { 25 namespace arc {
23 26
24 class ArcAuthCodeFetcherDelegate; 27 // The instance is not reusable, so for each Fetch(), the instance must be
25 28 // re-created. Deleting the instance cancels inflight operation.
26 class ArcAuthCodeFetcher : public OAuth2TokenService::Consumer, 29 class ArcAuthCodeFetcher : public OAuth2TokenService::Consumer,
27 public net::URLFetcherDelegate { 30 public net::URLFetcherDelegate {
28 public: 31 public:
29 ArcAuthCodeFetcher(ArcAuthCodeFetcherDelegate* delegate, 32 ArcAuthCodeFetcher(Profile* profile,
30 net::URLRequestContextGetter* request_context_getter, 33 ArcAuthContext* context,
31 Profile* profile,
32 const std::string& auth_endpoint); 34 const std::string& auth_endpoint);
33 ~ArcAuthCodeFetcher() override; 35 ~ArcAuthCodeFetcher() override;
34 36
37 // Starts to fetch the token. On success fetched |auth_token| is passed.
38 // On error, auth_token is empty.
39 using FetchCallback = base::Callback<void(const std::string& auth_token)>;
40 void Fetch(const FetchCallback& callback);
41
35 // OAuth2TokenService::Consumer: 42 // OAuth2TokenService::Consumer:
36 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 43 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
37 const std::string& access_token, 44 const std::string& access_token,
38 const base::Time& expiration_time) override; 45 const base::Time& expiration_time) override;
39 void OnGetTokenFailure(const OAuth2TokenService::Request* request, 46 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
40 const GoogleServiceAuthError& error) override; 47 const GoogleServiceAuthError& error) override;
41 48
42 // net::URLFetcherDelegate: 49 // net::URLFetcherDelegate:
43 void OnURLFetchComplete(const net::URLFetcher* source) override; 50 void OnURLFetchComplete(const net::URLFetcher* source) override;
44 51
45 private: 52 private:
46 void ResetFetchers(); 53 void ResetFetchers();
54 void OnPrepared(net::URLRequestContextGetter* request_context_getter);
47 55
48 // Unowned pointers. 56 // Unowned pointers.
49 ArcAuthCodeFetcherDelegate* const delegate_;
50 net::URLRequestContextGetter* const request_context_getter_;
51 Profile* const profile_; 57 Profile* const profile_;
58 ArcAuthContext* const context_;
59 net::URLRequestContextGetter* request_context_getter_ = nullptr;
52 60
53 // URL to request auth code. 61 // URL to request auth code.
54 const std::string auth_endpoint_; 62 const std::string auth_endpoint_;
55 63
64 FetchCallback callback_;
65
56 std::unique_ptr<OAuth2TokenService::Request> login_token_request_; 66 std::unique_ptr<OAuth2TokenService::Request> login_token_request_;
57 std::unique_ptr<net::URLFetcher> auth_code_fetcher_; 67 std::unique_ptr<net::URLFetcher> auth_code_fetcher_;
58 68
69 base::WeakPtrFactory<ArcAuthCodeFetcher> weak_ptr_factory_;
70
59 DISALLOW_COPY_AND_ASSIGN(ArcAuthCodeFetcher); 71 DISALLOW_COPY_AND_ASSIGN(ArcAuthCodeFetcher);
60 }; 72 };
61 73
62 } // namespace arc 74 } // namespace arc
63 75
64 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ 76 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/BUILD.gn ('k') | chrome/browser/chromeos/arc/arc_auth_code_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698