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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_service.cc

Issue 2004043002: Supervised Users Initiated Installs v2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kid_initiated_install
Patch Set: Response to code review by Devlin and fixing a test Created 4 years, 6 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 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 <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h"
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/path_service.h" 14 #include "base/path_service.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "base/task_runner_util.h" 17 #include "base/task_runner_util.h"
17 #include "base/version.h" 18 #include "base/version.h"
18 #include "build/build_config.h" 19 #include "build/build_config.h"
19 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h " 21 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h "
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_attributes_entry.h" 23 #include "chrome/browser/profiles/profile_attributes_entry.h"
23 #include "chrome/browser/profiles/profile_attributes_storage.h" 24 #include "chrome/browser/profiles/profile_attributes_storage.h"
24 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
26 #include "chrome/browser/signin/signin_manager_factory.h" 27 #include "chrome/browser/signin/signin_manager_factory.h"
27 #include "chrome/browser/supervised_user/experimental/supervised_user_filtering_ switches.h" 28 #include "chrome/browser/supervised_user/experimental/supervised_user_filtering_ switches.h"
28 #include "chrome/browser/supervised_user/permission_request_creator.h" 29 #include "chrome/browser/supervised_user/permission_request_creator.h"
29 #include "chrome/browser/supervised_user/supervised_user_constants.h" 30 #include "chrome/browser/supervised_user/supervised_user_constants.h"
31 #include "chrome/browser/supervised_user/supervised_user_features.h"
32 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
30 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" 33 #include "chrome/browser/supervised_user/supervised_user_service_observer.h"
31 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" 34 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
32 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" 35 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h"
33 #include "chrome/browser/supervised_user/supervised_user_site_list.h" 36 #include "chrome/browser/supervised_user/supervised_user_site_list.h"
34 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" 37 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h"
35 #include "chrome/browser/sync/profile_sync_service_factory.h" 38 #include "chrome/browser/sync/profile_sync_service_factory.h"
36 #include "chrome/browser/ui/browser.h" 39 #include "chrome/browser/ui/browser.h"
37 #include "chrome/browser/ui/browser_list.h" 40 #include "chrome/browser/ui/browser_list.h"
38 #include "chrome/common/chrome_paths.h" 41 #include "chrome/common/chrome_paths.h"
39 #include "chrome/common/chrome_switches.h" 42 #include "chrome/common/chrome_switches.h"
(...skipping 23 matching lines...) Expand all
63 #if defined(OS_CHROMEOS) 66 #if defined(OS_CHROMEOS)
64 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 67 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
65 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" 68 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
66 #include "components/user_manager/user_manager.h" 69 #include "components/user_manager/user_manager.h"
67 #endif 70 #endif
68 71
69 #if defined(ENABLE_EXTENSIONS) 72 #if defined(ENABLE_EXTENSIONS)
70 #include "chrome/browser/extensions/extension_service.h" 73 #include "chrome/browser/extensions/extension_service.h"
71 #include "chrome/browser/extensions/extension_util.h" 74 #include "chrome/browser/extensions/extension_util.h"
72 #include "extensions/browser/extension_prefs.h" 75 #include "extensions/browser/extension_prefs.h"
76 #include "extensions/browser/extension_registry.h"
73 #include "extensions/browser/extension_system.h" 77 #include "extensions/browser/extension_system.h"
74 #endif 78 #endif
75 79
76 #if defined(ENABLE_THEMES) 80 #if defined(ENABLE_THEMES)
77 #include "chrome/browser/themes/theme_service.h" 81 #include "chrome/browser/themes/theme_service.h"
78 #include "chrome/browser/themes/theme_service_factory.h" 82 #include "chrome/browser/themes/theme_service_factory.h"
79 #endif 83 #endif
80 84
81 using base::DictionaryValue; 85 using base::DictionaryValue;
82 using base::UserMetricsAction; 86 using base::UserMetricsAction;
83 using content::BrowserThread; 87 using content::BrowserThread;
84 88
85 #if defined(ENABLE_EXTENSIONS) 89 #if defined(ENABLE_EXTENSIONS)
90 using extensions::Extension;
91 using extensions::ExtensionPrefs;
92 using extensions::ExtensionRegistry;
93 using extensions::ExtensionSystem;
94 #endif
95
96 #if defined(ENABLE_EXTENSIONS)
86 using extensions::ExtensionPrefs; 97 using extensions::ExtensionPrefs;
87 #endif 98 #endif
88 99
89 namespace { 100 namespace {
90 101
91 // The URL from which to download a host blacklist if no local one exists yet. 102 // The URL from which to download a host blacklist if no local one exists yet.
92 const char kBlacklistURL[] = 103 const char kBlacklistURL[] =
93 "https://www.gstatic.com/chrome/supervised_user/blacklist-20141001-1k.bin"; 104 "https://www.gstatic.com/chrome/supervised_user/blacklist-20141001-1k.bin";
94 // The filename under which we'll store the blacklist (in the user data dir). 105 // The filename under which we'll store the blacklist (in the user data dir).
95 const char kBlacklistFilename[] = "su-blacklist.bin"; 106 const char kBlacklistFilename[] = "su-blacklist.bin";
96 107
97 const char* const kCustodianInfoPrefs[] = { 108 const char* const kCustodianInfoPrefs[] = {
98 prefs::kSupervisedUserCustodianName, 109 prefs::kSupervisedUserCustodianName,
99 prefs::kSupervisedUserCustodianEmail, 110 prefs::kSupervisedUserCustodianEmail,
100 prefs::kSupervisedUserCustodianProfileImageURL, 111 prefs::kSupervisedUserCustodianProfileImageURL,
101 prefs::kSupervisedUserCustodianProfileURL, 112 prefs::kSupervisedUserCustodianProfileURL,
102 prefs::kSupervisedUserSecondCustodianName, 113 prefs::kSupervisedUserSecondCustodianName,
103 prefs::kSupervisedUserSecondCustodianEmail, 114 prefs::kSupervisedUserSecondCustodianEmail,
104 prefs::kSupervisedUserSecondCustodianProfileImageURL, 115 prefs::kSupervisedUserSecondCustodianProfileImageURL,
105 prefs::kSupervisedUserSecondCustodianProfileURL, 116 prefs::kSupervisedUserSecondCustodianProfileURL,
106 }; 117 };
107 118
108 void CreateURLAccessRequest( 119 void CreateURLAccessRequest(
109 const GURL& url, 120 const GURL& url,
110 PermissionRequestCreator* creator, 121 PermissionRequestCreator* creator,
111 const SupervisedUserService::SuccessCallback& callback) { 122 const SupervisedUserService::SuccessCallback& callback) {
112 creator->CreateURLAccessRequest(url, callback); 123 creator->CreateURLAccessRequest(url, callback);
113 } 124 }
114 125
126 void CreateExtensionInstallRequest(
127 const std::string& id,
128 PermissionRequestCreator* creator,
129 const SupervisedUserService::SuccessCallback& callback) {
130 creator->CreateExtensionInstallRequest(id, callback);
131 }
132
115 void CreateExtensionUpdateRequest( 133 void CreateExtensionUpdateRequest(
116 const std::string& id, 134 const std::string& id,
117 PermissionRequestCreator* creator, 135 PermissionRequestCreator* creator,
118 const SupervisedUserService::SuccessCallback& callback) { 136 const SupervisedUserService::SuccessCallback& callback) {
119 creator->CreateExtensionUpdateRequest(id, callback); 137 creator->CreateExtensionUpdateRequest(id, callback);
120 } 138 }
121 139
140 // Default callback for AddExtensionInstallRequest.
141 void ExtensionInstallRequestSent(const std::string& id, bool success) {
142 VLOG_IF(1, !success) << "Failed sending install request for " << id;
143 }
144
122 // Default callback for AddExtensionUpdateRequest. 145 // Default callback for AddExtensionUpdateRequest.
123 void ExtensionUpdateRequestSent(const std::string& id, bool success) { 146 void ExtensionUpdateRequestSent(const std::string& id, bool success) {
124 VLOG_IF(1, !success) << "Failed sending update request for " << id; 147 VLOG_IF(1, !success) << "Failed sending update request for " << id;
125 } 148 }
126 149
127 base::FilePath GetBlacklistPath() { 150 base::FilePath GetBlacklistPath() {
128 base::FilePath blacklist_dir; 151 base::FilePath blacklist_dir;
129 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); 152 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir);
130 return blacklist_dir.AppendASCII(kBlacklistFilename); 153 return blacklist_dir.AppendASCII(kBlacklistFilename);
131 } 154 }
132 155
133 } // namespace 156 } // namespace
134 157
135 SupervisedUserService::~SupervisedUserService() { 158 SupervisedUserService::~SupervisedUserService() {
136 DCHECK(!did_init_ || did_shutdown_); 159 DCHECK(!did_init_ || did_shutdown_);
137 url_filter_context_.ui_url_filter()->RemoveObserver(this); 160 url_filter_context_.ui_url_filter()->RemoveObserver(this);
138 } 161 }
139 162
140 // static 163 // static
141 void SupervisedUserService::RegisterProfilePrefs( 164 void SupervisedUserService::RegisterProfilePrefs(
142 user_prefs::PrefRegistrySyncable* registry) { 165 user_prefs::PrefRegistrySyncable* registry) {
166 registry->RegisterDictionaryPref(prefs::kSupervisedUserApprovedExtensions);
143 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts); 167 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts);
144 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs); 168 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs);
145 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior, 169 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior,
146 SupervisedUserURLFilter::ALLOW); 170 SupervisedUserURLFilter::ALLOW);
147 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true); 171 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true);
148 registry->RegisterBooleanPref(prefs::kSupervisedUserSafeSites, true); 172 registry->RegisterBooleanPref(prefs::kSupervisedUserSafeSites, true);
149 for (const char* pref : kCustodianInfoPrefs) { 173 for (const char* pref : kCustodianInfoPrefs) {
150 registry->RegisterStringPref(pref, std::string()); 174 registry->RegisterStringPref(pref, std::string());
151 } 175 }
152 } 176 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 247 }
224 248
225 void SupervisedUserService::ReportURL(const GURL& url, 249 void SupervisedUserService::ReportURL(const GURL& url,
226 const SuccessCallback& callback) { 250 const SuccessCallback& callback) {
227 if (url_reporter_) 251 if (url_reporter_)
228 url_reporter_->ReportUrl(url, callback); 252 url_reporter_->ReportUrl(url, callback);
229 else 253 else
230 callback.Run(false); 254 callback.Run(false);
231 } 255 }
232 256
257 void SupervisedUserService::AddExtensionInstallRequest(
258 const std::string& extension_id,
259 const base::Version& version,
260 const SuccessCallback& callback) {
261 std::string id = GetExtensionRequestId(extension_id, version);
262 AddPermissionRequestInternal(base::Bind(CreateExtensionInstallRequest, id),
263 callback, 0);
264 }
265
266 void SupervisedUserService::AddExtensionInstallRequest(
267 const std::string& extension_id,
268 const base::Version& version) {
269 std::string id = GetExtensionRequestId(extension_id, version);
270 AddPermissionRequestInternal(base::Bind(CreateExtensionInstallRequest, id),
271 base::Bind(ExtensionInstallRequestSent, id), 0);
272 }
273
233 void SupervisedUserService::AddExtensionUpdateRequest( 274 void SupervisedUserService::AddExtensionUpdateRequest(
234 const std::string& extension_id, 275 const std::string& extension_id,
235 const base::Version& version, 276 const base::Version& version,
236 const SuccessCallback& callback) { 277 const SuccessCallback& callback) {
237 std::string id = GetExtensionUpdateRequestId(extension_id, version); 278 std::string id = GetExtensionRequestId(extension_id, version);
238 AddPermissionRequestInternal( 279 AddPermissionRequestInternal(
239 base::Bind(CreateExtensionUpdateRequest, id), callback, 0); 280 base::Bind(CreateExtensionUpdateRequest, id), callback, 0);
240 } 281 }
241 282
242 void SupervisedUserService::AddExtensionUpdateRequest( 283 void SupervisedUserService::AddExtensionUpdateRequest(
243 const std::string& extension_id, 284 const std::string& extension_id,
244 const base::Version& version) { 285 const base::Version& version) {
245 std::string id = GetExtensionUpdateRequestId(extension_id, version); 286 std::string id = GetExtensionRequestId(extension_id, version);
246 AddExtensionUpdateRequest(extension_id, version, 287 AddExtensionUpdateRequest(extension_id, version,
247 base::Bind(ExtensionUpdateRequestSent, id)); 288 base::Bind(ExtensionUpdateRequestSent, id));
248 } 289 }
249 290
291 void SupervisedUserService::ChangeExtensionStateIfNecessary(
292 const std::string& extension_id) {
293 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
294 const Extension* extension = registry->GetInstalledExtension(extension_id);
295 // If the extension is not installed (yet), do nothing.
296 // When it gets installed, GetExtensionState() will return ALLOWED, hence
297 // it will be enabled.
298 if (!extension)
299 return;
300
301 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
302 ExtensionService* service =
303 ExtensionSystem::Get(profile_)->extension_service();
304
305 ExtensionState state = GetExtensionState(*extension);
306 // BLOCKED/FORCED extensions should be already disabled/enabled
307 // and we don't need to change their state here.
308 if (state == ExtensionState::BLOCKED || state == ExtensionState::FORCED)
309 return;
310
311 if (state == ExtensionState::REQUIRE_APPROVAL) {
312 service->DisableExtension(extension_id,
313 Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED);
314 return;
315 }
316
317 if (state == ExtensionState::ALLOWED) {
318 extension_prefs->RemoveDisableReason(
319 extension_id, Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED);
320 extension_prefs->RemoveDisableReason(
321 extension_id, Extension::DISABLE_PERMISSIONS_INCREASE);
322 // If not disabled for other reasons, enable it.
323 if (extension_prefs->GetDisableReasons(extension_id) ==
324 Extension::DISABLE_NONE) {
325 service->EnableExtension(extension_id);
326 }
327 }
328 }
329
250 // static 330 // static
251 std::string SupervisedUserService::GetExtensionUpdateRequestId( 331 std::string SupervisedUserService::GetExtensionRequestId(
252 const std::string& extension_id, 332 const std::string& extension_id,
253 const base::Version& version) { 333 const base::Version& version) {
254 return base::StringPrintf("%s:%s", extension_id.c_str(), 334 return base::StringPrintf("%s:%s", extension_id.c_str(),
255 version.GetString().c_str()); 335 version.GetString().c_str());
256 } 336 }
257 337
258 std::string SupervisedUserService::GetCustodianEmailAddress() const { 338 std::string SupervisedUserService::GetCustodianEmailAddress() const {
259 std::string email = profile_->GetPrefs()->GetString( 339 std::string email = profile_->GetPrefs()->GetString(
260 prefs::kSupervisedUserCustodianEmail); 340 prefs::kSupervisedUserCustodianEmail);
261 #if defined(OS_CHROMEOS) 341 #if defined(OS_CHROMEOS)
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 SupervisedUserService::SupervisedUserService(Profile* profile) 561 SupervisedUserService::SupervisedUserService(Profile* profile)
482 : includes_sync_sessions_type_(true), 562 : includes_sync_sessions_type_(true),
483 profile_(profile), 563 profile_(profile),
484 active_(false), 564 active_(false),
485 delegate_(NULL), 565 delegate_(NULL),
486 waiting_for_sync_initialization_(false), 566 waiting_for_sync_initialization_(false),
487 is_profile_active_(false), 567 is_profile_active_(false),
488 did_init_(false), 568 did_init_(false),
489 did_shutdown_(false), 569 did_shutdown_(false),
490 blacklist_state_(BlacklistLoadState::NOT_LOADED), 570 blacklist_state_(BlacklistLoadState::NOT_LOADED),
571 registry_observer_(this),
491 weak_ptr_factory_(this) { 572 weak_ptr_factory_(this) {
492 url_filter_context_.ui_url_filter()->AddObserver(this); 573 url_filter_context_.ui_url_filter()->AddObserver(this);
574 registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
493 } 575 }
494 576
495 void SupervisedUserService::SetActive(bool active) { 577 void SupervisedUserService::SetActive(bool active) {
496 if (active_ == active) 578 if (active_ == active)
497 return; 579 return;
498 active_ = active; 580 active_ = active;
499 581
500 if (!delegate_ || !delegate_->SetActive(active_)) { 582 if (!delegate_ || !delegate_->SetActive(active_)) {
501 if (active_) { 583 if (active_) {
502 #if !defined(OS_ANDROID) 584 #if !defined(OS_ANDROID)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 629
548 #if defined(ENABLE_EXTENSIONS) 630 #if defined(ENABLE_EXTENSIONS)
549 SetExtensionsActive(); 631 SetExtensionsActive();
550 #endif 632 #endif
551 633
552 if (active_) { 634 if (active_) {
553 pref_change_registrar_.Add( 635 pref_change_registrar_.Add(
554 prefs::kDefaultSupervisedUserFilteringBehavior, 636 prefs::kDefaultSupervisedUserFilteringBehavior,
555 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, 637 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged,
556 base::Unretained(this))); 638 base::Unretained(this)));
639 pref_change_registrar_.Add(
640 prefs::kSupervisedUserApprovedExtensions,
641 base::Bind(&SupervisedUserService::UpdateApprovedExtensions,
642 base::Unretained(this)));
557 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, 643 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites,
558 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, 644 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged,
559 base::Unretained(this))); 645 base::Unretained(this)));
560 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, 646 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts,
561 base::Bind(&SupervisedUserService::UpdateManualHosts, 647 base::Bind(&SupervisedUserService::UpdateManualHosts,
562 base::Unretained(this))); 648 base::Unretained(this)));
563 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, 649 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs,
564 base::Bind(&SupervisedUserService::UpdateManualURLs, 650 base::Bind(&SupervisedUserService::UpdateManualURLs,
565 base::Unretained(this))); 651 base::Unretained(this)));
566 for (const char* pref : kCustodianInfoPrefs) { 652 for (const char* pref : kCustodianInfoPrefs) {
567 pref_change_registrar_.Add(pref, 653 pref_change_registrar_.Add(pref,
568 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, 654 base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
569 base::Unretained(this))); 655 base::Unretained(this)));
570 } 656 }
571 657
572 // Initialize the filter. 658 // Initialize the filter.
573 OnDefaultFilteringBehaviorChanged(); 659 OnDefaultFilteringBehaviorChanged();
574 OnSafeSitesSettingChanged(); 660 OnSafeSitesSettingChanged();
575 whitelist_service_->Init(); 661 whitelist_service_->Init();
576 UpdateManualHosts(); 662 UpdateManualHosts();
577 UpdateManualURLs(); 663 UpdateManualURLs();
664 UpdateApprovedExtensions();
578 665
579 #if !defined(OS_ANDROID) 666 #if !defined(OS_ANDROID)
580 // TODO(bauerb): Get rid of the platform-specific #ifdef here. 667 // TODO(bauerb): Get rid of the platform-specific #ifdef here.
581 // http://crbug.com/313377 668 // http://crbug.com/313377
582 BrowserList::AddObserver(this); 669 BrowserList::AddObserver(this);
583 #endif 670 #endif
584 } else { 671 } else {
585 permissions_creators_.clear(); 672 permissions_creators_.clear();
586 url_reporter_.reset(); 673 url_reporter_.reset();
587 674
588 pref_change_registrar_.Remove( 675 pref_change_registrar_.Remove(
589 prefs::kDefaultSupervisedUserFilteringBehavior); 676 prefs::kDefaultSupervisedUserFilteringBehavior);
677 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions);
590 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); 678 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts);
591 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); 679 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs);
592 for (const char* pref : kCustodianInfoPrefs) { 680 for (const char* pref : kCustodianInfoPrefs) {
593 pref_change_registrar_.Remove(pref); 681 pref_change_registrar_.Remove(pref);
594 } 682 }
595 683
596 url_filter_context_.Clear(); 684 url_filter_context_.Clear();
597 FOR_EACH_OBSERVER( 685 FOR_EACH_OBSERVER(
598 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); 686 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged());
599 687
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 bool result = it.value().GetAsBoolean(&allow); 964 bool result = it.value().GetAsBoolean(&allow);
877 DCHECK(result); 965 DCHECK(result);
878 (*url_map)[GURL(it.key())] = allow; 966 (*url_map)[GURL(it.key())] = allow;
879 } 967 }
880 url_filter_context_.SetManualURLs(std::move(url_map)); 968 url_filter_context_.SetManualURLs(std::move(url_map));
881 969
882 FOR_EACH_OBSERVER( 970 FOR_EACH_OBSERVER(
883 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); 971 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged());
884 } 972 }
885 973
974 void SupervisedUserService::UpdateApprovedExtensions() {
975 const base::DictionaryValue* dict = profile_->GetPrefs()->GetDictionary(
976 prefs::kSupervisedUserApprovedExtensions);
977 approved_extensions_map_.clear();
978 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
979 std::string version_str;
980 bool result = it.value().GetAsString(&version_str);
981 DCHECK(result);
982 base::Version version(version_str);
983 if (version.IsValid())
984 approved_extensions_map_[it.key()] = version;
985 else
986 LOG(WARNING) << "Invalid version number " << version_str;
987 }
988
989 for (const auto& extensions_entry : approved_extensions_map_) {
990 ChangeExtensionStateIfNecessary(extensions_entry.first);
991 }
992 }
993
886 std::string SupervisedUserService::GetSupervisedUserName() const { 994 std::string SupervisedUserService::GetSupervisedUserName() const {
887 #if defined(OS_CHROMEOS) 995 #if defined(OS_CHROMEOS)
888 // The active user can be NULL in unit tests. 996 // The active user can be NULL in unit tests.
889 if (user_manager::UserManager::Get()->GetActiveUser()) { 997 if (user_manager::UserManager::Get()->GetActiveUser()) {
890 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( 998 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName(
891 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId())); 999 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId()));
892 } 1000 }
893 return std::string(); 1001 return std::string();
894 #else 1002 #else
895 return profile_->GetPrefs()->GetString(prefs::kProfileName); 1003 return profile_->GetPrefs()->GetString(prefs::kProfileName);
896 #endif 1004 #endif
897 } 1005 }
898 1006
899 void SupervisedUserService::OnForceSessionSyncChanged() { 1007 void SupervisedUserService::OnForceSessionSyncChanged() {
900 includes_sync_sessions_type_ = 1008 includes_sync_sessions_type_ =
901 profile_->GetPrefs()->GetBoolean(prefs::kForceSessionSync); 1009 profile_->GetPrefs()->GetBoolean(prefs::kForceSessionSync);
902 ProfileSyncServiceFactory::GetForProfile(profile_) 1010 ProfileSyncServiceFactory::GetForProfile(profile_)
903 ->ReconfigureDatatypeManager(); 1011 ->ReconfigureDatatypeManager();
904 } 1012 }
905 1013
1014 void SupervisedUserService::OnExtensionInstalled(
1015 content::BrowserContext* browser_context,
1016 const extensions::Extension* extension,
1017 bool is_update) {
1018 // This callback is responsible only for updating the approved version
1019 // upon extension update if it doesn't require extra permission.
1020 if (!is_update)
1021 return;
1022
1023 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
1024 const std::string& id = extension->id();
1025 const base::Version& version = *extension->version();
1026
1027 // If an already approved extension is updated without requiring
1028 // new permissions, we update the approved_version and re-enable it.
1029 if (!extension_prefs->HasDisableReason(
1030 id, Extension::DISABLE_PERMISSIONS_INCREASE) &&
1031 approved_extensions_map_.count(id) > 0 &&
1032 approved_extensions_map_[id] < version) {
1033 approved_extensions_map_[id] = version;
1034
1035 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey(
1036 supervised_users::kApprovedExtensions, id);
1037 std::unique_ptr<base::Value> version_value(
1038 new base::StringValue(version.GetString()));
1039 GetSettingsService()->UpdateSetting(key, std::move(version_value));
1040 }
1041 ChangeExtensionStateIfNecessary(id);
1042 }
1043
906 void SupervisedUserService::Shutdown() { 1044 void SupervisedUserService::Shutdown() {
907 if (!did_init_) 1045 if (!did_init_)
908 return; 1046 return;
909 DCHECK(!did_shutdown_); 1047 DCHECK(!did_shutdown_);
910 did_shutdown_ = true; 1048 did_shutdown_ = true;
911 if (ProfileIsSupervised()) { 1049 if (ProfileIsSupervised()) {
912 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); 1050 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser"));
913 } 1051 }
914 SetActive(false); 1052 SetActive(false);
915 sync_blocker_.reset(); 1053 sync_blocker_.reset();
916 1054
917 ProfileSyncService* sync_service = 1055 ProfileSyncService* sync_service =
918 ProfileSyncServiceFactory::GetForProfile(profile_); 1056 ProfileSyncServiceFactory::GetForProfile(profile_);
919 1057
920 // Can be null in tests. 1058 // Can be null in tests.
921 if (sync_service) 1059 if (sync_service)
922 sync_service->RemovePreferenceProvider(this); 1060 sync_service->RemovePreferenceProvider(this);
923 } 1061 }
924 1062
925 #if defined(ENABLE_EXTENSIONS) 1063 #if defined(ENABLE_EXTENSIONS)
926 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( 1064 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState(
927 const extensions::Extension* extension) const { 1065 const Extension& extension) const {
928 bool was_installed_by_default = extension->was_installed_by_default(); 1066 bool was_installed_by_default = extension.was_installed_by_default();
929 #if defined(OS_CHROMEOS) 1067 #if defined(OS_CHROMEOS)
930 // On Chrome OS all external sources are controlled by us so it means that 1068 // On Chrome OS all external sources are controlled by us so it means that
931 // they are "default". Method was_installed_by_default returns false because 1069 // they are "default". Method was_installed_by_default returns false because
932 // extensions creation flags are ignored in case of default extensions with 1070 // extensions creation flags are ignored in case of default extensions with
933 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). 1071 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound).
934 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation 1072 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation
935 // flags are not ignored. 1073 // flags are not ignored.
936 was_installed_by_default = 1074 was_installed_by_default =
937 extensions::Manifest::IsExternalLocation(extension->location()); 1075 extensions::Manifest::IsExternalLocation(extension->location());
938 #endif 1076 #endif
939 // Note: Component extensions are protected from modification/uninstallation 1077 // Note: Component extensions are protected from modification/uninstallation
940 // anyway, so there's no need to enforce them again for supervised users. 1078 // anyway, so there's no need to enforce them again for supervised users.
941 // Also, leave policy-installed extensions alone - they have their own 1079 // Also, leave policy-installed extensions alone - they have their own
942 // management; in particular we don't want to override the force-install list. 1080 // management; in particular we don't want to override the force-install list.
943 if (extensions::Manifest::IsComponentLocation(extension->location()) || 1081 if (extensions::Manifest::IsComponentLocation(extension.location()) ||
944 extensions::Manifest::IsPolicyLocation(extension->location()) || 1082 extensions::Manifest::IsPolicyLocation(extension.location()) ||
945 extension->is_theme() || 1083 extension.is_theme() || extension.from_bookmark() ||
946 extension->from_bookmark() || 1084 extension.is_shared_module() || was_installed_by_default) {
947 extension->is_shared_module() || 1085 return ExtensionState::ALLOWED;
948 was_installed_by_default) {
949 return ExtensionState::EXTENSION_ALLOWED;
950 } 1086 }
951 1087
952 if (extensions::util::WasInstalledByCustodian(extension->id(), profile_)) 1088 if (extensions::util::WasInstalledByCustodian(extension.id(), profile_))
953 return ExtensionState::EXTENSION_FORCED; 1089 return ExtensionState::FORCED;
954 1090
955 return ExtensionState::EXTENSION_BLOCKED; 1091 if (!base::FeatureList::IsEnabled(
1092 supervised_users::kSupervisedUserInitiatedExtensionInstall)) {
1093 return ExtensionState::BLOCKED;
1094 }
1095
1096 const std::string& id = extension.id();
1097
1098 auto extension_it = approved_extensions_map_.find(id);
1099 // If the installed version is approved, then the extension is allowed,
1100 // otherwise, it requires approval.
1101 if (extension_it != approved_extensions_map_.end() &&
1102 extension_it->second == *extension.version()) {
1103 return ExtensionState::ALLOWED;
1104 }
1105 return ExtensionState::REQUIRE_APPROVAL;
956 } 1106 }
957 1107
958 std::string SupervisedUserService::GetDebugPolicyProviderName() const { 1108 std::string SupervisedUserService::GetDebugPolicyProviderName() const {
959 // Save the string space in official builds. 1109 // Save the string space in official builds.
960 #ifdef NDEBUG 1110 #ifdef NDEBUG
961 NOTREACHED(); 1111 NOTREACHED();
962 return std::string(); 1112 return std::string();
963 #else 1113 #else
964 return "Supervised User Service"; 1114 return "Supervised User Service";
965 #endif 1115 #endif
966 } 1116 }
967 1117
968 bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, 1118 bool SupervisedUserService::UserMayLoad(const Extension* extension,
969 base::string16* error) const { 1119 base::string16* error) const {
970 DCHECK(ProfileIsSupervised()); 1120 DCHECK(ProfileIsSupervised());
971 ExtensionState result = GetExtensionState(extension); 1121 ExtensionState result = GetExtensionState(*extension);
972 bool may_load = (result != EXTENSION_BLOCKED); 1122 bool may_load = result != ExtensionState::BLOCKED;
973 if (!may_load && error) 1123 if (!may_load && error)
974 *error = GetExtensionsLockedMessage(); 1124 *error = GetExtensionsLockedMessage();
975 return may_load; 1125 return may_load;
976 } 1126 }
977 1127
978 bool SupervisedUserService::UserMayModifySettings( 1128 bool SupervisedUserService::UserMayModifySettings(const Extension* extension,
979 const extensions::Extension* extension, 1129 base::string16* error) const {
980 base::string16* error) const {
981 DCHECK(ProfileIsSupervised()); 1130 DCHECK(ProfileIsSupervised());
982 ExtensionState result = GetExtensionState(extension); 1131 ExtensionState result = GetExtensionState(*extension);
983 bool may_modify = (result == EXTENSION_ALLOWED); 1132 // While the following check allows the supervised user to modify the settings
1133 // and enable or disable the extension, MustRemainDisabled properly takes care
1134 // of keeping an extension disabled when required.
1135 // For custodian-installed extensions, the state is always FORCED, even if
1136 // it's waiting for an update approval.
1137 bool may_modify = result != ExtensionState::FORCED;
984 if (!may_modify && error) 1138 if (!may_modify && error)
985 *error = GetExtensionsLockedMessage(); 1139 *error = GetExtensionsLockedMessage();
986 return may_modify; 1140 return may_modify;
987 } 1141 }
988 1142
989 // Note: Having MustRemainInstalled always say "true" for custodian-installed 1143 // Note: Having MustRemainInstalled always say "true" for custodian-installed
990 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but 1144 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but
991 // exactly what we want). 1145 // exactly what we want).
992 bool SupervisedUserService::MustRemainInstalled( 1146 bool SupervisedUserService::MustRemainInstalled(const Extension* extension,
993 const extensions::Extension* extension, 1147 base::string16* error) const {
994 base::string16* error) const {
995 DCHECK(ProfileIsSupervised()); 1148 DCHECK(ProfileIsSupervised());
996 ExtensionState result = GetExtensionState(extension); 1149 ExtensionState result = GetExtensionState(*extension);
997 bool may_not_uninstall = (result == EXTENSION_FORCED); 1150 bool may_not_uninstall = (result == ExtensionState::FORCED);
998 if (may_not_uninstall && error) 1151 if (may_not_uninstall && error)
999 *error = GetExtensionsLockedMessage(); 1152 *error = GetExtensionsLockedMessage();
1000 return may_not_uninstall; 1153 return may_not_uninstall;
1001 } 1154 }
1002 1155
1156 bool SupervisedUserService::MustRemainDisabled(const Extension* extension,
1157 Extension::DisableReason* reason,
1158 base::string16* error) const {
1159 DCHECK(ProfileIsSupervised());
1160 ExtensionState state = GetExtensionState(*extension);
1161 bool must_remain_disabled = state == ExtensionState::BLOCKED ||
1162 state == ExtensionState::REQUIRE_APPROVAL;
1163
1164 if (must_remain_disabled) {
1165 if (error)
1166 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER);
1167 // If the extension must remain disabled due to permission increase,
1168 // then the update request has been already sent at update time.
1169 // We do nothing and we don't add an extra disable reason.
1170 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
1171 if (extension_prefs->HasDisableReason(
1172 extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE)) {
1173 if (reason)
1174 *reason = Extension::DISABLE_PERMISSIONS_INCREASE;
1175 return true;
1176 }
1177 if (reason)
1178 *reason = Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED;
1179 if (base::FeatureList::IsEnabled(
1180 supervised_users::kSupervisedUserInitiatedExtensionInstall)) {
1181 // If the Extension isn't pending a custodian approval already, send
1182 // an approval request.
1183 if (!extension_prefs->HasDisableReason(
1184 extension->id(),
1185 Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)) {
1186 // MustRemainDisabled is a const method and hence cannot call
1187 // AddExtensionInstallRequest directly.
1188 SupervisedUserService* supervised_user_service =
1189 SupervisedUserServiceFactory::GetForProfile(profile_);
1190 supervised_user_service->AddExtensionInstallRequest(
1191 extension->id(), *extension->version());
1192 }
1193 }
1194 }
1195 return must_remain_disabled;
1196 }
1197
1003 void SupervisedUserService::SetExtensionsActive() { 1198 void SupervisedUserService::SetExtensionsActive() {
1004 extensions::ExtensionSystem* extension_system = 1199 extensions::ExtensionSystem* extension_system =
1005 extensions::ExtensionSystem::Get(profile_); 1200 extensions::ExtensionSystem::Get(profile_);
1006 extensions::ManagementPolicy* management_policy = 1201 extensions::ManagementPolicy* management_policy =
1007 extension_system->management_policy(); 1202 extension_system->management_policy();
1008 1203
1009 if (management_policy) { 1204 if (management_policy) {
1010 if (active_) 1205 if (active_)
1011 management_policy->RegisterProvider(this); 1206 management_policy->RegisterProvider(this);
1012 else 1207 else
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); 1253 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile"));
1059 1254
1060 is_profile_active_ = profile_became_active; 1255 is_profile_active_ = profile_became_active;
1061 } 1256 }
1062 #endif // !defined(OS_ANDROID) 1257 #endif // !defined(OS_ANDROID)
1063 1258
1064 void SupervisedUserService::OnSiteListUpdated() { 1259 void SupervisedUserService::OnSiteListUpdated() {
1065 FOR_EACH_OBSERVER( 1260 FOR_EACH_OBSERVER(
1066 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); 1261 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged());
1067 } 1262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698