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/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/managed_mode/managed_user_constants.h" |
| 15 #include "chrome/browser/managed_mode/managed_user_shared_settings_service.h" |
| 16 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto
ry.h" |
14 #include "chrome/browser/managed_mode/managed_user_sync_service.h" | 17 #include "chrome/browser/managed_mode/managed_user_sync_service.h" |
15 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" | 18 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" |
16 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_info_cache.h" | 20 #include "chrome/browser/profiles/profile_info_cache.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/signin/signin_global_error.h" | 22 #include "chrome/browser/signin/signin_global_error.h" |
20 #include "chrome/browser/signin/signin_manager.h" | 23 #include "chrome/browser/signin/signin_manager.h" |
21 #include "chrome/browser/signin/signin_manager_factory.h" | 24 #include "chrome/browser/signin/signin_manager_factory.h" |
22 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 g_browser_process->profile_manager()->GetProfileInfoCache(); | 127 g_browser_process->profile_manager()->GetProfileInfoCache(); |
125 | 128 |
126 // Collect the ids of local supervised user profiles. | 129 // Collect the ids of local supervised user profiles. |
127 std::set<std::string> managed_user_ids; | 130 std::set<std::string> managed_user_ids; |
128 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 131 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
129 if (cache.ProfileIsManagedAtIndex(i)) | 132 if (cache.ProfileIsManagedAtIndex(i)) |
130 managed_user_ids.insert(cache.GetManagedUserIdOfProfileAtIndex(i)); | 133 managed_user_ids.insert(cache.GetManagedUserIdOfProfileAtIndex(i)); |
131 } | 134 } |
132 | 135 |
133 base::ListValue managed_users; | 136 base::ListValue managed_users; |
| 137 Profile* profile = Profile::FromWebUI(web_ui()); |
| 138 ManagedUserSharedSettingsService* service = |
| 139 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); |
134 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 140 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
135 const base::DictionaryValue* value = NULL; | 141 const base::DictionaryValue* value = NULL; |
136 bool success = it.value().GetAsDictionary(&value); | 142 bool success = it.value().GetAsDictionary(&value); |
137 DCHECK(success); | 143 DCHECK(success); |
138 std::string name; | 144 std::string name; |
139 value->GetString(ManagedUserSyncService::kName, &name); | 145 value->GetString(ManagedUserSyncService::kName, &name); |
140 std::string avatar_str; | |
141 value->GetString(ManagedUserSyncService::kChromeAvatar, &avatar_str); | |
142 | 146 |
143 base::DictionaryValue* managed_user = new base::DictionaryValue; | 147 base::DictionaryValue* managed_user = new base::DictionaryValue; |
144 managed_user->SetString("id", it.key()); | 148 managed_user->SetString("id", it.key()); |
145 managed_user->SetString("name", name); | 149 managed_user->SetString("name", name); |
146 | 150 |
147 int avatar_index = ManagedUserSyncService::kNoAvatar; | 151 int avatar_index = ManagedUserSyncService::kNoAvatar; |
148 success = ManagedUserSyncService::GetAvatarIndex(avatar_str, &avatar_index); | 152 const base::Value* avatar_index_value = |
| 153 service->GetValue(it.key(), managed_users::kChromeAvatarIndex); |
| 154 if (avatar_index_value) { |
| 155 success = avatar_index_value->GetAsInteger(&avatar_index); |
| 156 } else { |
| 157 // Check if there is a legacy avatar index stored. |
| 158 std::string avatar_str; |
| 159 value->GetString(ManagedUserSyncService::kChromeAvatar, &avatar_str); |
| 160 success = |
| 161 ManagedUserSyncService::GetAvatarIndex(avatar_str, &avatar_index); |
| 162 } |
149 DCHECK(success); | 163 DCHECK(success); |
150 managed_user->SetBoolean("needAvatar", | 164 managed_user->SetBoolean("needAvatar", |
151 avatar_index == ManagedUserSyncService::kNoAvatar); | 165 avatar_index == ManagedUserSyncService::kNoAvatar); |
152 | 166 |
153 std::string supervised_user_icon = | 167 std::string supervised_user_icon = |
154 std::string(chrome::kChromeUIThemeURL) + | 168 std::string(chrome::kChromeUIThemeURL) + |
155 "IDR_SUPERVISED_USER_PLACEHOLDER"; | 169 "IDR_SUPERVISED_USER_PLACEHOLDER"; |
156 std::string avatar_url = | 170 std::string avatar_url = |
157 avatar_index == ManagedUserSyncService::kNoAvatar ? | 171 avatar_index == ManagedUserSyncService::kNoAvatar ? |
158 supervised_user_icon : | 172 supervised_user_icon : |
(...skipping 29 matching lines...) Expand all Loading... |
188 GoogleServiceAuthError::State state = | 202 GoogleServiceAuthError::State state = |
189 signin_global_error->GetLastAuthError().state(); | 203 signin_global_error->GetLastAuthError().state(); |
190 | 204 |
191 return state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 205 return state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
192 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || | 206 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || |
193 state == GoogleServiceAuthError::ACCOUNT_DELETED || | 207 state == GoogleServiceAuthError::ACCOUNT_DELETED || |
194 state == GoogleServiceAuthError::ACCOUNT_DISABLED; | 208 state == GoogleServiceAuthError::ACCOUNT_DISABLED; |
195 } | 209 } |
196 | 210 |
197 } // namespace options | 211 } // namespace options |
OLD | NEW |