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

Side by Side Diff: chrome/browser/ui/views/user_manager_view.cc

Issue 199533004: [Mac, Win] Show a user manager tutorial once per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: much refactor. such change. Created 6 years, 9 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
OLDNEW
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/views/user_manager_view.h" 5 #include "chrome/browser/ui/views/user_manager_view.h"
6 6
7 #include "base/strings/string_number_conversions.h"
8 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/lifetime/application_lifetime.h" 8 #include "chrome/browser/lifetime/application_lifetime.h"
10 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/profiles/profile_metrics.h" 10 #include "chrome/browser/profiles/profile_metrics.h"
11 #include "chrome/browser/profiles/profile_window.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_dialogs.h" 13 #include "chrome/browser/ui/browser_dialogs.h"
14 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/views/auto_keep_alive.h" 15 #include "chrome/browser/ui/views/auto_keep_alive.h"
16 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_view.h" 17 #include "content/public/browser/web_contents_view.h"
19 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/views/controls/webview/webview.h" 20 #include "ui/views/controls/webview/webview.h"
22 #include "ui/views/layout/fill_layout.h" 21 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/view.h" 22 #include "ui/views/view.h"
24 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
25 24
26 #if defined(USE_ASH) 25 #if defined(USE_ASH)
(...skipping 12 matching lines...) Expand all
39 // Default window size. 38 // Default window size.
40 const int kWindowWidth = 900; 39 const int kWindowWidth = 900;
41 const int kWindowHeight = 700; 40 const int kWindowHeight = 700;
42 41
43 } 42 }
44 43
45 namespace chrome { 44 namespace chrome {
46 45
47 // Declared in browser_dialogs.h so others don't have to depend on this header. 46 // Declared in browser_dialogs.h so others don't have to depend on this header.
48 void ShowUserManager(const base::FilePath& profile_path_to_focus) { 47 void ShowUserManager(const base::FilePath& profile_path_to_focus) {
49 UserManagerView::Show(profile_path_to_focus); 48 UserManagerView::Show(
49 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL);
50 } 50 }
51 51
52 void HideUserManager() { 52 void HideUserManager() {
53 UserManagerView::Hide(); 53 UserManagerView::Hide();
54 } 54 }
55 55
56 } // namespace chrome 56 } // namespace chrome
57 57
58 // static 58 // static
59 UserManagerView* UserManagerView::instance_ = NULL; 59 UserManagerView* UserManagerView::instance_ = NULL;
60 60
61 UserManagerView::UserManagerView(Profile* profile) 61 UserManagerView::UserManagerView(Profile* profile)
62 : web_view_(new views::WebView(profile)) { 62 : web_view_(new views::WebView(profile)) {
63 SetLayoutManager(new views::FillLayout); 63 SetLayoutManager(new views::FillLayout);
64 AddChildView(web_view_); 64 AddChildView(web_view_);
65 } 65 }
66 66
67 UserManagerView::~UserManagerView() { 67 UserManagerView::~UserManagerView() {
68 } 68 }
69 69
70 // static 70 // static
71 void UserManagerView::Show(const base::FilePath& profile_path_to_focus) { 71 void UserManagerView::Show(const base::FilePath& profile_path_to_focus,
72 profiles::UserManagerTutorialMode tutorial_mode) {
72 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_USER_MANAGER); 73 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_USER_MANAGER);
73 if (instance_) { 74 if (instance_) {
74 // If there's a user manager window open already, just activate it. 75 // If there's a user manager window open already, just activate it.
75 instance_->GetWidget()->Activate(); 76 instance_->GetWidget()->Activate();
76 return; 77 return;
77 } 78 }
78 79
79 // Create the guest profile, if necessary, and open the user manager 80 // Create the guest profile, if necessary, and open the user manager
80 // from the guest profile. 81 // from the guest profile.
81 ProfileManager* profile_manager = g_browser_process->profile_manager(); 82 profiles::CreateGuestProfileForUserManager(
82 profile_manager->CreateProfileAsync( 83 profile_path_to_focus,
83 ProfileManager::GetGuestProfilePath(), 84 tutorial_mode,
84 base::Bind(&UserManagerView::OnGuestProfileCreated, 85 base::Bind(&UserManagerView::OnGuestProfileCreated));
85 profile_path_to_focus),
86 base::string16(),
87 base::string16(),
88 std::string());
89 } 86 }
90 87
91 // static 88 // static
92 void UserManagerView::Hide() { 89 void UserManagerView::Hide() {
93 if (instance_) 90 if (instance_)
94 instance_->GetWidget()->Close(); 91 instance_->GetWidget()->Close();
95 } 92 }
96 93
97 // static 94 // static
98 bool UserManagerView::IsShowing() { 95 bool UserManagerView::IsShowing() {
99 return instance_ ? instance_->GetWidget()->IsActive() : false; 96 return instance_ ? instance_->GetWidget()->IsActive() : false;
100 } 97 }
101 98
102 void UserManagerView::OnGuestProfileCreated( 99 // static
103 const base::FilePath& profile_path_to_focus, 100 void UserManagerView::OnGuestProfileCreated(Profile* guest_profile,
104 Profile* guest_profile, 101 const std::string& url) {
105 Profile::CreateStatus status) {
106 if (status != Profile::CREATE_STATUS_INITIALIZED)
107 return;
108
109 instance_ = new UserManagerView(guest_profile); 102 instance_ = new UserManagerView(guest_profile);
110 DialogDelegate::CreateDialogWidget(instance_, NULL, NULL); 103 DialogDelegate::CreateDialogWidget(instance_, NULL, NULL);
111 104
112 gfx::NativeWindow window = instance_->GetWidget()->GetNativeWindow(); 105 gfx::NativeWindow window = instance_->GetWidget()->GetNativeWindow();
113 instance_->keep_alive_.reset(new AutoKeepAlive(window)); 106 instance_->keep_alive_.reset(new AutoKeepAlive(window));
114 107
115 #if defined(OS_WIN) 108 #if defined(OS_WIN)
116 // Set the app id for the task manager to the app id of its parent 109 // Set the app id for the task manager to the app id of its parent
117 ui::win::SetAppIdForWindow( 110 ui::win::SetAppIdForWindow(
118 ShellIntegration::GetChromiumModelIdForProfile( 111 ShellIntegration::GetChromiumModelIdForProfile(
119 guest_profile->GetPath()), 112 guest_profile->GetPath()),
120 views::HWNDForWidget(instance_->GetWidget())); 113 views::HWNDForWidget(instance_->GetWidget()));
121 #endif 114 #endif
122 instance_->GetWidget()->Show(); 115 instance_->GetWidget()->Show();
123 116
124 // Tell the webui which user pod should be focused.
125 std::string page = chrome::kChromeUIUserManagerURL;
126
127 if (!profile_path_to_focus.empty()) {
128 ProfileInfoCache& cache =
129 g_browser_process->profile_manager()->GetProfileInfoCache();
130 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus);
131 if (index != std::string::npos) {
132 page += "#";
133 page += base::IntToString(index);
134 }
135 }
136
137 instance_->web_view_->LoadInitialURL(GURL(page)); 117 instance_->web_view_->LoadInitialURL(GURL(page));
138 instance_->web_view_->RequestFocus(); 118 instance_->web_view_->RequestFocus();
139 } 119 }
140 120
141 gfx::Size UserManagerView::GetPreferredSize() { 121 gfx::Size UserManagerView::GetPreferredSize() {
142 return gfx::Size(kWindowWidth, kWindowHeight); 122 return gfx::Size(kWindowWidth, kWindowHeight);
143 } 123 }
144 124
145 bool UserManagerView::CanResize() const { 125 bool UserManagerView::CanResize() const {
146 return true; 126 return true;
(...skipping 15 matching lines...) Expand all
162 // Now that the window is closed, we can allow a new one to be opened. 142 // Now that the window is closed, we can allow a new one to be opened.
163 // (WindowClosing comes in asynchronously from the call to Close() and we 143 // (WindowClosing comes in asynchronously from the call to Close() and we
164 // may have already opened a new instance). 144 // may have already opened a new instance).
165 if (instance_ == this) 145 if (instance_ == this)
166 instance_ = NULL; 146 instance_ = NULL;
167 } 147 }
168 148
169 bool UserManagerView::UseNewStyleForThisDialog() const { 149 bool UserManagerView::UseNewStyleForThisDialog() const {
170 return false; 150 return false;
171 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698