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/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.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 base::TimeDelta kRefreshTokenTimeout = | 25 constexpr base::TimeDelta kRefreshTokenTimeout = |
26 base::TimeDelta::FromSeconds(10); | 26 base::TimeDelta::FromSeconds(10); |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 ArcAuthContext::ArcAuthContext(Profile* profile) { | 30 ArcAuthContext::ArcAuthContext(Profile* profile) : profile_(profile) { |
31 // Reuse storage used in ARC OptIn platform app. | 31 // Reuse storage used in ARC OptIn platform app. |
32 const std::string site_url = base::StringPrintf( | 32 const std::string site_url = base::StringPrintf( |
33 "%s://%s/persist?%s", content::kGuestScheme, ArcSupportHost::kHostAppId, | 33 "%s://%s/persist?%s", content::kGuestScheme, ArcSupportHost::kHostAppId, |
34 ArcSupportHost::kStorageId); | 34 ArcSupportHost::kStorageId); |
35 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( | 35 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( |
36 profile, GURL(site_url)); | 36 profile_, GURL(site_url)); |
37 CHECK(storage_partition_); | 37 CHECK(storage_partition_); |
38 | 38 |
39 // Get token service and account ID to fetch auth tokens. | 39 // Get token service and account ID to fetch auth tokens. |
40 token_service_ = ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 40 token_service_ = ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
41 const SigninManagerBase* const signin_manager = | 41 CHECK(token_service_); |
42 SigninManagerFactory::GetForProfile(profile); | |
43 CHECK(token_service_ && signin_manager); | |
44 account_id_ = signin_manager->GetAuthenticatedAccountId(); | |
khmel
2017/03/15 18:12:22
This is race condition on Chrome restart on crash.
xiyuan
2017/03/15 19:34:30
Not sure I understand why there is a race. SigninM
khmel
2017/03/15 19:39:05
InitProfilePreferences is not called in case of cr
xiyuan
2017/03/15 19:53:16
InitProfilePreferences stores the info in SigninMa
khmel
2017/03/16 02:07:24
So, I investigated this case and can confirm my su
xiyuan
2017/03/16 04:37:42
Thanks for looking into this.
I would prefer to a
khmel
2017/03/16 15:41:42
Yes, this works.
| |
45 } | 42 } |
46 | 43 |
47 ArcAuthContext::~ArcAuthContext() { | 44 ArcAuthContext::~ArcAuthContext() { |
48 token_service_->RemoveObserver(this); | 45 token_service_->RemoveObserver(this); |
49 } | 46 } |
50 | 47 |
51 void ArcAuthContext::Prepare(const PrepareCallback& callback) { | 48 void ArcAuthContext::Prepare(const PrepareCallback& callback) { |
52 if (context_prepared_) { | 49 if (context_prepared_) { |
53 callback.Run(storage_partition_->GetURLRequestContext()); | 50 callback.Run(storage_partition_->GetURLRequestContext()); |
54 return; | 51 return; |
55 } | 52 } |
56 | 53 |
54 const SigninManagerBase* const signin_manager = | |
55 SigninManagerFactory::GetForProfile(profile_); | |
56 CHECK(signin_manager); | |
57 account_id_ = signin_manager->GetAuthenticatedAccountId(); | |
58 DCHECK(!account_id_.empty()); | |
59 | |
57 callback_ = callback; | 60 callback_ = callback; |
58 token_service_->RemoveObserver(this); | 61 token_service_->RemoveObserver(this); |
59 refresh_token_timeout_.Stop(); | 62 refresh_token_timeout_.Stop(); |
60 | 63 |
61 if (!token_service_->RefreshTokenIsAvailable(account_id_)) { | 64 if (!token_service_->RefreshTokenIsAvailable(account_id_)) { |
62 token_service_->AddObserver(this); | 65 token_service_->AddObserver(this); |
63 refresh_token_timeout_.Start(FROM_HERE, kRefreshTokenTimeout, this, | 66 refresh_token_timeout_.Start(FROM_HERE, kRefreshTokenTimeout, this, |
64 &ArcAuthContext::OnRefreshTokenTimeout); | 67 &ArcAuthContext::OnRefreshTokenTimeout); |
65 return; | 68 return; |
66 } | 69 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 ResetFetchers(); | 125 ResetFetchers(); |
123 base::ResetAndReturn(&callback_).Run(nullptr); | 126 base::ResetAndReturn(&callback_).Run(nullptr); |
124 } | 127 } |
125 | 128 |
126 void ArcAuthContext::ResetFetchers() { | 129 void ArcAuthContext::ResetFetchers() { |
127 merger_fetcher_.reset(); | 130 merger_fetcher_.reset(); |
128 ubertoken_fetcher_.reset(); | 131 ubertoken_fetcher_.reset(); |
129 } | 132 } |
130 | 133 |
131 } // namespace arc | 134 } // namespace arc |
OLD | NEW |