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

Side by Side Diff: chrome/browser/profiles/avatar_menu_model.cc

Issue 10967003: Add desktop type context to most existing instances of FindTabbedBrowser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pre-review pass. Created 8 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/profiles/avatar_menu_model.h" 5 #include "chrome/browser/profiles/avatar_menu_model.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 28
29 using content::BrowserThread; 29 using content::BrowserThread;
30 30
31 namespace { 31 namespace {
32 32
33 void OnProfileCreated(bool always_create, 33 void OnProfileCreated(bool always_create,
34 chrome::HostDesktopType desktop_type,
34 Profile* profile, 35 Profile* profile,
35 Profile::CreateStatus status) { 36 Profile::CreateStatus status) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 38
38 if (status == Profile::CREATE_STATUS_INITIALIZED) { 39 if (status == Profile::CREATE_STATUS_INITIALIZED) {
39 ProfileManager::FindOrCreateNewWindowForProfile( 40 ProfileManager::FindOrCreateNewWindowForProfile(
40 profile, 41 profile,
41 chrome::startup::IS_NOT_PROCESS_STARTUP, 42 chrome::startup::IS_NOT_PROCESS_STARTUP,
42 chrome::startup::IS_NOT_FIRST_RUN, 43 chrome::startup::IS_NOT_FIRST_RUN,
44 desktop_type,
43 always_create); 45 always_create);
44 } 46 }
45 } 47 }
46 48
47 } // namespace 49 } // namespace
48 50
49 AvatarMenuModel::AvatarMenuModel(ProfileInfoInterface* profile_cache, 51 AvatarMenuModel::AvatarMenuModel(ProfileInfoInterface* profile_cache,
50 AvatarMenuModelObserver* observer, 52 AvatarMenuModelObserver* observer,
51 Browser* browser) 53 Browser* browser)
52 : profile_info_(profile_cache), 54 : profile_info_(profile_cache),
(...skipping 22 matching lines...) Expand all
75 } 77 }
76 78
77 AvatarMenuModel::Item::~Item() { 79 AvatarMenuModel::Item::~Item() {
78 } 80 }
79 81
80 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) { 82 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) {
81 DCHECK(ProfileManager::IsMultipleProfilesEnabled() || 83 DCHECK(ProfileManager::IsMultipleProfilesEnabled() ||
82 index == GetActiveProfileIndex()); 84 index == GetActiveProfileIndex());
83 const Item& item = GetItemAt(index); 85 const Item& item = GetItemAt(index);
84 FilePath path = profile_info_->GetPathOfProfileAtIndex(item.model_index); 86 FilePath path = profile_info_->GetPathOfProfileAtIndex(item.model_index);
87
88 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE;
89 if (browser_) {
90 desktop_type = browser_->host_desktop_type();
91 }
92
85 g_browser_process->profile_manager()->CreateProfileAsync( 93 g_browser_process->profile_manager()->CreateProfileAsync(
86 path, base::Bind(&OnProfileCreated, always_create), string16(), 94 path,
95 base::Bind(&OnProfileCreated,
96 always_create,
97 desktop_type),
98 string16(),
87 string16()); 99 string16());
88 100
89 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); 101 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON);
90 } 102 }
91 103
92 void AvatarMenuModel::EditProfile(size_t index) { 104 void AvatarMenuModel::EditProfile(size_t index) {
93 Browser* browser = browser_; 105 Browser* browser = browser_;
94 if (!browser) { 106 if (!browser) {
95 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( 107 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath(
96 profile_info_->GetPathOfProfileAtIndex(GetItemAt(index).model_index)); 108 profile_info_->GetPathOfProfileAtIndex(GetItemAt(index).model_index));
97 browser = new Browser(Browser::CreateParams(profile)); 109 browser = new Browser(Browser::CreateParams(profile));
98 } 110 }
99 std::string page = chrome::kManageProfileSubPage; 111 std::string page = chrome::kManageProfileSubPage;
100 page += "#"; 112 page += "#";
101 page += base::IntToString(static_cast<int>(index)); 113 page += base::IntToString(static_cast<int>(index));
102 chrome::ShowSettingsSubPage(browser, page); 114 chrome::ShowSettingsSubPage(browser, page);
103 } 115 }
104 116
105 void AvatarMenuModel::AddNewProfile() { 117 void AvatarMenuModel::AddNewProfile() {
118 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE;
119 if (browser_) {
120 desktop_type = browser_->host_desktop_type();
121 }
122
106 ProfileManager::CreateMultiProfileAsync( 123 ProfileManager::CreateMultiProfileAsync(
107 string16(), string16(), ProfileManager::CreateCallback()); 124 string16(), string16(), ProfileManager::CreateCallback(), desktop_type);
108 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_ICON); 125 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_ICON);
109 } 126 }
110 127
111 size_t AvatarMenuModel::GetNumberOfItems() { 128 size_t AvatarMenuModel::GetNumberOfItems() {
112 return items_.size(); 129 return items_.size();
113 } 130 }
114 131
115 size_t AvatarMenuModel::GetActiveProfileIndex() { 132 size_t AvatarMenuModel::GetActiveProfileIndex() {
116 // During singleton profile deletion, this function can be called with no 133 // During singleton profile deletion, this function can be called with no
117 // profiles in the model - crbug.com/102278 . 134 // profiles in the model - crbug.com/102278 .
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 item->active = browser_->profile()->GetPath() == path; 192 item->active = browser_->profile()->GetPath() == path;
176 } 193 }
177 items_.push_back(item); 194 items_.push_back(item);
178 } 195 }
179 } 196 }
180 197
181 void AvatarMenuModel::ClearMenu() { 198 void AvatarMenuModel::ClearMenu() {
182 STLDeleteContainerPointers(items_.begin(), items_.end()); 199 STLDeleteContainerPointers(items_.begin(), items_.end());
183 items_.clear(); 200 items_.clear();
184 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698