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

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

Issue 1684063002: Add ArcEnabled policy implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@26869593
Patch Set: Added browser test. Created 4 years, 10 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_service.h" 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 profile_ = profile; 128 profile_ = profile;
129 // Reuse storage used in ARC OptIn platform app. 129 // Reuse storage used in ARC OptIn platform app.
130 const std::string site_url = 130 const std::string site_url =
131 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, 131 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme,
132 kArcSupportExtensionId, kArcSupportStorageId); 132 kArcSupportExtensionId, kArcSupportStorageId);
133 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( 133 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite(
134 profile_, GURL(site_url)); 134 profile_, GURL(site_url));
135 CHECK(storage_partition_); 135 CHECK(storage_partition_);
136 136
137 // In case UI is disabled we assume that ARC is opted-in. 137 pref_change_registrar_.Init(profile_->GetPrefs());
138 if (!IsOptInVerificationDisabled()) { 138 pref_change_registrar_.Add(
139 pref_change_registrar_.Init(profile_->GetPrefs()); 139 prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged,
140 pref_change_registrar_.Add( 140 base::Unretained(this)));
141 prefs::kArcEnabled, 141 OnOptInPreferenceChanged();
142 base::Bind(&ArcAuthService::OnOptInPreferenceChanged,
143 base::Unretained(this)));
144 OnOptInPreferenceChanged();
145 } else {
146 auth_code_.clear();
147 ArcBridgeService::Get()->HandleStartup();
148 SetState(State::ENABLE);
149 }
150 } 142 }
151 143
152 void ArcAuthService::Shutdown() { 144 void ArcAuthService::Shutdown() {
153 ShutdownBridgeAndCloseUI(); 145 ShutdownBridgeAndCloseUI();
154 profile_ = nullptr; 146 profile_ = nullptr;
155 pref_change_registrar_.RemoveAll(); 147 pref_change_registrar_.RemoveAll();
156 } 148 }
157 149
158 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { 150 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) {
159 DCHECK(thread_checker_.CalledOnValidThread()); 151 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 29 matching lines...) Expand all
189 VLOG(2) << "Failed to get ubertoken " << error.ToString() << "."; 181 VLOG(2) << "Failed to get ubertoken " << error.ToString() << ".";
190 OnAuthCodeFailed(); 182 OnAuthCodeFailed();
191 } 183 }
192 184
193 void ArcAuthService::OnOptInPreferenceChanged() { 185 void ArcAuthService::OnOptInPreferenceChanged() {
194 DCHECK(thread_checker_.CalledOnValidThread()); 186 DCHECK(thread_checker_.CalledOnValidThread());
195 DCHECK(profile_); 187 DCHECK(profile_);
196 188
197 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { 189 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) {
198 if (state_ != State::ENABLE) { 190 if (state_ != State::ENABLE) {
199 CloseUI();
200 auth_code_.clear(); 191 auth_code_.clear();
201 SetState(State::FETCHING_CODE); 192 if (!IsOptInVerificationDisabled()) {
202 FetchAuthCode(); 193 CloseUI();
194 SetState(State::FETCHING_CODE);
195 FetchAuthCode();
196 } else {
197 ArcBridgeService::Get()->HandleStartup();
198 SetState(State::ENABLE);
199 }
203 } 200 }
204 } else { 201 } else {
205 ShutdownBridgeAndCloseUI(); 202 ShutdownBridgeAndCloseUI();
206 } 203 }
207 } 204 }
208 205
209 void ArcAuthService::ShutdownBridgeAndCloseUI() { 206 void ArcAuthService::ShutdownBridgeAndCloseUI() {
210 CloseUI(); 207 CloseUI();
211 auth_fetcher_.reset(); 208 auth_fetcher_.reset();
212 ubertoken_fethcher_.reset(); 209 ubertoken_fethcher_.reset();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 return os << kStateNoCode; 310 return os << kStateNoCode;
314 case ArcAuthService::State::ENABLE: 311 case ArcAuthService::State::ENABLE:
315 return os << kStateEnable; 312 return os << kStateEnable;
316 default: 313 default:
317 NOTREACHED(); 314 NOTREACHED();
318 return os; 315 return os;
319 } 316 }
320 } 317 }
321 318
322 } // namespace arc 319 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698