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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 namespace options { | 48 namespace options { |
49 | 49 |
50 ManagedUserImportHandler::ManagedUserImportHandler() | 50 ManagedUserImportHandler::ManagedUserImportHandler() |
51 : observer_(this), | 51 : observer_(this), |
52 weak_ptr_factory_(this) {} | 52 weak_ptr_factory_(this) {} |
53 | 53 |
54 ManagedUserImportHandler::~ManagedUserImportHandler() { | 54 ManagedUserImportHandler::~ManagedUserImportHandler() { |
55 Profile* profile = Profile::FromWebUI(web_ui()); | 55 Profile* profile = Profile::FromWebUI(web_ui()); |
56 if (!profile->IsManaged()) { | 56 if (!profile->IsSupervised()) { |
57 ManagedUserSyncService* service = | 57 ManagedUserSyncService* service = |
58 ManagedUserSyncServiceFactory::GetForProfile(profile); | 58 ManagedUserSyncServiceFactory::GetForProfile(profile); |
59 if (service) | 59 if (service) |
60 service->RemoveObserver(this); | 60 service->RemoveObserver(this); |
61 subscription_.reset(); | 61 subscription_.reset(); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 void ManagedUserImportHandler::GetLocalizedValues( | 65 void ManagedUserImportHandler::GetLocalizedValues( |
66 base::DictionaryValue* localized_strings) { | 66 base::DictionaryValue* localized_strings) { |
(...skipping 12 matching lines...) Expand all Loading... |
79 { "managedUserSelectAvatarText", IDS_MANAGED_USER_SELECT_AVATAR_TEXT }, | 79 { "managedUserSelectAvatarText", IDS_MANAGED_USER_SELECT_AVATAR_TEXT }, |
80 { "managedUserSelectAvatarOk", IDS_MANAGED_USER_SELECT_AVATAR_OK }, | 80 { "managedUserSelectAvatarOk", IDS_MANAGED_USER_SELECT_AVATAR_OK }, |
81 }; | 81 }; |
82 | 82 |
83 RegisterStrings(localized_strings, resources, arraysize(resources)); | 83 RegisterStrings(localized_strings, resources, arraysize(resources)); |
84 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); | 84 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); |
85 } | 85 } |
86 | 86 |
87 void ManagedUserImportHandler::InitializeHandler() { | 87 void ManagedUserImportHandler::InitializeHandler() { |
88 Profile* profile = Profile::FromWebUI(web_ui()); | 88 Profile* profile = Profile::FromWebUI(web_ui()); |
89 if (!profile->IsManaged()) { | 89 if (!profile->IsSupervised()) { |
90 ManagedUserSyncService* sync_service = | 90 ManagedUserSyncService* sync_service = |
91 ManagedUserSyncServiceFactory::GetForProfile(profile); | 91 ManagedUserSyncServiceFactory::GetForProfile(profile); |
92 if (sync_service) { | 92 if (sync_service) { |
93 sync_service->AddObserver(this); | 93 sync_service->AddObserver(this); |
94 observer_.Add(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> | 94 observer_.Add(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> |
95 signin_error_controller()); | 95 signin_error_controller()); |
96 ManagedUserSharedSettingsService* settings_service = | 96 ManagedUserSharedSettingsService* settings_service = |
97 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext( | 97 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext( |
98 profile); | 98 profile); |
99 subscription_ = settings_service->Subscribe( | 99 subscription_ = settings_service->Subscribe( |
(...skipping 17 matching lines...) Expand all Loading... |
117 FetchManagedUsers(); | 117 FetchManagedUsers(); |
118 } | 118 } |
119 | 119 |
120 void ManagedUserImportHandler::FetchManagedUsers() { | 120 void ManagedUserImportHandler::FetchManagedUsers() { |
121 web_ui()->CallJavascriptFunction("options.ManagedUserListData.resetPromise"); | 121 web_ui()->CallJavascriptFunction("options.ManagedUserListData.resetPromise"); |
122 RequestManagedUserImportUpdate(NULL); | 122 RequestManagedUserImportUpdate(NULL); |
123 } | 123 } |
124 | 124 |
125 void ManagedUserImportHandler::RequestManagedUserImportUpdate( | 125 void ManagedUserImportHandler::RequestManagedUserImportUpdate( |
126 const base::ListValue* /* args */) { | 126 const base::ListValue* /* args */) { |
127 if (Profile::FromWebUI(web_ui())->IsManaged()) | 127 if (Profile::FromWebUI(web_ui())->IsSupervised()) |
128 return; | 128 return; |
129 | 129 |
130 if (!IsAccountConnected() || HasAuthError()) { | 130 if (!IsAccountConnected() || HasAuthError()) { |
131 ClearManagedUsersAndShowError(); | 131 ClearManagedUsersAndShowError(); |
132 } else { | 132 } else { |
133 ManagedUserSyncService* managed_user_sync_service = | 133 ManagedUserSyncService* managed_user_sync_service = |
134 ManagedUserSyncServiceFactory::GetForProfile( | 134 ManagedUserSyncServiceFactory::GetForProfile( |
135 Profile::FromWebUI(web_ui())); | 135 Profile::FromWebUI(web_ui())); |
136 if (managed_user_sync_service) { | 136 if (managed_user_sync_service) { |
137 managed_user_sync_service->GetManagedUsersAsync( | 137 managed_user_sync_service->GetManagedUsersAsync( |
138 base::Bind(&ManagedUserImportHandler::SendExistingManagedUsers, | 138 base::Bind(&ManagedUserImportHandler::SendExistingManagedUsers, |
139 weak_ptr_factory_.GetWeakPtr())); | 139 weak_ptr_factory_.GetWeakPtr())); |
140 } | 140 } |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 void ManagedUserImportHandler::SendExistingManagedUsers( | 144 void ManagedUserImportHandler::SendExistingManagedUsers( |
145 const base::DictionaryValue* dict) { | 145 const base::DictionaryValue* dict) { |
146 DCHECK(dict); | 146 DCHECK(dict); |
147 const ProfileInfoCache& cache = | 147 const ProfileInfoCache& cache = |
148 g_browser_process->profile_manager()->GetProfileInfoCache(); | 148 g_browser_process->profile_manager()->GetProfileInfoCache(); |
149 | 149 |
150 // Collect the ids of local supervised user profiles. | 150 // Collect the ids of local supervised user profiles. |
151 std::set<std::string> managed_user_ids; | 151 std::set<std::string> managed_user_ids; |
152 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 152 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
153 if (cache.ProfileIsManagedAtIndex(i)) | 153 if (cache.ProfileIsSupervisedAtIndex(i)) |
154 managed_user_ids.insert(cache.GetManagedUserIdOfProfileAtIndex(i)); | 154 managed_user_ids.insert(cache.GetSupervisedUserIdOfProfileAtIndex(i)); |
155 } | 155 } |
156 | 156 |
157 base::ListValue managed_users; | 157 base::ListValue managed_users; |
158 Profile* profile = Profile::FromWebUI(web_ui()); | 158 Profile* profile = Profile::FromWebUI(web_ui()); |
159 ManagedUserSharedSettingsService* service = | 159 ManagedUserSharedSettingsService* service = |
160 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); | 160 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); |
161 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 161 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
162 const base::DictionaryValue* value = NULL; | 162 const base::DictionaryValue* value = NULL; |
163 bool success = it.value().GetAsDictionary(&value); | 163 bool success = it.value().GetAsDictionary(&value); |
164 DCHECK(success); | 164 DCHECK(success); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 const std::string& key) { | 239 const std::string& key) { |
240 if (key == managed_users::kChromeAvatarIndex) | 240 if (key == managed_users::kChromeAvatarIndex) |
241 FetchManagedUsers(); | 241 FetchManagedUsers(); |
242 } | 242 } |
243 | 243 |
244 void ManagedUserImportHandler::OnErrorChanged() { | 244 void ManagedUserImportHandler::OnErrorChanged() { |
245 FetchManagedUsers(); | 245 FetchManagedUsers(); |
246 } | 246 } |
247 | 247 |
248 } // namespace options | 248 } // namespace options |
OLD | NEW |