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

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_context.cc

Issue 2498363002: Remove delegates from ArcAuthCodeFetcher and ArcAuthContext. (Closed)
Patch Set: Address comments. 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
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 #include "chrome/browser/chromeos/arc/arc_auth_context.h" 5 #include "chrome/browser/chromeos/arc/arc_auth_context.h"
6 6
7 #include "base/callback_helpers.h"
7 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/chromeos/arc/arc_auth_context_delegate.h"
9 #include "chrome/browser/chromeos/arc/arc_support_host.h" 9 #include "chrome/browser/chromeos/arc/arc_support_host.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/signin/signin_manager_factory.h" 12 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "components/signin/core/browser/profile_oauth2_token_service.h" 13 #include "components/signin/core/browser/profile_oauth2_token_service.h"
14 #include "components/signin/core/browser/signin_manager_base.h" 14 #include "components/signin/core/browser/signin_manager_base.h"
15 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/storage_partition.h" 16 #include "content/public/browser/storage_partition.h"
17 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
18 #include "google_apis/gaia/gaia_auth_fetcher.h" 18 #include "google_apis/gaia/gaia_auth_fetcher.h"
19 #include "google_apis/gaia/gaia_constants.h" 19 #include "google_apis/gaia/gaia_constants.h"
20 20
21 namespace arc { 21 namespace arc {
22 22
23 namespace { 23 namespace {
24 24
25 constexpr int kRefreshTokenTimeoutSeconds = 10; 25 constexpr base::TimeDelta kRefreshTokenTimeout =
26 base::TimeDelta::FromSeconds(10);
26 27
27 } // namespace 28 } // namespace
28 29
29 ArcAuthContext::ArcAuthContext(ArcAuthContextDelegate* delegate, 30 ArcAuthContext::ArcAuthContext(Profile* profile) {
30 Profile* profile)
31 : delegate_(delegate) {
32 // Reuse storage used in ARC OptIn platform app. 31 // Reuse storage used in ARC OptIn platform app.
33 const std::string site_url = base::StringPrintf( 32 const std::string site_url = base::StringPrintf(
34 "%s://%s/persist?%s", content::kGuestScheme, ArcSupportHost::kHostAppId, 33 "%s://%s/persist?%s", content::kGuestScheme, ArcSupportHost::kHostAppId,
35 ArcSupportHost::kStorageId); 34 ArcSupportHost::kStorageId);
36 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( 35 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite(
37 profile, GURL(site_url)); 36 profile, GURL(site_url));
38 CHECK(storage_partition_); 37 CHECK(storage_partition_);
39 38
40 // Get token service and account ID to fetch auth tokens. 39 // Get token service and account ID to fetch auth tokens.
41 token_service_ = ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 40 token_service_ = ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
(...skipping 15 matching lines...) Expand all
57 56
58 void ArcAuthContext::OnRefreshTokensLoaded() { 57 void ArcAuthContext::OnRefreshTokensLoaded() {
59 token_service_->RemoveObserver(this); 58 token_service_->RemoveObserver(this);
60 refresh_token_timeout_.Stop(); 59 refresh_token_timeout_.Stop();
61 StartFetchers(); 60 StartFetchers();
62 } 61 }
63 62
64 void ArcAuthContext::OnRefreshTokenTimeout() { 63 void ArcAuthContext::OnRefreshTokenTimeout() {
65 VLOG(2) << "Failed to wait for refresh token."; 64 VLOG(2) << "Failed to wait for refresh token.";
66 token_service_->RemoveObserver(this); 65 token_service_->RemoveObserver(this);
67 delegate_->OnPrepareContextFailed(); 66 base::ResetAndReturn(&callback_).Run(nullptr);
68 } 67 }
69 68
70 void ArcAuthContext::OnMergeSessionSuccess(const std::string& data) { 69 void ArcAuthContext::OnMergeSessionSuccess(const std::string& data) {
71 context_prepared_ = true; 70 context_prepared_ = true;
72 ResetFetchers(); 71 ResetFetchers();
73 delegate_->OnContextReady(); 72 base::ResetAndReturn(&callback_)
73 .Run(storage_partition_->GetURLRequestContext());
74 } 74 }
75 75
76 void ArcAuthContext::OnMergeSessionFailure( 76 void ArcAuthContext::OnMergeSessionFailure(
77 const GoogleServiceAuthError& error) { 77 const GoogleServiceAuthError& error) {
78 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; 78 VLOG(2) << "Failed to merge gaia session " << error.ToString() << ".";
79 ResetFetchers(); 79 ResetFetchers();
80 delegate_->OnPrepareContextFailed(); 80 base::ResetAndReturn(&callback_).Run(nullptr);
81 } 81 }
82 82
83 void ArcAuthContext::OnUbertokenSuccess(const std::string& token) { 83 void ArcAuthContext::OnUbertokenSuccess(const std::string& token) {
84 ResetFetchers(); 84 ResetFetchers();
85 merger_fetcher_.reset( 85 merger_fetcher_.reset(
86 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, 86 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource,
87 storage_partition_->GetURLRequestContext())); 87 storage_partition_->GetURLRequestContext()));
88 merger_fetcher_->StartMergeSession(token, std::string()); 88 merger_fetcher_->StartMergeSession(token, std::string());
89 base::ResetAndReturn(&callback_).Run(nullptr);
Luis Héctor Chávez 2016/11/16 03:29:58 I'm still a bit confused as to why this was added.
hidehiko 2016/11/16 04:09:38 Oops... So my mistake was not forgetting L80 callb
89 } 90 }
90 91
91 void ArcAuthContext::OnUbertokenFailure(const GoogleServiceAuthError& error) { 92 void ArcAuthContext::OnUbertokenFailure(const GoogleServiceAuthError& error) {
92 VLOG(2) << "Failed to get ubertoken " << error.ToString() << "."; 93 VLOG(2) << "Failed to get ubertoken " << error.ToString() << ".";
93 ResetFetchers(); 94 ResetFetchers();
94 delegate_->OnPrepareContextFailed(); 95 base::ResetAndReturn(&callback_).Run(nullptr);
95 } 96 }
96 97
97 void ArcAuthContext::PrepareContext() { 98 void ArcAuthContext::Prepare(const PrepareCallback& callback) {
98 if (context_prepared_) { 99 if (context_prepared_) {
99 delegate_->OnContextReady(); 100 callback.Run(storage_partition_->GetURLRequestContext());
100 return; 101 return;
101 } 102 }
102 103
104 callback_ = callback;
103 token_service_->RemoveObserver(this); 105 token_service_->RemoveObserver(this);
104 refresh_token_timeout_.Stop(); 106 refresh_token_timeout_.Stop();
105 107
106 if (!token_service_->RefreshTokenIsAvailable(account_id_)) { 108 if (!token_service_->RefreshTokenIsAvailable(account_id_)) {
107 token_service_->AddObserver(this); 109 token_service_->AddObserver(this);
108 refresh_token_timeout_.Start( 110 refresh_token_timeout_.Start(FROM_HERE, kRefreshTokenTimeout, this,
109 FROM_HERE, base::TimeDelta::FromSeconds(kRefreshTokenTimeoutSeconds), 111 &ArcAuthContext::OnRefreshTokenTimeout);
110 this, &ArcAuthContext::OnRefreshTokenTimeout);
111 return; 112 return;
112 } 113 }
113 114
114 StartFetchers(); 115 StartFetchers();
115 } 116 }
116 117
117 void ArcAuthContext::StartFetchers() { 118 void ArcAuthContext::StartFetchers() {
118 DCHECK(!refresh_token_timeout_.IsRunning()); 119 DCHECK(!refresh_token_timeout_.IsRunning());
119 ResetFetchers(); 120 ResetFetchers();
120 ubertoken_fetcher_.reset( 121 ubertoken_fetcher_.reset(
121 new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource, 122 new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource,
122 storage_partition_->GetURLRequestContext())); 123 storage_partition_->GetURLRequestContext()));
123 ubertoken_fetcher_->StartFetchingToken(account_id_); 124 ubertoken_fetcher_->StartFetchingToken(account_id_);
124 } 125 }
125 126
126 void ArcAuthContext::ResetFetchers() { 127 void ArcAuthContext::ResetFetchers() {
127 merger_fetcher_.reset(); 128 merger_fetcher_.reset();
128 ubertoken_fetcher_.reset(); 129 ubertoken_fetcher_.reset();
129 } 130 }
130 131
131 net::URLRequestContextGetter* ArcAuthContext::GetURLRequestContext() {
132 DCHECK(context_prepared_);
133 return storage_partition_->GetURLRequestContext();
134 }
135
136 } // namespace arc 132 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_context.h ('k') | chrome/browser/chromeos/arc/arc_auth_context_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698