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

Side by Side Diff: chrome/browser/ui/webui/options/browser_options_handler.cc

Issue 22405002: Move the managed user ID validity check out of the general code path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/options/browser_options_handler.h" 5 #include "chrome/browser/ui/webui/options/browser_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 bool create_shortcut = false; 1116 bool create_shortcut = false;
1117 bool managed_user = false; 1117 bool managed_user = false;
1118 if (args->GetString(0, &name) && args->GetString(1, &icon)) { 1118 if (args->GetString(0, &name) && args->GetString(1, &icon)) {
1119 if (args->GetBoolean(2, &create_shortcut)) { 1119 if (args->GetBoolean(2, &create_shortcut)) {
1120 bool success = args->GetBoolean(3, &managed_user); 1120 bool success = args->GetBoolean(3, &managed_user);
1121 DCHECK(success); 1121 DCHECK(success);
1122 success = args->GetString(4, &managed_user_id); 1122 success = args->GetString(4, &managed_user_id);
1123 DCHECK(success); 1123 DCHECK(success);
1124 } 1124 }
1125 } 1125 }
1126 if (!IsValidExistingManagedUserId(managed_user_id))
1127 return;
1128 1126
1129 std::vector<ProfileManager::CreateCallback> callbacks; 1127 std::vector<ProfileManager::CreateCallback> callbacks;
1130 if (create_shortcut) 1128 if (create_shortcut)
1131 callbacks.push_back(base::Bind(&CreateDesktopShortcutForProfile)); 1129 callbacks.push_back(base::Bind(&CreateDesktopShortcutForProfile));
1132 1130
1133 ProfileManager::CreateCallback show_user_feedback = 1131 ProfileManager::CreateCallback show_user_feedback =
1134 base::Bind(&BrowserOptionsHandler::ShowProfileCreationFeedback, 1132 base::Bind(&BrowserOptionsHandler::ShowProfileCreationFeedback,
1135 weak_ptr_factory_.GetWeakPtr(), GetDesktopType(), 1133 weak_ptr_factory_.GetWeakPtr(), GetDesktopType(),
1136 managed_user); 1134 managed_user);
1137 1135
1138 if (managed_user && ManagedUserService::AreManagedUsersEnabled()) { 1136 if (managed_user && ManagedUserService::AreManagedUsersEnabled()) {
1137 if (!IsValidExistingManagedUserId(managed_user_id))
1138 return;
1139
1139 if (managed_user_id.empty()) { 1140 if (managed_user_id.empty()) {
1140 managed_user_id = 1141 managed_user_id =
1141 ManagedUserRegistrationUtility::GenerateNewManagedUserId(); 1142 ManagedUserRegistrationUtility::GenerateNewManagedUserId();
1142 } 1143 }
1143 callbacks.push_back( 1144 callbacks.push_back(
1144 base::Bind(&BrowserOptionsHandler::RegisterManagedUser, 1145 base::Bind(&BrowserOptionsHandler::RegisterManagedUser,
1145 weak_ptr_factory_.GetWeakPtr(), 1146 weak_ptr_factory_.GetWeakPtr(),
1146 show_user_feedback, 1147 show_user_feedback,
1147 managed_user_id)); 1148 managed_user_id));
1148 } else { 1149 } else {
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 !proxy_config->IsUserModifiable()); 1739 !proxy_config->IsUserModifiable());
1739 base::FundamentalValue extension_controlled(is_extension_controlled); 1740 base::FundamentalValue extension_controlled(is_extension_controlled);
1740 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection", 1741 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection",
1741 disabled, extension_controlled); 1742 disabled, extension_controlled);
1742 1743
1743 #endif // !defined(OS_CHROMEOS) 1744 #endif // !defined(OS_CHROMEOS)
1744 } 1745 }
1745 1746
1746 bool BrowserOptionsHandler::IsValidExistingManagedUserId( 1747 bool BrowserOptionsHandler::IsValidExistingManagedUserId(
1747 const std::string& existing_managed_user_id) const { 1748 const std::string& existing_managed_user_id) const {
1749 if (existing_managed_user_id.empty())
1750 return true;
1751
1748 if (!CommandLine::ForCurrentProcess()->HasSwitch( 1752 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1749 switches::kAllowCreateExistingManagedUsers)) { 1753 switches::kAllowCreateExistingManagedUsers)) {
1750 return false; 1754 return false;
1751 } 1755 }
1752 1756
1753 if (existing_managed_user_id.empty())
1754 return true;
1755 DictionaryPrefUpdate update(Profile::FromWebUI(web_ui())->GetPrefs(), 1757 DictionaryPrefUpdate update(Profile::FromWebUI(web_ui())->GetPrefs(),
1756 prefs::kManagedUsers); 1758 prefs::kManagedUsers);
1757 DictionaryValue* dict = update.Get(); 1759 DictionaryValue* dict = update.Get();
1758 if (!dict->HasKey(existing_managed_user_id)) 1760 if (!dict->HasKey(existing_managed_user_id))
1759 return false; 1761 return false;
1760 1762
1761 // Check if this managed user is already exists on this machine. 1763 // Check if this managed user already exists on this machine.
1762 const ProfileInfoCache& cache = 1764 const ProfileInfoCache& cache =
1763 g_browser_process->profile_manager()->GetProfileInfoCache(); 1765 g_browser_process->profile_manager()->GetProfileInfoCache();
1764 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { 1766 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
1765 if (existing_managed_user_id == cache.GetManagedUserIdOfProfileAtIndex(i)) 1767 if (existing_managed_user_id == cache.GetManagedUserIdOfProfileAtIndex(i))
1766 return false; 1768 return false;
1767 } 1769 }
1768 return true; 1770 return true;
1769 } 1771 }
1770 1772
1771 } // namespace options 1773 } // namespace options
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698