OLD | NEW |
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/ui/webui/options/supervised_user_import_handler.h" | 5 #include "chrome/browser/ui/webui/options/supervised_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" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 service->RemoveObserver(this); | 60 service->RemoveObserver(this); |
61 subscription_.reset(); | 61 subscription_.reset(); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 void SupervisedUserImportHandler::GetLocalizedValues( | 65 void SupervisedUserImportHandler::GetLocalizedValues( |
66 base::DictionaryValue* localized_strings) { | 66 base::DictionaryValue* localized_strings) { |
67 DCHECK(localized_strings); | 67 DCHECK(localized_strings); |
68 | 68 |
69 static OptionsStringResource resources[] = { | 69 static OptionsStringResource resources[] = { |
70 { "managedUserImportTitle", IDS_IMPORT_EXISTING_SUPERVISED_USER_TITLE }, | 70 { "supervisedUserImportTitle", |
71 { "managedUserImportText", IDS_IMPORT_EXISTING_SUPERVISED_USER_TEXT }, | 71 IDS_IMPORT_EXISTING_SUPERVISED_USER_TITLE }, |
| 72 { "supervisedUserImportText", IDS_IMPORT_EXISTING_SUPERVISED_USER_TEXT }, |
72 { "createNewUserLink", IDS_CREATE_NEW_USER_LINK }, | 73 { "createNewUserLink", IDS_CREATE_NEW_USER_LINK }, |
73 { "managedUserImportOk", IDS_IMPORT_EXISTING_SUPERVISED_USER_OK }, | 74 { "supervisedUserImportOk", IDS_IMPORT_EXISTING_SUPERVISED_USER_OK }, |
74 { "managedUserImportSigninError", | 75 { "supervisedUserImportSigninError", |
75 IDS_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR }, | 76 IDS_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR }, |
76 { "managedUserAlreadyOnThisDevice", | 77 { "supervisedUserAlreadyOnThisDevice", |
77 IDS_SUPERVISED_USER_ALREADY_ON_THIS_DEVICE }, | 78 IDS_SUPERVISED_USER_ALREADY_ON_THIS_DEVICE }, |
78 { "noExistingManagedUsers", IDS_SUPERVISED_USER_NO_EXISTING_ERROR }, | 79 { "noExistingSupervisedUsers", IDS_SUPERVISED_USER_NO_EXISTING_ERROR }, |
79 { "managedUserSelectAvatarTitle", | 80 { "supervisedUserSelectAvatarTitle", |
80 IDS_SUPERVISED_USER_SELECT_AVATAR_TITLE }, | 81 IDS_SUPERVISED_USER_SELECT_AVATAR_TITLE }, |
81 { "managedUserSelectAvatarText", IDS_SUPERVISED_USER_SELECT_AVATAR_TEXT }, | 82 { "supervisedUserSelectAvatarText", |
82 { "managedUserSelectAvatarOk", IDS_SUPERVISED_USER_SELECT_AVATAR_OK }, | 83 IDS_SUPERVISED_USER_SELECT_AVATAR_TEXT }, |
| 84 { "supervisedUserSelectAvatarOk", IDS_SUPERVISED_USER_SELECT_AVATAR_OK }, |
83 }; | 85 }; |
84 | 86 |
85 RegisterStrings(localized_strings, resources, arraysize(resources)); | 87 RegisterStrings(localized_strings, resources, arraysize(resources)); |
86 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); | 88 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); |
87 } | 89 } |
88 | 90 |
89 void SupervisedUserImportHandler::InitializeHandler() { | 91 void SupervisedUserImportHandler::InitializeHandler() { |
90 Profile* profile = Profile::FromWebUI(web_ui()); | 92 Profile* profile = Profile::FromWebUI(web_ui()); |
91 if (!profile->IsSupervised()) { | 93 if (!profile->IsSupervised()) { |
92 SupervisedUserSyncService* sync_service = | 94 SupervisedUserSyncService* sync_service = |
(...skipping 10 matching lines...) Expand all Loading... |
103 weak_ptr_factory_.GetWeakPtr())); | 105 weak_ptr_factory_.GetWeakPtr())); |
104 } else { | 106 } else { |
105 DCHECK(!SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( | 107 DCHECK(!SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( |
106 profile)); | 108 profile)); |
107 DCHECK(!ProfileOAuth2TokenServiceFactory::GetForProfile(profile)); | 109 DCHECK(!ProfileOAuth2TokenServiceFactory::GetForProfile(profile)); |
108 } | 110 } |
109 } | 111 } |
110 } | 112 } |
111 | 113 |
112 void SupervisedUserImportHandler::RegisterMessages() { | 114 void SupervisedUserImportHandler::RegisterMessages() { |
113 web_ui()->RegisterMessageCallback("requestManagedUserImportUpdate", | 115 web_ui()->RegisterMessageCallback("requestSupervisedUserImportUpdate", |
114 base::Bind(&SupervisedUserImportHandler:: | 116 base::Bind(&SupervisedUserImportHandler:: |
115 RequestSupervisedUserImportUpdate, | 117 RequestSupervisedUserImportUpdate, |
116 base::Unretained(this))); | 118 base::Unretained(this))); |
117 } | 119 } |
118 | 120 |
119 void SupervisedUserImportHandler::OnSupervisedUsersChanged() { | 121 void SupervisedUserImportHandler::OnSupervisedUsersChanged() { |
120 FetchSupervisedUsers(); | 122 FetchSupervisedUsers(); |
121 } | 123 } |
122 | 124 |
123 void SupervisedUserImportHandler::FetchSupervisedUsers() { | 125 void SupervisedUserImportHandler::FetchSupervisedUsers() { |
124 web_ui()->CallJavascriptFunction("options.ManagedUserListData.resetPromise"); | 126 web_ui()->CallJavascriptFunction( |
| 127 "options.SupervisedUserListData.resetPromise"); |
125 RequestSupervisedUserImportUpdate(NULL); | 128 RequestSupervisedUserImportUpdate(NULL); |
126 } | 129 } |
127 | 130 |
128 void SupervisedUserImportHandler::RequestSupervisedUserImportUpdate( | 131 void SupervisedUserImportHandler::RequestSupervisedUserImportUpdate( |
129 const base::ListValue* /* args */) { | 132 const base::ListValue* /* args */) { |
130 if (Profile::FromWebUI(web_ui())->IsSupervised()) | 133 if (Profile::FromWebUI(web_ui())->IsSupervised()) |
131 return; | 134 return; |
132 | 135 |
133 if (!IsAccountConnected() || HasAuthError()) { | 136 if (!IsAccountConnected() || HasAuthError()) { |
134 ClearSupervisedUsersAndShowError(); | 137 ClearSupervisedUsersAndShowError(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 profiles::GetDefaultAvatarIconUrl(avatar_index); | 201 profiles::GetDefaultAvatarIconUrl(avatar_index); |
199 supervised_user->SetString("iconURL", avatar_url); | 202 supervised_user->SetString("iconURL", avatar_url); |
200 bool on_current_device = | 203 bool on_current_device = |
201 supervised_user_ids.find(it.key()) != supervised_user_ids.end(); | 204 supervised_user_ids.find(it.key()) != supervised_user_ids.end(); |
202 supervised_user->SetBoolean("onCurrentDevice", on_current_device); | 205 supervised_user->SetBoolean("onCurrentDevice", on_current_device); |
203 | 206 |
204 supervised_users.Append(supervised_user); | 207 supervised_users.Append(supervised_user); |
205 } | 208 } |
206 | 209 |
207 web_ui()->CallJavascriptFunction( | 210 web_ui()->CallJavascriptFunction( |
208 "options.ManagedUserListData.receiveExistingManagedUsers", | 211 "options.SupervisedUserListData.receiveExistingSupervisedUsers", |
209 supervised_users); | 212 supervised_users); |
210 } | 213 } |
211 | 214 |
212 void SupervisedUserImportHandler::ClearSupervisedUsersAndShowError() { | 215 void SupervisedUserImportHandler::ClearSupervisedUsersAndShowError() { |
213 web_ui()->CallJavascriptFunction("options.ManagedUserListData.onSigninError"); | 216 web_ui()->CallJavascriptFunction( |
| 217 "options.SupervisedUserListData.onSigninError"); |
214 } | 218 } |
215 | 219 |
216 bool SupervisedUserImportHandler::IsAccountConnected() const { | 220 bool SupervisedUserImportHandler::IsAccountConnected() const { |
217 Profile* profile = Profile::FromWebUI(web_ui()); | 221 Profile* profile = Profile::FromWebUI(web_ui()); |
218 SigninManagerBase* signin_manager = | 222 SigninManagerBase* signin_manager = |
219 SigninManagerFactory::GetForProfile(profile); | 223 SigninManagerFactory::GetForProfile(profile); |
220 return signin_manager && !signin_manager->GetAuthenticatedUsername().empty(); | 224 return signin_manager && !signin_manager->GetAuthenticatedUsername().empty(); |
221 } | 225 } |
222 | 226 |
223 bool SupervisedUserImportHandler::HasAuthError() const { | 227 bool SupervisedUserImportHandler::HasAuthError() const { |
(...skipping 19 matching lines...) Expand all Loading... |
243 const std::string& key) { | 247 const std::string& key) { |
244 if (key == supervised_users::kChromeAvatarIndex) | 248 if (key == supervised_users::kChromeAvatarIndex) |
245 FetchSupervisedUsers(); | 249 FetchSupervisedUsers(); |
246 } | 250 } |
247 | 251 |
248 void SupervisedUserImportHandler::OnErrorChanged() { | 252 void SupervisedUserImportHandler::OnErrorChanged() { |
249 FetchSupervisedUsers(); | 253 FetchSupervisedUsers(); |
250 } | 254 } |
251 | 255 |
252 } // namespace options | 256 } // namespace options |
OLD | NEW |