OLD | NEW |
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/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/chromeos/arc/arc_auth_context_delegate.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" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 void ArcAuthContext::OnRefreshTokenTimeout() { | 64 void ArcAuthContext::OnRefreshTokenTimeout() { |
65 VLOG(2) << "Failed to wait for refresh token."; | 65 VLOG(2) << "Failed to wait for refresh token."; |
66 token_service_->RemoveObserver(this); | 66 token_service_->RemoveObserver(this); |
67 delegate_->OnPrepareContextFailed(); | 67 delegate_->OnPrepareContextFailed(); |
68 } | 68 } |
69 | 69 |
70 void ArcAuthContext::OnMergeSessionSuccess(const std::string& data) { | 70 void ArcAuthContext::OnMergeSessionSuccess(const std::string& data) { |
71 context_prepared_ = true; | 71 context_prepared_ = true; |
| 72 ResetFetchers(); |
72 delegate_->OnContextReady(); | 73 delegate_->OnContextReady(); |
73 } | 74 } |
74 | 75 |
75 void ArcAuthContext::OnMergeSessionFailure( | 76 void ArcAuthContext::OnMergeSessionFailure( |
76 const GoogleServiceAuthError& error) { | 77 const GoogleServiceAuthError& error) { |
77 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; | 78 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; |
| 79 ResetFetchers(); |
78 delegate_->OnPrepareContextFailed(); | 80 delegate_->OnPrepareContextFailed(); |
79 } | 81 } |
80 | 82 |
81 void ArcAuthContext::OnUbertokenSuccess(const std::string& token) { | 83 void ArcAuthContext::OnUbertokenSuccess(const std::string& token) { |
| 84 ResetFetchers(); |
82 merger_fetcher_.reset( | 85 merger_fetcher_.reset( |
83 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, | 86 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, |
84 storage_partition_->GetURLRequestContext())); | 87 storage_partition_->GetURLRequestContext())); |
85 merger_fetcher_->StartMergeSession(token, std::string()); | 88 merger_fetcher_->StartMergeSession(token, std::string()); |
86 } | 89 } |
87 | 90 |
88 void ArcAuthContext::OnUbertokenFailure(const GoogleServiceAuthError& error) { | 91 void ArcAuthContext::OnUbertokenFailure(const GoogleServiceAuthError& error) { |
89 VLOG(2) << "Failed to get ubertoken " << error.ToString() << "."; | 92 VLOG(2) << "Failed to get ubertoken " << error.ToString() << "."; |
| 93 ResetFetchers(); |
90 delegate_->OnPrepareContextFailed(); | 94 delegate_->OnPrepareContextFailed(); |
91 } | 95 } |
92 | 96 |
93 void ArcAuthContext::PrepareContext() { | 97 void ArcAuthContext::PrepareContext() { |
94 if (context_prepared_) { | 98 if (context_prepared_) { |
95 delegate_->OnContextReady(); | 99 delegate_->OnContextReady(); |
96 return; | 100 return; |
97 } | 101 } |
98 | 102 |
99 token_service_->RemoveObserver(this); | 103 token_service_->RemoveObserver(this); |
100 refresh_token_timeout_.Stop(); | 104 refresh_token_timeout_.Stop(); |
101 | 105 |
102 if (!token_service_->RefreshTokenIsAvailable(account_id_)) { | 106 if (!token_service_->RefreshTokenIsAvailable(account_id_)) { |
103 token_service_->AddObserver(this); | 107 token_service_->AddObserver(this); |
104 refresh_token_timeout_.Start( | 108 refresh_token_timeout_.Start( |
105 FROM_HERE, base::TimeDelta::FromSeconds(kRefreshTokenTimeoutSeconds), | 109 FROM_HERE, base::TimeDelta::FromSeconds(kRefreshTokenTimeoutSeconds), |
106 this, &ArcAuthContext::OnRefreshTokenTimeout); | 110 this, &ArcAuthContext::OnRefreshTokenTimeout); |
107 return; | 111 return; |
108 } | 112 } |
109 | 113 |
110 StartFetchers(); | 114 StartFetchers(); |
111 } | 115 } |
112 | 116 |
113 void ArcAuthContext::StartFetchers() { | 117 void ArcAuthContext::StartFetchers() { |
114 DCHECK(!refresh_token_timeout_.IsRunning()); | 118 DCHECK(!refresh_token_timeout_.IsRunning()); |
115 merger_fetcher_.reset(); | 119 ResetFetchers(); |
116 ubertoken_fetcher_.reset( | 120 ubertoken_fetcher_.reset( |
117 new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource, | 121 new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource, |
118 storage_partition_->GetURLRequestContext())); | 122 storage_partition_->GetURLRequestContext())); |
119 ubertoken_fetcher_->StartFetchingToken(account_id_); | 123 ubertoken_fetcher_->StartFetchingToken(account_id_); |
120 } | 124 } |
121 | 125 |
| 126 void ArcAuthContext::ResetFetchers() { |
| 127 merger_fetcher_.reset(); |
| 128 ubertoken_fetcher_.reset(); |
| 129 } |
| 130 |
| 131 net::URLRequestContextGetter* ArcAuthContext::GetURLRequestContext() { |
| 132 DCHECK(context_prepared_); |
| 133 return storage_partition_->GetURLRequestContext(); |
| 134 } |
| 135 |
122 } // namespace arc | 136 } // namespace arc |
OLD | NEW |