OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/managed_user_import_handler.h" | 5 #include "chrome/browser/ui/webui/options/managed_user_import_handler.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/managed_mode/managed_user_sync_service.h" | 15 #include "chrome/browser/managed_mode/managed_user_sync_service.h" |
15 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" | 16 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_info_cache.h" | 18 #include "chrome/browser/profiles/profile_info_cache.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/signin/signin_global_error.h" | 20 #include "chrome/browser/signin/signin_global_error.h" |
20 #include "chrome/browser/signin/signin_manager.h" | 21 #include "chrome/browser/signin/signin_manager.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 DCHECK(localized_strings); | 56 DCHECK(localized_strings); |
56 | 57 |
57 static OptionsStringResource resources[] = { | 58 static OptionsStringResource resources[] = { |
58 { "managedUserImportTitle", IDS_IMPORT_EXISTING_MANAGED_USER_TITLE }, | 59 { "managedUserImportTitle", IDS_IMPORT_EXISTING_MANAGED_USER_TITLE }, |
59 { "managedUserImportText", IDS_IMPORT_EXISTING_MANAGED_USER_TEXT }, | 60 { "managedUserImportText", IDS_IMPORT_EXISTING_MANAGED_USER_TEXT }, |
60 { "createNewUserLink", IDS_CREATE_NEW_USER_LINK }, | 61 { "createNewUserLink", IDS_CREATE_NEW_USER_LINK }, |
61 { "managedUserImportOk", IDS_IMPORT_EXISTING_MANAGED_USER_OK }, | 62 { "managedUserImportOk", IDS_IMPORT_EXISTING_MANAGED_USER_OK }, |
62 { "managedUserImportSigninError", IDS_MANAGED_USER_IMPORT_SIGN_IN_ERROR }, | 63 { "managedUserImportSigninError", IDS_MANAGED_USER_IMPORT_SIGN_IN_ERROR }, |
63 { "managedUserAlreadyOnThisDevice", | 64 { "managedUserAlreadyOnThisDevice", |
64 IDS_MANAGED_USER_ALREADY_ON_THIS_DEVICE }, | 65 IDS_MANAGED_USER_ALREADY_ON_THIS_DEVICE }, |
| 66 { "managedUserNameConflict", IDS_MANAGED_USER_NAME_CONFLICT }, |
65 { "noExistingManagedUsers", IDS_MANAGED_USER_NO_EXISTING_ERROR }, | 67 { "noExistingManagedUsers", IDS_MANAGED_USER_NO_EXISTING_ERROR }, |
66 { "managedUserSelectAvatarTitle", IDS_MANAGED_USER_SELECT_AVATAR_TITLE }, | 68 { "managedUserSelectAvatarTitle", IDS_MANAGED_USER_SELECT_AVATAR_TITLE }, |
67 { "managedUserSelectAvatarText", IDS_MANAGED_USER_SELECT_AVATAR_TEXT }, | 69 { "managedUserSelectAvatarText", IDS_MANAGED_USER_SELECT_AVATAR_TEXT }, |
68 { "managedUserSelectAvatarOk", IDS_MANAGED_USER_SELECT_AVATAR_OK }, | 70 { "managedUserSelectAvatarOk", IDS_MANAGED_USER_SELECT_AVATAR_OK }, |
69 }; | 71 }; |
70 | 72 |
71 RegisterStrings(localized_strings, resources, arraysize(resources)); | 73 RegisterStrings(localized_strings, resources, arraysize(resources)); |
72 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); | 74 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); |
73 } | 75 } |
74 | 76 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 base::Bind(&ManagedUserImportHandler::SendExistingManagedUsers, | 117 base::Bind(&ManagedUserImportHandler::SendExistingManagedUsers, |
116 weak_ptr_factory_.GetWeakPtr())); | 118 weak_ptr_factory_.GetWeakPtr())); |
117 } | 119 } |
118 } | 120 } |
119 | 121 |
120 void ManagedUserImportHandler::SendExistingManagedUsers( | 122 void ManagedUserImportHandler::SendExistingManagedUsers( |
121 const base::DictionaryValue* dict) { | 123 const base::DictionaryValue* dict) { |
122 DCHECK(dict); | 124 DCHECK(dict); |
123 const ProfileInfoCache& cache = | 125 const ProfileInfoCache& cache = |
124 g_browser_process->profile_manager()->GetProfileInfoCache(); | 126 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 127 |
| 128 // Collect the names of the local profiles. |
| 129 std::vector<base::string16> profile_names_list = |
| 130 ProfileInfoCache::GetProfileNames(); |
| 131 std::set<std::string> profile_names; |
| 132 for (size_t i = 0; i < profile_names_list.size(); ++i) |
| 133 profile_names.insert(UTF16ToUTF8(profile_names_list[i])); |
| 134 |
| 135 // Collect the ids of local supervised user profiles. |
125 std::set<std::string> managed_user_ids; | 136 std::set<std::string> managed_user_ids; |
126 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) | 137 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
127 managed_user_ids.insert(cache.GetManagedUserIdOfProfileAtIndex(i)); | 138 if (cache.ProfileIsManagedAtIndex(i)) |
| 139 managed_user_ids.insert(cache.GetManagedUserIdOfProfileAtIndex(i)); |
| 140 } |
128 | 141 |
129 base::ListValue managed_users; | 142 base::ListValue managed_users; |
130 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 143 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
131 const base::DictionaryValue* value = NULL; | 144 const base::DictionaryValue* value = NULL; |
132 bool success = it.value().GetAsDictionary(&value); | 145 bool success = it.value().GetAsDictionary(&value); |
133 DCHECK(success); | 146 DCHECK(success); |
134 std::string name; | 147 std::string name; |
135 value->GetString(ManagedUserSyncService::kName, &name); | 148 value->GetString(ManagedUserSyncService::kName, &name); |
136 std::string avatar_str; | 149 std::string avatar_str; |
137 value->GetString(ManagedUserSyncService::kChromeAvatar, &avatar_str); | 150 value->GetString(ManagedUserSyncService::kChromeAvatar, &avatar_str); |
(...skipping 12 matching lines...) Expand all Loading... |
150 std::string(chrome::kChromeUIThemeURL) + | 163 std::string(chrome::kChromeUIThemeURL) + |
151 "IDR_SUPERVISED_USER_PLACEHOLDER"; | 164 "IDR_SUPERVISED_USER_PLACEHOLDER"; |
152 std::string avatar_url = | 165 std::string avatar_url = |
153 avatar_index == ManagedUserSyncService::kNoAvatar ? | 166 avatar_index == ManagedUserSyncService::kNoAvatar ? |
154 supervised_user_icon : | 167 supervised_user_icon : |
155 ProfileInfoCache::GetDefaultAvatarIconUrl(avatar_index); | 168 ProfileInfoCache::GetDefaultAvatarIconUrl(avatar_index); |
156 managed_user->SetString("iconURL", avatar_url); | 169 managed_user->SetString("iconURL", avatar_url); |
157 bool on_current_device = | 170 bool on_current_device = |
158 managed_user_ids.find(it.key()) != managed_user_ids.end(); | 171 managed_user_ids.find(it.key()) != managed_user_ids.end(); |
159 managed_user->SetBoolean("onCurrentDevice", on_current_device); | 172 managed_user->SetBoolean("onCurrentDevice", on_current_device); |
| 173 bool name_conflict = profile_names.find(name) != profile_names.end(); |
| 174 managed_user->SetBoolean("nameConflict", name_conflict); |
160 | 175 |
161 managed_users.Append(managed_user); | 176 managed_users.Append(managed_user); |
162 } | 177 } |
163 | 178 |
164 web_ui()->CallJavascriptFunction( | 179 web_ui()->CallJavascriptFunction( |
165 "options.ManagedUserListData.receiveExistingManagedUsers", | 180 "options.ManagedUserListData.receiveExistingManagedUsers", |
166 managed_users); | 181 managed_users); |
167 } | 182 } |
168 | 183 |
169 void ManagedUserImportHandler::ClearManagedUsersAndShowError() { | 184 void ManagedUserImportHandler::ClearManagedUsersAndShowError() { |
(...skipping 14 matching lines...) Expand all Loading... |
184 GoogleServiceAuthError::State state = | 199 GoogleServiceAuthError::State state = |
185 signin_global_error->GetLastAuthError().state(); | 200 signin_global_error->GetLastAuthError().state(); |
186 | 201 |
187 return state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 202 return state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
188 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || | 203 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || |
189 state == GoogleServiceAuthError::ACCOUNT_DELETED || | 204 state == GoogleServiceAuthError::ACCOUNT_DELETED || |
190 state == GoogleServiceAuthError::ACCOUNT_DISABLED; | 205 state == GoogleServiceAuthError::ACCOUNT_DISABLED; |
191 } | 206 } |
192 | 207 |
193 } // namespace options | 208 } // namespace options |
OLD | NEW |