OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/supervised_user_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 scoped_ptr<std::map<GURL, bool> > url_map) { | 126 scoped_ptr<std::map<GURL, bool> > url_map) { |
127 ui_url_filter_->SetManualURLs(url_map.get()); | 127 ui_url_filter_->SetManualURLs(url_map.get()); |
128 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
129 BrowserThread::IO, | 129 BrowserThread::IO, |
130 FROM_HERE, | 130 FROM_HERE, |
131 base::Bind(&SupervisedUserURLFilter::SetManualURLs, | 131 base::Bind(&SupervisedUserURLFilter::SetManualURLs, |
132 io_url_filter_, base::Owned(url_map.release()))); | 132 io_url_filter_, base::Owned(url_map.release()))); |
133 } | 133 } |
134 | 134 |
135 SupervisedUserService::SupervisedUserService(Profile* profile) | 135 SupervisedUserService::SupervisedUserService(Profile* profile) |
136 : profile_(profile), | 136 : includes_sync_sessions_type_(true), |
137 profile_(profile), | |
137 active_(false), | 138 active_(false), |
138 delegate_(NULL), | 139 delegate_(NULL), |
139 #if defined(ENABLE_EXTENSIONS) | 140 #if defined(ENABLE_EXTENSIONS) |
140 extension_registry_observer_(this), | 141 extension_registry_observer_(this), |
141 #endif | 142 #endif |
142 waiting_for_sync_initialization_(false), | 143 waiting_for_sync_initialization_(false), |
143 is_profile_active_(false), | 144 is_profile_active_(false), |
144 elevated_for_testing_(false), | 145 elevated_for_testing_(false), |
145 did_init_(false), | 146 did_init_(false), |
146 did_shutdown_(false), | 147 did_shutdown_(false), |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 UpdateSiteLists(); | 357 UpdateSiteLists(); |
357 } | 358 } |
358 } | 359 } |
359 #endif // defined(ENABLE_EXTENSIONS) | 360 #endif // defined(ENABLE_EXTENSIONS) |
360 | 361 |
361 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { | 362 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { |
362 if (!ProfileIsSupervised()) | 363 if (!ProfileIsSupervised()) |
363 return syncer::ModelTypeSet(); | 364 return syncer::ModelTypeSet(); |
364 | 365 |
365 syncer::ModelTypeSet result; | 366 syncer::ModelTypeSet result; |
366 result.Put(syncer::SESSIONS); | 367 if (IncludesSyncSessionsType()) |
368 result.Put(syncer::SESSIONS); | |
367 result.Put(syncer::EXTENSIONS); | 369 result.Put(syncer::EXTENSIONS); |
368 result.Put(syncer::EXTENSION_SETTINGS); | 370 result.Put(syncer::EXTENSION_SETTINGS); |
369 result.Put(syncer::APPS); | 371 result.Put(syncer::APPS); |
370 result.Put(syncer::APP_SETTINGS); | 372 result.Put(syncer::APP_SETTINGS); |
371 result.Put(syncer::APP_NOTIFICATIONS); | 373 result.Put(syncer::APP_NOTIFICATIONS); |
372 result.Put(syncer::APP_LIST); | 374 result.Put(syncer::APP_LIST); |
373 return result; | 375 return result; |
374 } | 376 } |
375 | 377 |
378 void SupervisedUserService::OnHistoryRecordingStateChanged() { | |
379 includes_sync_sessions_type_ = | |
380 profile_->GetPrefs()->GetBoolean(prefs::kRecordHistory); | |
381 ProfileSyncServiceFactory::GetForProfile(profile_) | |
382 ->ReconfigureDatatypeManager(); | |
383 } | |
384 | |
385 bool SupervisedUserService::IncludesSyncSessionsType() const { | |
386 return includes_sync_sessions_type_; | |
387 } | |
388 | |
376 void SupervisedUserService::OnStateChanged() { | 389 void SupervisedUserService::OnStateChanged() { |
377 ProfileSyncService* service = | 390 ProfileSyncService* service = |
378 ProfileSyncServiceFactory::GetForProfile(profile_); | 391 ProfileSyncServiceFactory::GetForProfile(profile_); |
379 if (waiting_for_sync_initialization_ && service->sync_initialized()) { | 392 if (waiting_for_sync_initialization_ && service->sync_initialized()) { |
380 waiting_for_sync_initialization_ = false; | 393 waiting_for_sync_initialization_ = false; |
381 service->RemoveObserver(this); | 394 service->RemoveObserver(this); |
382 FinishSetupSync(); | 395 FinishSetupSync(); |
383 return; | 396 return; |
384 } | 397 } |
385 | 398 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 ProfileSyncService* service = | 432 ProfileSyncService* service = |
420 ProfileSyncServiceFactory::GetForProfile(profile_); | 433 ProfileSyncServiceFactory::GetForProfile(profile_); |
421 DCHECK(service->sync_initialized()); | 434 DCHECK(service->sync_initialized()); |
422 | 435 |
423 // Sync nothing (except types which are set via GetPreferredDataTypes). | 436 // Sync nothing (except types which are set via GetPreferredDataTypes). |
424 bool sync_everything = false; | 437 bool sync_everything = false; |
425 syncer::ModelTypeSet synced_datatypes; | 438 syncer::ModelTypeSet synced_datatypes; |
426 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 439 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
427 | 440 |
428 // Notify ProfileSyncService that we are done with configuration. | 441 // Notify ProfileSyncService that we are done with configuration. |
429 service->SetSetupInProgress(false); | 442 service->SetSetupInProgress(false); |
Nicolas Zea
2014/09/26 20:34:11
Why not use this approach, rather than explicitly
fhorschig
2014/09/29 07:23:51
This approach was chosen first but then changed to
Marc Treib
2014/09/29 07:45:57
Mostly clarity:
service->ReconfigureDataTypeManage
| |
430 service->SetSyncSetupCompleted(); | 443 service->SetSyncSetupCompleted(); |
431 } | 444 } |
432 | 445 |
433 #if defined(ENABLE_EXTENSIONS) | 446 #if defined(ENABLE_EXTENSIONS) |
434 bool SupervisedUserService::ExtensionManagementPolicyImpl( | 447 bool SupervisedUserService::ExtensionManagementPolicyImpl( |
435 const extensions::Extension* extension, | 448 const extensions::Extension* extension, |
436 base::string16* error) const { | 449 base::string16* error) const { |
437 // |extension| can be NULL in unit_tests. | 450 // |extension| can be NULL in unit_tests. |
438 if (!ProfileIsSupervised() || (extension && extension->is_theme())) | 451 if (!ProfileIsSupervised() || (extension && extension->is_theme())) |
439 return true; | 452 return true; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 void SupervisedUserService::Init() { | 618 void SupervisedUserService::Init() { |
606 DCHECK(!did_init_); | 619 DCHECK(!did_init_); |
607 did_init_ = true; | 620 did_init_ = true; |
608 DCHECK(GetSettingsService()->IsReady()); | 621 DCHECK(GetSettingsService()->IsReady()); |
609 | 622 |
610 pref_change_registrar_.Init(profile_->GetPrefs()); | 623 pref_change_registrar_.Init(profile_->GetPrefs()); |
611 pref_change_registrar_.Add( | 624 pref_change_registrar_.Add( |
612 prefs::kSupervisedUserId, | 625 prefs::kSupervisedUserId, |
613 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, | 626 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, |
614 base::Unretained(this))); | 627 base::Unretained(this))); |
628 pref_change_registrar_.Add( | |
629 prefs::kRecordHistory, | |
630 base::Bind(&SupervisedUserService::OnHistoryRecordingStateChanged, | |
631 base::Unretained(this))); | |
615 | 632 |
616 ProfileSyncService* sync_service = | 633 ProfileSyncService* sync_service = |
617 ProfileSyncServiceFactory::GetForProfile(profile_); | 634 ProfileSyncServiceFactory::GetForProfile(profile_); |
618 // Can be null in tests. | 635 // Can be null in tests. |
619 if (sync_service) | 636 if (sync_service) |
620 sync_service->AddPreferenceProvider(this); | 637 sync_service->AddPreferenceProvider(this); |
621 | 638 |
622 SetActive(ProfileIsSupervised()); | 639 SetActive(ProfileIsSupervised()); |
623 } | 640 } |
624 | 641 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
823 // The active user can be NULL in unit tests. | 840 // The active user can be NULL in unit tests. |
824 if (user_manager::UserManager::Get()->GetActiveUser()) { | 841 if (user_manager::UserManager::Get()->GetActiveUser()) { |
825 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 842 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
826 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 843 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
827 } | 844 } |
828 return std::string(); | 845 return std::string(); |
829 #else | 846 #else |
830 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 847 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
831 #endif | 848 #endif |
832 } | 849 } |
OLD | NEW |