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

Side by Side Diff: chrome/browser/chromeos/arc/auth/arc_background_auth_code_fetcher.h

Issue 2547073002: Fix race issue in ArcAuthService. (Closed)
Patch Set: Address comments Created 4 years 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
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_AUTH_ARC_BACKGROUND_AUTH_CODE_FETCHER_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_AUTH_ARC_BACKGROUND_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/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/chromeos/arc/arc_auth_context.h" 14 #include "chrome/browser/chromeos/arc/arc_auth_context.h"
15 #include "chrome/browser/chromeos/arc/auth/arc_auth_code_fetcher.h"
15 #include "google_apis/gaia/oauth2_token_service.h" 16 #include "google_apis/gaia/oauth2_token_service.h"
16 #include "net/url_request/url_fetcher_delegate.h" 17 #include "net/url_request/url_fetcher_delegate.h"
17 18
18 class Profile; 19 class Profile;
19 20
20 namespace net { 21 namespace net {
21 class URLFetcher; 22 class URLFetcher;
22 class URLRequestContextGetter; 23 class URLRequestContextGetter;
23 } 24 }
24 25
25 namespace arc { 26 namespace arc {
26 27
27 // The instance is not reusable, so for each Fetch(), the instance must be 28 // The instance is not reusable, so for each Fetch(), the instance must be
28 // re-created. Deleting the instance cancels inflight operation. 29 // re-created. Deleting the instance cancels inflight operation.
29 class ArcAuthCodeFetcher : public OAuth2TokenService::Consumer, 30 class ArcBackgroundAuthCodeFetcher : public ArcAuthCodeFetcher,
30 public net::URLFetcherDelegate { 31 public OAuth2TokenService::Consumer,
32 public net::URLFetcherDelegate {
31 public: 33 public:
32 ArcAuthCodeFetcher(Profile* profile, ArcAuthContext* context); 34 ArcBackgroundAuthCodeFetcher(Profile* profile, ArcAuthContext* context);
33 ~ArcAuthCodeFetcher() override; 35 ~ArcBackgroundAuthCodeFetcher() override;
34 36
35 // Starts to fetch the token. On success fetched |auth_token| is passed. 37 // ArcAuthCodeFetcher:
36 // On error, auth_token is empty. 38 void Fetch(const FetchCallback& callback) override;
37 using FetchCallback = base::Callback<void(const std::string& auth_token)>; 39
38 void Fetch(const FetchCallback& callback); 40 private:
41 void ResetFetchers();
42 void OnPrepared(net::URLRequestContextGetter* request_context_getter);
39 43
40 // OAuth2TokenService::Consumer: 44 // OAuth2TokenService::Consumer:
41 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 45 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
42 const std::string& access_token, 46 const std::string& access_token,
43 const base::Time& expiration_time) override; 47 const base::Time& expiration_time) override;
44 void OnGetTokenFailure(const OAuth2TokenService::Request* request, 48 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
45 const GoogleServiceAuthError& error) override; 49 const GoogleServiceAuthError& error) override;
46 50
47 // net::URLFetcherDelegate: 51 // net::URLFetcherDelegate:
48 void OnURLFetchComplete(const net::URLFetcher* source) override; 52 void OnURLFetchComplete(const net::URLFetcher* source) override;
49 53
50 private:
51 void ResetFetchers();
52 void OnPrepared(net::URLRequestContextGetter* request_context_getter);
53
54 // Unowned pointers. 54 // Unowned pointers.
55 Profile* const profile_; 55 Profile* const profile_;
56 ArcAuthContext* const context_; 56 ArcAuthContext* const context_;
57 net::URLRequestContextGetter* request_context_getter_ = nullptr; 57 net::URLRequestContextGetter* request_context_getter_ = nullptr;
58 58
59 FetchCallback callback_; 59 FetchCallback callback_;
60 60
61 std::unique_ptr<OAuth2TokenService::Request> login_token_request_; 61 std::unique_ptr<OAuth2TokenService::Request> login_token_request_;
62 std::unique_ptr<net::URLFetcher> auth_code_fetcher_; 62 std::unique_ptr<net::URLFetcher> auth_code_fetcher_;
63 63
64 base::WeakPtrFactory<ArcAuthCodeFetcher> weak_ptr_factory_; 64 base::WeakPtrFactory<ArcBackgroundAuthCodeFetcher> weak_ptr_factory_;
65 65
66 DISALLOW_COPY_AND_ASSIGN(ArcAuthCodeFetcher); 66 DISALLOW_COPY_AND_ASSIGN(ArcBackgroundAuthCodeFetcher);
67 }; 67 };
68 68
69 } // namespace arc 69 } // namespace arc
70 70
71 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ 71 #endif // CHROME_BROWSER_CHROMEOS_ARC_AUTH_ARC_BACKGROUND_AUTH_CODE_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698