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

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