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" | 13 #include "chrome/browser/managed_mode/managed_user_sync_service.h" |
14 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" | 14 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/profiles/profile_info_cache.h" | 16 #include "chrome/browser/profiles/profile_info_cache.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 | 21 |
| 22 namespace { |
| 23 |
| 24 scoped_ptr<base::ListValue> GetAvatarIcons() { |
| 25 scoped_ptr<base::ListValue> avatar_icons(new base::ListValue); |
| 26 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); ++i) { |
| 27 std::string avatar_url = ProfileInfoCache::GetDefaultAvatarIconUrl(i); |
| 28 avatar_icons->Append(new base::StringValue(avatar_url)); |
| 29 } |
| 30 |
| 31 return avatar_icons.Pass(); |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
22 namespace options { | 36 namespace options { |
23 | 37 |
24 ManagedUserImportHandler::ManagedUserImportHandler() {} | 38 ManagedUserImportHandler::ManagedUserImportHandler() {} |
25 | 39 |
26 ManagedUserImportHandler::~ManagedUserImportHandler() {} | 40 ManagedUserImportHandler::~ManagedUserImportHandler() {} |
27 | 41 |
28 void ManagedUserImportHandler::GetLocalizedValues( | 42 void ManagedUserImportHandler::GetLocalizedValues( |
29 base::DictionaryValue* localized_strings) { | 43 base::DictionaryValue* localized_strings) { |
30 DCHECK(localized_strings); | 44 DCHECK(localized_strings); |
31 | 45 |
32 static OptionsStringResource resources[] = { | 46 static OptionsStringResource resources[] = { |
| 47 { "managedUserImportTitle", IDS_IMPORT_EXISTING_MANAGED_USER_TITLE }, |
33 { "managedUserImportText", IDS_IMPORT_EXISTING_MANAGED_USER_TEXT }, | 48 { "managedUserImportText", IDS_IMPORT_EXISTING_MANAGED_USER_TEXT }, |
34 { "createNewUserLink", IDS_CREATE_NEW_USER_LINK }, | 49 { "createNewUserLink", IDS_CREATE_NEW_USER_LINK }, |
35 { "managedUserImportOk", IDS_IMPORT_EXISTING_MANAGED_USER_OK }, | 50 { "managedUserImportOk", IDS_IMPORT_EXISTING_MANAGED_USER_OK }, |
36 { "managedUserAlreadyOnThisDevice", | 51 { "managedUserAlreadyOnThisDevice", |
37 IDS_MANAGED_USER_ALREADY_ON_THIS_DEVICE }, | 52 IDS_MANAGED_USER_ALREADY_ON_THIS_DEVICE }, |
38 { "noExistingManagedUsers", IDS_MANAGED_USER_NO_EXISTING_ERROR }, | 53 { "noExistingManagedUsers", IDS_MANAGED_USER_NO_EXISTING_ERROR }, |
| 54 { "managedUserSelectAvatarTitle", IDS_MANAGED_USER_SELECT_AVATAR_TITLE }, |
| 55 { "managedUserSelectAvatarText", IDS_MANAGED_USER_SELECT_AVATAR_TEXT }, |
| 56 { "managedUserSelectAvatarOk", IDS_MANAGED_USER_SELECT_AVATAR_OK }, |
39 }; | 57 }; |
40 | 58 |
41 RegisterStrings(localized_strings, resources, arraysize(resources)); | 59 RegisterStrings(localized_strings, resources, arraysize(resources)); |
42 RegisterTitle(localized_strings, "managedUserImport", | 60 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); |
43 IDS_IMPORT_EXISTING_MANAGED_USER_TITLE); | |
44 } | 61 } |
45 | 62 |
46 void ManagedUserImportHandler::RegisterMessages() { | 63 void ManagedUserImportHandler::RegisterMessages() { |
47 web_ui()->RegisterMessageCallback("requestExistingManagedUsers", | 64 web_ui()->RegisterMessageCallback("requestExistingManagedUsers", |
48 base::Bind(&ManagedUserImportHandler::RequestExistingManagedUsers, | 65 base::Bind(&ManagedUserImportHandler::RequestExistingManagedUsers, |
49 base::Unretained(this))); | 66 base::Unretained(this))); |
50 } | 67 } |
51 | 68 |
52 void ManagedUserImportHandler::RequestExistingManagedUsers( | 69 void ManagedUserImportHandler::RequestExistingManagedUsers( |
53 const ListValue* args) { | 70 const ListValue* args) { |
(...skipping 19 matching lines...) Expand all Loading... |
73 std::string avatar_str; | 90 std::string avatar_str; |
74 value->GetString(ManagedUserSyncService::kChromeAvatar, &avatar_str); | 91 value->GetString(ManagedUserSyncService::kChromeAvatar, &avatar_str); |
75 | 92 |
76 DictionaryValue* managed_user = new DictionaryValue; | 93 DictionaryValue* managed_user = new DictionaryValue; |
77 managed_user->SetString("id", it.key()); | 94 managed_user->SetString("id", it.key()); |
78 managed_user->SetString("name", name); | 95 managed_user->SetString("name", name); |
79 | 96 |
80 int avatar_index = ManagedUserSyncService::kNoAvatar; | 97 int avatar_index = ManagedUserSyncService::kNoAvatar; |
81 success = ManagedUserSyncService::GetAvatarIndex(avatar_str, &avatar_index); | 98 success = ManagedUserSyncService::GetAvatarIndex(avatar_str, &avatar_index); |
82 DCHECK(success); | 99 DCHECK(success); |
| 100 managed_user->SetBoolean("needAvatar", avatar_index < 0); |
83 | 101 |
84 // TODO(ibraaaa): When we have an image indicating that this user | 102 // TODO(ibraaaa): When we have an image indicating that this user |
85 // has no synced avatar then change this to use it. | 103 // has no synced avatar then change this to use it. |
86 avatar_index = | 104 avatar_index = |
87 avatar_index == ManagedUserSyncService::kNoAvatar ? 0 : avatar_index; | 105 avatar_index == ManagedUserSyncService::kNoAvatar ? 0 : avatar_index; |
88 std::string avatar_url = | 106 std::string avatar_url = |
89 ProfileInfoCache::GetDefaultAvatarIconUrl(avatar_index); | 107 ProfileInfoCache::GetDefaultAvatarIconUrl(avatar_index); |
90 managed_user->SetString("iconURL", avatar_url); | 108 managed_user->SetString("iconURL", avatar_url); |
91 bool on_current_device = | 109 bool on_current_device = |
92 managed_user_ids.find(it.key()) != managed_user_ids.end(); | 110 managed_user_ids.find(it.key()) != managed_user_ids.end(); |
93 managed_user->SetBoolean("onCurrentDevice", on_current_device); | 111 managed_user->SetBoolean("onCurrentDevice", on_current_device); |
94 | 112 |
95 managed_users.Append(managed_user); | 113 managed_users.Append(managed_user); |
96 } | 114 } |
97 | 115 |
98 web_ui()->CallJavascriptFunction( | 116 web_ui()->CallJavascriptFunction( |
99 "ManagedUserImportOverlay.receiveExistingManagedUsers", | 117 "ManagedUserImportOverlay.receiveExistingManagedUsers", |
100 managed_users); | 118 managed_users); |
101 } | 119 } |
102 | 120 |
103 } // namespace options | 121 } // namespace options |
OLD | NEW |