| 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/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 active_(false), | 158 active_(false), |
| 159 delegate_(NULL), | 159 delegate_(NULL), |
| 160 #if defined(ENABLE_EXTENSIONS) | 160 #if defined(ENABLE_EXTENSIONS) |
| 161 extension_registry_observer_(this), | 161 extension_registry_observer_(this), |
| 162 #endif | 162 #endif |
| 163 waiting_for_sync_initialization_(false), | 163 waiting_for_sync_initialization_(false), |
| 164 is_profile_active_(false), | 164 is_profile_active_(false), |
| 165 elevated_for_testing_(false), | 165 elevated_for_testing_(false), |
| 166 did_init_(false), | 166 did_init_(false), |
| 167 did_shutdown_(false), | 167 did_shutdown_(false), |
| 168 waiting_for_permissions_(false), | |
| 169 weak_ptr_factory_(this) { | 168 weak_ptr_factory_(this) { |
| 170 } | 169 } |
| 171 | 170 |
| 172 SupervisedUserService::~SupervisedUserService() { | 171 SupervisedUserService::~SupervisedUserService() { |
| 173 DCHECK(!did_init_ || did_shutdown_); | 172 DCHECK(!did_init_ || did_shutdown_); |
| 174 } | 173 } |
| 175 | 174 |
| 176 void SupervisedUserService::Shutdown() { | 175 void SupervisedUserService::Shutdown() { |
| 177 if (!did_init_) | 176 if (!did_init_) |
| 178 return; | 177 return; |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 #if defined(ENABLE_EXTENSIONS) | 538 #if defined(ENABLE_EXTENSIONS) |
| 540 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); | 539 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); |
| 541 #endif | 540 #endif |
| 542 } | 541 } |
| 543 | 542 |
| 544 void SupervisedUserService::LoadBlacklist(const base::FilePath& path) { | 543 void SupervisedUserService::LoadBlacklist(const base::FilePath& path) { |
| 545 url_filter_context_.LoadBlacklist(path); | 544 url_filter_context_.LoadBlacklist(path); |
| 546 } | 545 } |
| 547 | 546 |
| 548 bool SupervisedUserService::AccessRequestsEnabled() { | 547 bool SupervisedUserService::AccessRequestsEnabled() { |
| 549 if (waiting_for_permissions_) | |
| 550 return false; | |
| 551 | |
| 552 ProfileSyncService* service = | 548 ProfileSyncService* service = |
| 553 ProfileSyncServiceFactory::GetForProfile(profile_); | 549 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 554 GoogleServiceAuthError::State state = service->GetAuthError().state(); | 550 GoogleServiceAuthError::State state = service->GetAuthError().state(); |
| 555 // We allow requesting access if Sync is working or has a transient error. | 551 // We allow requesting access if Sync is working or has a transient error. |
| 556 return (state == GoogleServiceAuthError::NONE || | 552 return (state == GoogleServiceAuthError::NONE || |
| 557 state == GoogleServiceAuthError::CONNECTION_FAILED || | 553 state == GoogleServiceAuthError::CONNECTION_FAILED || |
| 558 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 554 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 559 } | 555 } |
| 560 | 556 |
| 561 void SupervisedUserService::OnPermissionRequestIssued() { | 557 void SupervisedUserService::OnPermissionRequestIssued() { |
| 562 waiting_for_permissions_ = false; | |
| 563 // TODO(akuegel): Figure out how to show the result of issuing the permission | 558 // TODO(akuegel): Figure out how to show the result of issuing the permission |
| 564 // request in the UI. Currently, we assume the permission request was created | 559 // request in the UI. Currently, we assume the permission request was created |
| 565 // successfully. | 560 // successfully. |
| 566 } | 561 } |
| 567 | 562 |
| 568 void SupervisedUserService::AddAccessRequest(const GURL& url) { | 563 void SupervisedUserService::AddAccessRequest(const GURL& url) { |
| 569 waiting_for_permissions_ = true; | |
| 570 permissions_creator_->CreatePermissionRequest( | 564 permissions_creator_->CreatePermissionRequest( |
| 571 SupervisedUserURLFilter::Normalize(url), | 565 SupervisedUserURLFilter::Normalize(url), |
| 572 base::Bind(&SupervisedUserService::OnPermissionRequestIssued, | 566 base::Bind(&SupervisedUserService::OnPermissionRequestIssued, |
| 573 weak_ptr_factory_.GetWeakPtr())); | 567 weak_ptr_factory_.GetWeakPtr())); |
| 574 } | 568 } |
| 575 | 569 |
| 576 SupervisedUserService::ManualBehavior | 570 SupervisedUserService::ManualBehavior |
| 577 SupervisedUserService::GetManualBehaviorForHost( | 571 SupervisedUserService::GetManualBehaviorForHost( |
| 578 const std::string& hostname) { | 572 const std::string& hostname) { |
| 579 const base::DictionaryValue* dict = | 573 const base::DictionaryValue* dict = |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 // The active user can be NULL in unit tests. | 844 // The active user can be NULL in unit tests. |
| 851 if (user_manager::UserManager::Get()->GetActiveUser()) { | 845 if (user_manager::UserManager::Get()->GetActiveUser()) { |
| 852 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 846 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
| 853 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 847 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
| 854 } | 848 } |
| 855 return std::string(); | 849 return std::string(); |
| 856 #else | 850 #else |
| 857 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 851 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 858 #endif | 852 #endif |
| 859 } | 853 } |
| OLD | NEW |