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

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: Hiding extensions related code behind #ifdefine 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
250 // static 291 // static
251 std::string SupervisedUserService::GetExtensionUpdateRequestId( 292 std::string SupervisedUserService::GetExtensionRequestId(
252 const std::string& extension_id, 293 const std::string& extension_id,
253 const base::Version& version) { 294 const base::Version& version) {
254 return base::StringPrintf("%s:%s", extension_id.c_str(), 295 return base::StringPrintf("%s:%s", extension_id.c_str(),
255 version.GetString().c_str()); 296 version.GetString().c_str());
256 } 297 }
257 298
258 std::string SupervisedUserService::GetCustodianEmailAddress() const { 299 std::string SupervisedUserService::GetCustodianEmailAddress() const {
259 std::string email = profile_->GetPrefs()->GetString( 300 std::string email = profile_->GetPrefs()->GetString(
260 prefs::kSupervisedUserCustodianEmail); 301 prefs::kSupervisedUserCustodianEmail);
261 #if defined(OS_CHROMEOS) 302 #if defined(OS_CHROMEOS)
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 SupervisedUserService::SupervisedUserService(Profile* profile) 522 SupervisedUserService::SupervisedUserService(Profile* profile)
482 : includes_sync_sessions_type_(true), 523 : includes_sync_sessions_type_(true),
483 profile_(profile), 524 profile_(profile),
484 active_(false), 525 active_(false),
485 delegate_(NULL), 526 delegate_(NULL),
486 waiting_for_sync_initialization_(false), 527 waiting_for_sync_initialization_(false),
487 is_profile_active_(false), 528 is_profile_active_(false),
488 did_init_(false), 529 did_init_(false),
489 did_shutdown_(false), 530 did_shutdown_(false),
490 blacklist_state_(BlacklistLoadState::NOT_LOADED), 531 blacklist_state_(BlacklistLoadState::NOT_LOADED),
532 #if defined(ENABLE_EXTENSIONS)
533 registry_observer_(this),
534 #endif
491 weak_ptr_factory_(this) { 535 weak_ptr_factory_(this) {
492 url_filter_context_.ui_url_filter()->AddObserver(this); 536 url_filter_context_.ui_url_filter()->AddObserver(this);
537 #if defined(ENABLE_EXTENSIONS)
538 registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
539 #endif
493 } 540 }
494 541
495 void SupervisedUserService::SetActive(bool active) { 542 void SupervisedUserService::SetActive(bool active) {
496 if (active_ == active) 543 if (active_ == active)
497 return; 544 return;
498 active_ = active; 545 active_ = active;
499 546
500 if (!delegate_ || !delegate_->SetActive(active_)) { 547 if (!delegate_ || !delegate_->SetActive(active_)) {
501 if (active_) { 548 if (active_) {
502 #if !defined(OS_ANDROID) 549 #if !defined(OS_ANDROID)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 594
548 #if defined(ENABLE_EXTENSIONS) 595 #if defined(ENABLE_EXTENSIONS)
549 SetExtensionsActive(); 596 SetExtensionsActive();
550 #endif 597 #endif
551 598
552 if (active_) { 599 if (active_) {
553 pref_change_registrar_.Add( 600 pref_change_registrar_.Add(
554 prefs::kDefaultSupervisedUserFilteringBehavior, 601 prefs::kDefaultSupervisedUserFilteringBehavior,
555 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, 602 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged,
556 base::Unretained(this))); 603 base::Unretained(this)));
604 #if defined(ENABLE_EXTENSIONS)
605 pref_change_registrar_.Add(
606 prefs::kSupervisedUserApprovedExtensions,
607 base::Bind(&SupervisedUserService::UpdateApprovedExtensions,
608 base::Unretained(this)));
609 #endif
557 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, 610 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites,
558 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, 611 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged,
559 base::Unretained(this))); 612 base::Unretained(this)));
560 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, 613 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts,
561 base::Bind(&SupervisedUserService::UpdateManualHosts, 614 base::Bind(&SupervisedUserService::UpdateManualHosts,
562 base::Unretained(this))); 615 base::Unretained(this)));
563 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, 616 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs,
564 base::Bind(&SupervisedUserService::UpdateManualURLs, 617 base::Bind(&SupervisedUserService::UpdateManualURLs,
565 base::Unretained(this))); 618 base::Unretained(this)));
566 for (const char* pref : kCustodianInfoPrefs) { 619 for (const char* pref : kCustodianInfoPrefs) {
567 pref_change_registrar_.Add(pref, 620 pref_change_registrar_.Add(pref,
568 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, 621 base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
569 base::Unretained(this))); 622 base::Unretained(this)));
570 } 623 }
571 624
572 // Initialize the filter. 625 // Initialize the filter.
573 OnDefaultFilteringBehaviorChanged(); 626 OnDefaultFilteringBehaviorChanged();
574 OnSafeSitesSettingChanged(); 627 OnSafeSitesSettingChanged();
575 whitelist_service_->Init(); 628 whitelist_service_->Init();
576 UpdateManualHosts(); 629 UpdateManualHosts();
577 UpdateManualURLs(); 630 UpdateManualURLs();
578 631
632 #if defined(ENABLE_EXTENSIONS)
633 UpdateApprovedExtensions();
634 #endif
635
579 #if !defined(OS_ANDROID) 636 #if !defined(OS_ANDROID)
580 // TODO(bauerb): Get rid of the platform-specific #ifdef here. 637 // TODO(bauerb): Get rid of the platform-specific #ifdef here.
581 // http://crbug.com/313377 638 // http://crbug.com/313377
582 BrowserList::AddObserver(this); 639 BrowserList::AddObserver(this);
583 #endif 640 #endif
584 } else { 641 } else {
585 permissions_creators_.clear(); 642 permissions_creators_.clear();
586 url_reporter_.reset(); 643 url_reporter_.reset();
587 644
588 pref_change_registrar_.Remove( 645 pref_change_registrar_.Remove(
589 prefs::kDefaultSupervisedUserFilteringBehavior); 646 prefs::kDefaultSupervisedUserFilteringBehavior);
647 #if defined(ENABLE_EXTENSIONS)
648 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions);
649 #endif
590 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); 650 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts);
591 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); 651 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs);
592 for (const char* pref : kCustodianInfoPrefs) { 652 for (const char* pref : kCustodianInfoPrefs) {
593 pref_change_registrar_.Remove(pref); 653 pref_change_registrar_.Remove(pref);
594 } 654 }
595 655
596 url_filter_context_.Clear(); 656 url_filter_context_.Clear();
597 FOR_EACH_OBSERVER( 657 FOR_EACH_OBSERVER(
598 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); 658 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged());
599 659
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 ProfileSyncService* sync_service = 977 ProfileSyncService* sync_service =
918 ProfileSyncServiceFactory::GetForProfile(profile_); 978 ProfileSyncServiceFactory::GetForProfile(profile_);
919 979
920 // Can be null in tests. 980 // Can be null in tests.
921 if (sync_service) 981 if (sync_service)
922 sync_service->RemovePreferenceProvider(this); 982 sync_service->RemovePreferenceProvider(this);
923 } 983 }
924 984
925 #if defined(ENABLE_EXTENSIONS) 985 #if defined(ENABLE_EXTENSIONS)
926 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( 986 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState(
927 const extensions::Extension* extension) const { 987 const Extension& extension) const {
928 bool was_installed_by_default = extension->was_installed_by_default(); 988 bool was_installed_by_default = extension.was_installed_by_default();
929 #if defined(OS_CHROMEOS) 989 #if defined(OS_CHROMEOS)
930 // On Chrome OS all external sources are controlled by us so it means that 990 // 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 991 // they are "default". Method was_installed_by_default returns false because
932 // extensions creation flags are ignored in case of default extensions with 992 // extensions creation flags are ignored in case of default extensions with
933 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). 993 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound).
934 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation 994 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation
935 // flags are not ignored. 995 // flags are not ignored.
936 was_installed_by_default = 996 was_installed_by_default =
937 extensions::Manifest::IsExternalLocation(extension->location()); 997 extensions::Manifest::IsExternalLocation(extension.location());
938 #endif 998 #endif
939 // Note: Component extensions are protected from modification/uninstallation 999 // Note: Component extensions are protected from modification/uninstallation
940 // anyway, so there's no need to enforce them again for supervised users. 1000 // anyway, so there's no need to enforce them again for supervised users.
941 // Also, leave policy-installed extensions alone - they have their own 1001 // Also, leave policy-installed extensions alone - they have their own
942 // management; in particular we don't want to override the force-install list. 1002 // management; in particular we don't want to override the force-install list.
943 if (extensions::Manifest::IsComponentLocation(extension->location()) || 1003 if (extensions::Manifest::IsComponentLocation(extension.location()) ||
944 extensions::Manifest::IsPolicyLocation(extension->location()) || 1004 extensions::Manifest::IsPolicyLocation(extension.location()) ||
945 extension->is_theme() || 1005 extension.is_theme() || extension.from_bookmark() ||
946 extension->from_bookmark() || 1006 extension.is_shared_module() || was_installed_by_default) {
947 extension->is_shared_module() || 1007 return ExtensionState::ALLOWED;
948 was_installed_by_default) {
949 return ExtensionState::EXTENSION_ALLOWED;
950 } 1008 }
951 1009
952 if (extensions::util::WasInstalledByCustodian(extension->id(), profile_)) 1010 if (extensions::util::WasInstalledByCustodian(extension.id(), profile_))
953 return ExtensionState::EXTENSION_FORCED; 1011 return ExtensionState::FORCED;
954 1012
955 return ExtensionState::EXTENSION_BLOCKED; 1013 if (!base::FeatureList::IsEnabled(
1014 supervised_users::kSupervisedUserInitiatedExtensionInstall)) {
1015 return ExtensionState::BLOCKED;
1016 }
1017
1018 const std::string& id = extension.id();
1019
1020 auto extension_it = approved_extensions_map_.find(id);
1021 // If the installed version is approved, then the extension is allowed,
1022 // otherwise, it requires approval.
1023 if (extension_it != approved_extensions_map_.end() &&
1024 extension_it->second == *extension.version()) {
1025 return ExtensionState::ALLOWED;
1026 }
1027 return ExtensionState::REQUIRE_APPROVAL;
956 } 1028 }
957 1029
958 std::string SupervisedUserService::GetDebugPolicyProviderName() const { 1030 std::string SupervisedUserService::GetDebugPolicyProviderName() const {
959 // Save the string space in official builds. 1031 // Save the string space in official builds.
960 #ifdef NDEBUG 1032 #ifdef NDEBUG
961 NOTREACHED(); 1033 NOTREACHED();
962 return std::string(); 1034 return std::string();
963 #else 1035 #else
964 return "Supervised User Service"; 1036 return "Supervised User Service";
965 #endif 1037 #endif
966 } 1038 }
967 1039
968 bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, 1040 bool SupervisedUserService::UserMayLoad(const Extension* extension,
969 base::string16* error) const { 1041 base::string16* error) const {
970 DCHECK(ProfileIsSupervised()); 1042 DCHECK(ProfileIsSupervised());
971 ExtensionState result = GetExtensionState(extension); 1043 ExtensionState result = GetExtensionState(*extension);
972 bool may_load = (result != EXTENSION_BLOCKED); 1044 bool may_load = result != ExtensionState::BLOCKED;
973 if (!may_load && error) 1045 if (!may_load && error)
974 *error = GetExtensionsLockedMessage(); 1046 *error = GetExtensionsLockedMessage();
975 return may_load; 1047 return may_load;
976 } 1048 }
977 1049
978 bool SupervisedUserService::UserMayModifySettings( 1050 bool SupervisedUserService::UserMayModifySettings(const Extension* extension,
979 const extensions::Extension* extension, 1051 base::string16* error) const {
980 base::string16* error) const {
981 DCHECK(ProfileIsSupervised()); 1052 DCHECK(ProfileIsSupervised());
982 ExtensionState result = GetExtensionState(extension); 1053 ExtensionState result = GetExtensionState(*extension);
983 bool may_modify = (result == EXTENSION_ALLOWED); 1054 // While the following check allows the supervised user to modify the settings
1055 // and enable or disable the extension, MustRemainDisabled properly takes care
1056 // of keeping an extension disabled when required.
1057 // For custodian-installed extensions, the state is always FORCED, even if
1058 // it's waiting for an update approval.
1059 bool may_modify = result != ExtensionState::FORCED;
984 if (!may_modify && error) 1060 if (!may_modify && error)
985 *error = GetExtensionsLockedMessage(); 1061 *error = GetExtensionsLockedMessage();
986 return may_modify; 1062 return may_modify;
987 } 1063 }
988 1064
989 // Note: Having MustRemainInstalled always say "true" for custodian-installed 1065 // Note: Having MustRemainInstalled always say "true" for custodian-installed
990 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but 1066 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but
991 // exactly what we want). 1067 // exactly what we want).
992 bool SupervisedUserService::MustRemainInstalled( 1068 bool SupervisedUserService::MustRemainInstalled(const Extension* extension,
993 const extensions::Extension* extension, 1069 base::string16* error) const {
994 base::string16* error) const {
995 DCHECK(ProfileIsSupervised()); 1070 DCHECK(ProfileIsSupervised());
996 ExtensionState result = GetExtensionState(extension); 1071 ExtensionState result = GetExtensionState(*extension);
997 bool may_not_uninstall = (result == EXTENSION_FORCED); 1072 bool may_not_uninstall = (result == ExtensionState::FORCED);
998 if (may_not_uninstall && error) 1073 if (may_not_uninstall && error)
999 *error = GetExtensionsLockedMessage(); 1074 *error = GetExtensionsLockedMessage();
1000 return may_not_uninstall; 1075 return may_not_uninstall;
1001 } 1076 }
1002 1077
1078 bool SupervisedUserService::MustRemainDisabled(const Extension* extension,
1079 Extension::DisableReason* reason,
1080 base::string16* error) const {
1081 DCHECK(ProfileIsSupervised());
1082 ExtensionState state = GetExtensionState(*extension);
1083 bool must_remain_disabled = state == ExtensionState::BLOCKED ||
1084 state == ExtensionState::REQUIRE_APPROVAL;
1085
1086 if (must_remain_disabled) {
1087 if (error)
1088 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER);
1089 // If the extension must remain disabled due to permission increase,
1090 // then the update request has been already sent at update time.
1091 // We do nothing and we don't add an extra disable reason.
1092 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
1093 if (extension_prefs->HasDisableReason(
1094 extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE)) {
1095 if (reason)
1096 *reason = Extension::DISABLE_PERMISSIONS_INCREASE;
1097 return true;
1098 }
1099 if (reason)
1100 *reason = Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED;
1101 if (base::FeatureList::IsEnabled(
1102 supervised_users::kSupervisedUserInitiatedExtensionInstall)) {
1103 // If the Extension isn't pending a custodian approval already, send
1104 // an approval request.
1105 if (!extension_prefs->HasDisableReason(
1106 extension->id(),
1107 Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)) {
1108 // MustRemainDisabled is a const method and hence cannot call
1109 // AddExtensionInstallRequest directly.
1110 SupervisedUserService* supervised_user_service =
1111 SupervisedUserServiceFactory::GetForProfile(profile_);
1112 supervised_user_service->AddExtensionInstallRequest(
1113 extension->id(), *extension->version());
1114 }
1115 }
1116 }
1117 return must_remain_disabled;
1118 }
1119
1120 void SupervisedUserService::OnExtensionInstalled(
1121 content::BrowserContext* browser_context,
1122 const extensions::Extension* extension,
1123 bool is_update) {
1124 // This callback is responsible only for updating the approved version
1125 // upon extension update if it doesn't require extra permission.
Marc Treib 2016/06/24 10:58:55 nit: This isn't really accurate anymore. It's also
mamir 2016/06/24 14:43:07 Done.
1126 if (!is_update)
1127 return;
1128
1129 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
1130 const std::string& id = extension->id();
1131 const base::Version& version = *extension->version();
1132
1133 // If an already approved extension is updated without requiring
1134 // new permissions, we update the approved_version and re-enable it.
Marc Treib 2016/06/24 10:58:55 nit: I'd remove the "and re-enable it" part (and m
mamir 2016/06/24 14:43:07 Done.
1135 if (!extension_prefs->HasDisableReason(
1136 id, Extension::DISABLE_PERMISSIONS_INCREASE) &&
1137 approved_extensions_map_.count(id) > 0 &&
1138 approved_extensions_map_[id] < version) {
1139 approved_extensions_map_[id] = version;
1140
1141 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey(
1142 supervised_users::kApprovedExtensions, id);
1143 std::unique_ptr<base::Value> version_value(
1144 new base::StringValue(version.GetString()));
1145 GetSettingsService()->UpdateSetting(key, std::move(version_value));
1146 }
1147 ChangeExtensionStateIfNecessary(id);
1148 }
1149
1150 void SupervisedUserService::UpdateApprovedExtensions() {
1151 const base::DictionaryValue* dict = profile_->GetPrefs()->GetDictionary(
1152 prefs::kSupervisedUserApprovedExtensions);
1153 approved_extensions_map_.clear();
1154 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
1155 std::string version_str;
1156 bool result = it.value().GetAsString(&version_str);
1157 DCHECK(result);
1158 base::Version version(version_str);
1159 if (version.IsValid())
1160 approved_extensions_map_[it.key()] = version;
1161 else
1162 LOG(WARNING) << "Invalid version number " << version_str;
1163 }
1164
1165 for (const auto& extensions_entry : approved_extensions_map_) {
1166 ChangeExtensionStateIfNecessary(extensions_entry.first);
Marc Treib 2016/06/24 10:58:55 Ah, one more thing here: If an approval was remove
mamir 2016/06/24 14:43:07 Well-spotted, thank you! Done and I have updated t
1167 }
1168 }
1169
1170 void SupervisedUserService::ChangeExtensionStateIfNecessary(
1171 const std::string& extension_id) {
1172 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
1173 const Extension* extension = registry->GetInstalledExtension(extension_id);
1174 // If the extension is not installed (yet), do nothing.
1175 // When it gets installed, GetExtensionState() will return ALLOWED, hence
Marc Treib 2016/06/24 10:58:55 IMO this isn't really accurate, GetExtensionState
mamir 2016/06/24 14:43:07 Done.
1176 // it will be enabled.
1177 if (!extension)
1178 return;
1179
1180 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
1181 ExtensionService* service =
1182 ExtensionSystem::Get(profile_)->extension_service();
Marc Treib 2016/06/24 10:58:55 nit: You could move both of these to later in the
mamir 2016/06/24 14:43:07 Done.
1183
1184 ExtensionState state = GetExtensionState(*extension);
1185 // BLOCKED/FORCED extensions should be already disabled/enabled
1186 // and we don't need to change their state here.
1187 if (state == ExtensionState::BLOCKED || state == ExtensionState::FORCED)
Marc Treib 2016/06/24 10:58:55 nit: This might be easier to read as a switch inst
mamir 2016/06/24 14:43:07 Done.
1188 return;
1189
1190 if (state == ExtensionState::REQUIRE_APPROVAL) {
1191 service->DisableExtension(extension_id,
1192 Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED);
1193 return;
1194 }
1195
1196 if (state == ExtensionState::ALLOWED) {
1197 extension_prefs->RemoveDisableReason(
1198 extension_id, Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED);
1199 extension_prefs->RemoveDisableReason(
1200 extension_id, Extension::DISABLE_PERMISSIONS_INCREASE);
1201 // If not disabled for other reasons, enable it.
1202 if (extension_prefs->GetDisableReasons(extension_id) ==
1203 Extension::DISABLE_NONE) {
1204 service->EnableExtension(extension_id);
1205 }
1206 }
1207 }
1208
1003 void SupervisedUserService::SetExtensionsActive() { 1209 void SupervisedUserService::SetExtensionsActive() {
1004 extensions::ExtensionSystem* extension_system = 1210 extensions::ExtensionSystem* extension_system =
1005 extensions::ExtensionSystem::Get(profile_); 1211 extensions::ExtensionSystem::Get(profile_);
1006 extensions::ManagementPolicy* management_policy = 1212 extensions::ManagementPolicy* management_policy =
1007 extension_system->management_policy(); 1213 extension_system->management_policy();
1008 1214
1009 if (management_policy) { 1215 if (management_policy) {
1010 if (active_) 1216 if (active_)
1011 management_policy->RegisterProvider(this); 1217 management_policy->RegisterProvider(this);
1012 else 1218 else
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); 1264 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile"));
1059 1265
1060 is_profile_active_ = profile_became_active; 1266 is_profile_active_ = profile_became_active;
1061 } 1267 }
1062 #endif // !defined(OS_ANDROID) 1268 #endif // !defined(OS_ANDROID)
1063 1269
1064 void SupervisedUserService::OnSiteListUpdated() { 1270 void SupervisedUserService::OnSiteListUpdated() {
1065 FOR_EACH_OBSERVER( 1271 FOR_EACH_OBSERVER(
1066 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); 1272 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged());
1067 } 1273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698