OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/toolbar/wrench_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/i18n/number_formatting.h" | 11 #include "base/i18n/number_formatting.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
19 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/profiles/profile_info_cache.h" |
21 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
22 #include "chrome/browser/sync/profile_sync_service.h" | 23 #include "chrome/browser/sync/profile_sync_service.h" |
23 #include "chrome/browser/sync/sync_ui_util.h" | 24 #include "chrome/browser/sync/sync_ui_util.h" |
24 #include "chrome/browser/tabs/tab_strip_model.h" | 25 #include "chrome/browser/tabs/tab_strip_model.h" |
25 #include "chrome/browser/task_manager/task_manager.h" | 26 #include "chrome/browser/task_manager/task_manager.h" |
26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
28 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 29 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
29 #include "chrome/browser/upgrade_detector.h" | 30 #include "chrome/browser/upgrade_detector.h" |
30 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 221 |
221 ProfilesSubMenuModel::ProfilesSubMenuModel( | 222 ProfilesSubMenuModel::ProfilesSubMenuModel( |
222 ui::SimpleMenuModel::Delegate* delegate, Browser* browser) | 223 ui::SimpleMenuModel::Delegate* delegate, Browser* browser) |
223 : SimpleMenuModel(this), | 224 : SimpleMenuModel(this), |
224 browser_(browser), | 225 browser_(browser), |
225 delegate_(delegate) { | 226 delegate_(delegate) { |
226 Build(); | 227 Build(); |
227 } | 228 } |
228 | 229 |
229 void ProfilesSubMenuModel::Build() { | 230 void ProfilesSubMenuModel::Build() { |
230 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 231 ProfileInfoCache& cache = |
231 size_t count = profile_manager->GetNumberOfProfiles(); | 232 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 233 size_t count = cache.GetNumberOfProfiles(); |
232 for (size_t i = 0; i < count; ++i) { | 234 for (size_t i = 0; i < count; ++i) { |
233 AddCheckItem(COMMAND_SWITCH_TO_PROFILE + i, | 235 AddCheckItem(COMMAND_SWITCH_TO_PROFILE + i, |
234 profile_manager->GetNameOfProfileAtIndex(i)); | 236 cache.GetNameOfProfileAtIndex(i)); |
235 } | 237 } |
236 | 238 |
237 AddSeparator(); | 239 AddSeparator(); |
238 | 240 |
239 const string16 short_product_name = | 241 const string16 short_product_name = |
240 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); | 242 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
241 AddItem(IDC_CREATE_NEW_PROFILE, l10n_util::GetStringFUTF16( | 243 AddItem(IDC_CREATE_NEW_PROFILE, l10n_util::GetStringFUTF16( |
242 IDS_PROFILES_CREATE_NEW_PROFILE_OPTION, short_product_name)); | 244 IDS_PROFILES_CREATE_NEW_PROFILE_OPTION, short_product_name)); |
243 } | 245 } |
244 | 246 |
245 class ProfileSwitchObserver : public ProfileManagerObserver { | 247 class ProfileSwitchObserver : public ProfileManagerObserver { |
246 virtual void OnProfileCreated(Profile* profile) OVERRIDE { | 248 virtual void OnProfileCreated(Profile* profile) OVERRIDE { |
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
248 | 250 |
249 Browser* browser = BrowserList::FindTabbedBrowser(profile, false); | 251 Browser* browser = BrowserList::FindTabbedBrowser(profile, false); |
250 if (browser) | 252 if (browser) |
251 browser->window()->Activate(); | 253 browser->window()->Activate(); |
252 else | 254 else |
253 Browser::NewWindowWithProfile(profile); | 255 Browser::NewWindowWithProfile(profile); |
254 } | 256 } |
255 | 257 |
256 virtual bool DeleteAfterCreation() OVERRIDE { return true; } | 258 virtual bool DeleteAfterCreation() OVERRIDE { return true; } |
257 }; | 259 }; |
258 | 260 |
259 void ProfilesSubMenuModel::ExecuteCommand(int command_id) { | 261 void ProfilesSubMenuModel::ExecuteCommand(int command_id) { |
260 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 262 ProfileInfoCache& cache = |
| 263 g_browser_process->profile_manager()->GetProfileInfoCache(); |
261 size_t index = command_id; | 264 size_t index = command_id; |
262 if (index < profile_manager->GetNumberOfProfiles()) { | 265 if (index < cache.GetNumberOfProfiles()) { |
263 FilePath userDataFolder; | 266 FilePath profile_path = cache.GetPathOfProfileAtIndex(index); |
264 PathService::Get(chrome::DIR_USER_DATA, &userDataFolder); | |
265 FilePath profile_path = | |
266 profile_manager->GetFilePathOfProfileAtIndex(index, userDataFolder); | |
267 | |
268 ProfileSwitchObserver* observer = new ProfileSwitchObserver; | 267 ProfileSwitchObserver* observer = new ProfileSwitchObserver; |
269 // The observer is deleted by the manager when profile creation is finished. | 268 // The observer is deleted by the manager when profile creation is finished. |
270 profile_manager->CreateProfileAsync(profile_path, observer); | 269 g_browser_process->profile_manager()->CreateProfileAsync( |
| 270 profile_path, observer); |
271 } else { | 271 } else { |
272 delegate_->ExecuteCommand(command_id); | 272 delegate_->ExecuteCommand(command_id); |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 bool ProfilesSubMenuModel::IsCommandIdChecked(int command_id) const { | 276 bool ProfilesSubMenuModel::IsCommandIdChecked(int command_id) const { |
277 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 277 ProfileInfoCache& cache = |
| 278 g_browser_process->profile_manager()->GetProfileInfoCache(); |
278 size_t index = command_id; | 279 size_t index = command_id; |
279 if (index < profile_manager->GetNumberOfProfiles()) { | 280 if (index < cache.GetNumberOfProfiles()) { |
280 FilePath userDataFolder; | 281 FilePath userDataFolder; |
281 PathService::Get(chrome::DIR_USER_DATA, &userDataFolder); | 282 PathService::Get(chrome::DIR_USER_DATA, &userDataFolder); |
282 FilePath profile_path = | 283 FilePath profile_path = cache.GetPathOfProfileAtIndex(index); |
283 profile_manager->GetFilePathOfProfileAtIndex(index, userDataFolder); | |
284 return browser_->GetProfile()->GetPath() == profile_path; | 284 return browser_->GetProfile()->GetPath() == profile_path; |
285 } | 285 } |
286 return delegate_->IsCommandIdChecked(command_id); | 286 return delegate_->IsCommandIdChecked(command_id); |
287 } | 287 } |
288 | 288 |
289 bool ProfilesSubMenuModel::IsCommandIdEnabled(int command_id) const { | 289 bool ProfilesSubMenuModel::IsCommandIdEnabled(int command_id) const { |
290 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 290 ProfileInfoCache& cache = |
| 291 g_browser_process->profile_manager()->GetProfileInfoCache(); |
291 size_t index = command_id; | 292 size_t index = command_id; |
292 if (index < profile_manager->GetNumberOfProfiles()) | 293 if (index < cache.GetNumberOfProfiles()) |
293 return true; | 294 return true; |
294 return delegate_->IsCommandIdEnabled(command_id); | 295 return delegate_->IsCommandIdEnabled(command_id); |
295 } | 296 } |
296 | 297 |
297 bool ProfilesSubMenuModel::GetAcceleratorForCommandId( | 298 bool ProfilesSubMenuModel::GetAcceleratorForCommandId( |
298 int command_id, | 299 int command_id, |
299 ui::Accelerator* accelerator) { | 300 ui::Accelerator* accelerator) { |
300 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 301 ProfileInfoCache& cache = |
| 302 g_browser_process->profile_manager()->GetProfileInfoCache(); |
301 size_t index = command_id; | 303 size_t index = command_id; |
302 if (index < profile_manager->GetNumberOfProfiles()) | 304 if (index < cache.GetNumberOfProfiles()) |
303 return false; | 305 return false; |
304 return delegate_->GetAcceleratorForCommandId(command_id, accelerator); | 306 return delegate_->GetAcceleratorForCommandId(command_id, accelerator); |
305 } | 307 } |
306 | 308 |
307 //////////////////////////////////////////////////////////////////////////////// | 309 //////////////////////////////////////////////////////////////////////////////// |
308 // WrenchMenuModel | 310 // WrenchMenuModel |
309 | 311 |
310 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, | 312 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, |
311 Browser* browser) | 313 Browser* browser) |
312 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 314 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 bookmark_sub_menu_model_.get()); | 566 bookmark_sub_menu_model_.get()); |
565 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); | 567 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); |
566 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); | 568 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); |
567 AddSeparator(); | 569 AddSeparator(); |
568 | 570 |
569 #if !defined(OS_CHROMEOS) | 571 #if !defined(OS_CHROMEOS) |
570 const string16 short_product_name = | 572 const string16 short_product_name = |
571 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); | 573 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
572 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 574 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
573 if (browser_command_line.HasSwitch(switches::kMultiProfiles)) { | 575 if (browser_command_line.HasSwitch(switches::kMultiProfiles)) { |
574 if (g_browser_process->profile_manager()->GetNumberOfProfiles() > 1) { | 576 ProfileInfoCache& cache = |
| 577 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 578 if (cache.GetNumberOfProfiles() > 1) { |
575 profiles_sub_menu_model_.reset(new ProfilesSubMenuModel(this, browser_)); | 579 profiles_sub_menu_model_.reset(new ProfilesSubMenuModel(this, browser_)); |
576 AddSubMenu(IDC_PROFILE_MENU, l10n_util::GetStringFUTF16( | 580 AddSubMenu(IDC_PROFILE_MENU, l10n_util::GetStringFUTF16( |
577 IDS_PROFILES_MENU, short_product_name), | 581 IDS_PROFILES_MENU, short_product_name), |
578 profiles_sub_menu_model_.get()); | 582 profiles_sub_menu_model_.get()); |
579 } else { | 583 } else { |
580 profiles_sub_menu_model_.reset(); | 584 profiles_sub_menu_model_.reset(); |
581 AddItem(IDC_CREATE_NEW_PROFILE, l10n_util::GetStringFUTF16( | 585 AddItem(IDC_CREATE_NEW_PROFILE, l10n_util::GetStringFUTF16( |
582 IDS_PROFILES_CREATE_NEW_PROFILE_OPTION, short_product_name)); | 586 IDS_PROFILES_CREATE_NEW_PROFILE_OPTION, short_product_name)); |
583 } | 587 } |
584 | 588 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 &enable_increment, &enable_decrement); | 675 &enable_increment, &enable_decrement); |
672 } | 676 } |
673 zoom_label_ = l10n_util::GetStringFUTF16( | 677 zoom_label_ = l10n_util::GetStringFUTF16( |
674 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 678 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
675 } | 679 } |
676 | 680 |
677 string16 WrenchMenuModel::GetSyncMenuLabel() const { | 681 string16 WrenchMenuModel::GetSyncMenuLabel() const { |
678 return sync_ui_util::GetSyncMenuLabel( | 682 return sync_ui_util::GetSyncMenuLabel( |
679 browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); | 683 browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); |
680 } | 684 } |
OLD | NEW |