Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1126)

Side by Side Diff: chrome/browser/ui/webui/new_profile_handler.cc

Issue 7256002: Multi-Profiles: New Profile Setup UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/new_profile_handler.h ('k') | chrome/browser/ui/webui/new_profile_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/new_profile_handler.h"
6
7 #include "base/string_number_conversions.h"
8 #include "base/values.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_info_cache.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/common/url_constants.h"
14 #include "content/browser/tab_contents/tab_contents.h"
15
16 NewProfileHandler::NewProfileHandler() {
17 }
18
19 void NewProfileHandler::RegisterMessages() {
20 web_ui_->RegisterMessageCallback("create",
21 NewCallback(this, &NewProfileHandler::HandleCreate));
22 web_ui_->RegisterMessageCallback("cancel",
23 NewCallback(this, &NewProfileHandler::HandleCancel));
24 web_ui_->RegisterMessageCallback("requestProfileInfo",
25 NewCallback(this, &NewProfileHandler::HandleRequestProfileInfo));
26 }
27
28 void NewProfileHandler::HandleCreate(const ListValue* args) {
29 string16 profile_name;
30 bool ret = args->GetString(0, &profile_name);
31 if (!ret || profile_name.empty())
32 return;
33
34 std::string string_index;
35 ret = args->GetString(1, &string_index);
36 if (!ret || string_index.empty())
37 return;
38 int profile_avatar_index;
39 if (!base::StringToInt(string_index, &profile_avatar_index))
40 return;
41
42 ProfileInfoCache& cache =
43 g_browser_process->profile_manager()->GetProfileInfoCache();
44 size_t index = cache.GetIndexOfProfileWithPath(
45 web_ui_->GetProfile()->GetPath());
46 if (index != std::string::npos) {
47 cache.SetNameOfProfileAtIndex(index, profile_name);
48 cache.SetAvatarIconOfProfileAtIndex(index, profile_avatar_index);
49 }
50
51 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUINewTabURL),
52 GURL(), CURRENT_TAB,
53 PageTransition::LINK);
54 }
55
56 void NewProfileHandler::HandleCancel(const ListValue* args) {
57 // TODO(sail): delete this profile.
58 }
59
60 void NewProfileHandler::HandleRequestProfileInfo(const ListValue* args) {
61 SendDefaultAvatarImages();
62 SendProfileInfo();
63 }
64
65 void NewProfileHandler::SendDefaultAvatarImages() {
66 ListValue image_url_list;
67 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
68 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
69 image_url_list.Append(Value::CreateStringValue(url));
70 }
71 web_ui_->CallJavascriptFunction("newProfile.setDefaultAvatarImages",
72 image_url_list);
73 }
74
75 void NewProfileHandler::SendProfileInfo() {
76 ProfileInfoCache& cache =
77 g_browser_process->profile_manager()->GetProfileInfoCache();
78 size_t index = cache.GetIndexOfProfileWithPath(
79 web_ui_->GetProfile()->GetPath());
80 if (index != std::string::npos) {
81 StringValue profile_name(cache.GetNameOfProfileAtIndex(index));
82 FundamentalValue profile_icon_index(static_cast<int>(
83 cache.GetAvatarIconIndexOfProfileAtIndex(index)));
84 web_ui_->CallJavascriptFunction("newProfile.setProfileInfo",
85 profile_name,
86 profile_icon_index);
87 }
88 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/new_profile_handler.h ('k') | chrome/browser/ui/webui/new_profile_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698