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

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

Issue 7563023: Multi-Profiles: Remove new profile setup UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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 g_browser_process->profile_manager()->ScheduleProfileForDeletion(
58 web_ui_->GetProfile()->GetPath());
59 }
60
61 void NewProfileHandler::HandleRequestProfileInfo(const ListValue* args) {
62 SendDefaultAvatarImages();
63 SendProfileInfo();
64 }
65
66 void NewProfileHandler::SendDefaultAvatarImages() {
67 ListValue image_url_list;
68 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
69 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
70 image_url_list.Append(Value::CreateStringValue(url));
71 }
72 web_ui_->CallJavascriptFunction("newProfile.setDefaultAvatarImages",
73 image_url_list);
74 }
75
76 void NewProfileHandler::SendProfileInfo() {
77 ProfileInfoCache& cache =
78 g_browser_process->profile_manager()->GetProfileInfoCache();
79 size_t index = cache.GetIndexOfProfileWithPath(
80 web_ui_->GetProfile()->GetPath());
81 if (index != std::string::npos) {
82 StringValue profile_name(cache.GetNameOfProfileAtIndex(index));
83 FundamentalValue profile_icon_index(static_cast<int>(
84 cache.GetAvatarIconIndexOfProfileAtIndex(index)));
85 web_ui_->CallJavascriptFunction("newProfile.setProfileInfo",
86 profile_name,
87 profile_icon_index);
88 }
89 }
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