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/managed_mode/managed_user_sync_service.h" |
| 14 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" |
13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_info_cache.h" | 16 #include "chrome/browser/profiles/profile_info_cache.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
17 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
18 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
19 | 21 |
20 namespace options { | 22 namespace options { |
21 | 23 |
22 ManagedUserImportHandler::ManagedUserImportHandler() {} | 24 ManagedUserImportHandler::ManagedUserImportHandler() {} |
(...skipping 30 matching lines...) Expand all Loading... |
53 if (profile->IsManaged()) | 55 if (profile->IsManaged()) |
54 return; | 56 return; |
55 | 57 |
56 const ProfileInfoCache& cache = | 58 const ProfileInfoCache& cache = |
57 g_browser_process->profile_manager()->GetProfileInfoCache(); | 59 g_browser_process->profile_manager()->GetProfileInfoCache(); |
58 std::set<std::string> managed_user_ids; | 60 std::set<std::string> managed_user_ids; |
59 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) | 61 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) |
60 managed_user_ids.insert(cache.GetManagedUserIdOfProfileAtIndex(i)); | 62 managed_user_ids.insert(cache.GetManagedUserIdOfProfileAtIndex(i)); |
61 | 63 |
62 const DictionaryValue* dict = | 64 const DictionaryValue* dict = |
63 profile->GetPrefs()->GetDictionary(prefs::kManagedUsers); | 65 ManagedUserSyncServiceFactory::GetForProfile(profile)->GetManagedUsers(); |
64 ListValue managed_users; | 66 ListValue managed_users; |
65 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 67 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
66 const DictionaryValue* value = NULL; | 68 const DictionaryValue* value = NULL; |
67 bool success = it.value().GetAsDictionary(&value); | 69 bool success = it.value().GetAsDictionary(&value); |
68 DCHECK(success); | 70 DCHECK(success); |
69 std::string name; | 71 std::string name; |
70 value->GetString("name", &name); | 72 value->GetString("name", &name); |
71 | 73 |
72 DictionaryValue* managed_user = new DictionaryValue; | 74 DictionaryValue* managed_user = new DictionaryValue; |
73 managed_user->SetString("id", it.key()); | 75 managed_user->SetString("id", it.key()); |
74 managed_user->SetString("name", name); | 76 managed_user->SetString("name", name); |
75 | 77 |
76 // TODO(ibraaaa): Update this to use the correct avatar | 78 // TODO(ibraaaa): Update this to use the correct avatar |
77 // when avatar syncing is implemented: http://crbug.com/278083 | 79 // when avatar syncing is implemented: http://crbug.com/278083 |
78 std::string avatar_url = ProfileInfoCache::GetDefaultAvatarIconUrl(0); | 80 std::string avatar_url = ProfileInfoCache::GetDefaultAvatarIconUrl(0); |
79 managed_user->SetString("iconURL", avatar_url); | 81 managed_user->SetString("iconURL", avatar_url); |
80 bool on_current_device = | 82 bool on_current_device = |
81 managed_user_ids.find(it.key()) != managed_user_ids.end(); | 83 managed_user_ids.find(it.key()) != managed_user_ids.end(); |
82 managed_user->SetBoolean("onCurrentDevice", on_current_device); | 84 managed_user->SetBoolean("onCurrentDevice", on_current_device); |
83 | 85 |
84 managed_users.Append(managed_user); | 86 managed_users.Append(managed_user); |
85 } | 87 } |
86 | 88 |
87 web_ui()->CallJavascriptFunction( | 89 web_ui()->CallJavascriptFunction( |
88 "ManagedUserImportOverlay.receiveExistingManagedUsers", | 90 "ManagedUserImportOverlay.receiveExistingManagedUsers", |
89 managed_users); | 91 managed_users); |
90 } | 92 } |
91 | 93 |
92 } // namespace options | 94 } // namespace options |
OLD | NEW |