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

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: Fixed GuestModeOptionsUIBrowserTest.testSections Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/policy/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 187
188 profile_ = profile; 188 profile_ = profile;
189 // Reuse storage used in ARC OptIn platform app. 189 // Reuse storage used in ARC OptIn platform app.
190 const std::string site_url = 190 const std::string site_url =
191 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, 191 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme,
192 kArcSupportExtensionId, kArcSupportStorageId); 192 kArcSupportExtensionId, kArcSupportStorageId);
193 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( 193 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite(
194 profile_, GURL(site_url)); 194 profile_, GURL(site_url));
195 CHECK(storage_partition_); 195 CHECK(storage_partition_);
196 196
197 // In case UI is disabled we assume that ARC is opted-in. 197 pref_change_registrar_.Init(profile_->GetPrefs());
198 if (!IsOptInVerificationDisabled()) { 198 pref_change_registrar_.Add(
199 pref_change_registrar_.Init(profile_->GetPrefs()); 199 prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged,
200 pref_change_registrar_.Add( 200 base::Unretained(this)));
201 prefs::kArcEnabled, 201 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) {
202 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, 202 OnOptInPreferenceChanged();
203 base::Unretained(this))); 203 } else {
204 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { 204 if (!disable_ui_for_testing && profile_->IsNewProfile()) {
205 OnOptInPreferenceChanged(); 205 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
206 } else { 206 OnIsSyncingChanged();
207 if (!disable_ui_for_testing && profile_->IsNewProfile()) {
208 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
209 OnIsSyncingChanged();
210 }
211 } 207 }
212 } else {
213 auth_code_.clear();
214 StartArc();
215 } 208 }
216 } 209 }
217 210
218 void ArcAuthService::OnIsSyncingChanged() { 211 void ArcAuthService::OnIsSyncingChanged() {
219 syncable_prefs::PrefServiceSyncable* const pref_service_syncable = 212 syncable_prefs::PrefServiceSyncable* const pref_service_syncable =
220 PrefServiceSyncableFromProfile(profile_); 213 PrefServiceSyncableFromProfile(profile_);
221 if (!pref_service_syncable->IsSyncing()) 214 if (!pref_service_syncable->IsSyncing())
222 return; 215 return;
223 216
224 pref_service_syncable->RemoveObserver(this); 217 pref_service_syncable->RemoveObserver(this);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 VLOG(2) << "Failed to get ubertoken " << error.ToString() << "."; 277 VLOG(2) << "Failed to get ubertoken " << error.ToString() << ".";
285 OnAuthCodeFailed(); 278 OnAuthCodeFailed();
286 } 279 }
287 280
288 void ArcAuthService::OnOptInPreferenceChanged() { 281 void ArcAuthService::OnOptInPreferenceChanged() {
289 DCHECK(thread_checker_.CalledOnValidThread()); 282 DCHECK(thread_checker_.CalledOnValidThread());
290 DCHECK(profile_); 283 DCHECK(profile_);
291 284
292 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { 285 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) {
293 if (state_ != State::ACTIVE) { 286 if (state_ != State::ACTIVE) {
294 CloseUI();
295 auth_code_.clear(); 287 auth_code_.clear();
296 288
297 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { 289 if (!IsOptInVerificationDisabled()) {
298 // Need pre-fetch auth code and show OptIn UI if needed. 290 CloseUI();
299 initial_opt_in_ = true; 291 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) {
300 SetState(State::FETCHING_CODE); 292 // Need pre-fetch auth code and show OptIn UI if needed.
301 FetchAuthCode(); 293 initial_opt_in_ = true;
294 SetState(State::FETCHING_CODE);
295 FetchAuthCode();
296 } else {
297 // Ready to start Arc.
298 StartArc();
299 }
302 } else { 300 } else {
303 // Ready to start Arc.
304 StartArc(); 301 StartArc();
305 } 302 }
306 } 303 }
307 } else { 304 } else {
308 ShutdownBridgeAndCloseUI(); 305 ShutdownBridgeAndCloseUI();
309 } 306 }
310 } 307 }
311 308
312 void ArcAuthService::ShutdownBridge() { 309 void ArcAuthService::ShutdownBridge() {
313 auth_callback_.reset(); 310 auth_callback_.reset();
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 return os << kStateFetchingCode; 470 return os << kStateFetchingCode;
474 case ArcAuthService::State::ACTIVE: 471 case ArcAuthService::State::ACTIVE:
475 return os << kStateActive; 472 return os << kStateActive;
476 default: 473 default:
477 NOTREACHED(); 474 NOTREACHED();
478 return os; 475 return os;
479 } 476 }
480 } 477 }
481 478
482 } // namespace arc 479 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698