| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser.h" | 5 #include "chrome/browser/browser.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // might show vertical tabs but not show an option to turn them off. | 229 // might show vertical tabs but not show an option to turn them off. |
| 230 use_vertical_tabs_.SetValue(false); | 230 use_vertical_tabs_.SetValue(false); |
| 231 } | 231 } |
| 232 UpdateTabStripModelInsertionPolicy(); | 232 UpdateTabStripModelInsertionPolicy(); |
| 233 | 233 |
| 234 tab_restore_service_ = profile->GetTabRestoreService(); | 234 tab_restore_service_ = profile->GetTabRestoreService(); |
| 235 if (tab_restore_service_) { | 235 if (tab_restore_service_) { |
| 236 tab_restore_service_->AddObserver(this); | 236 tab_restore_service_->AddObserver(this); |
| 237 TabRestoreServiceChanged(tab_restore_service_); | 237 TabRestoreServiceChanged(tab_restore_service_); |
| 238 } | 238 } |
| 239 |
| 240 if (profile_->GetProfileSyncService()) |
| 241 profile_->GetProfileSyncService()->AddObserver(this); |
| 239 } | 242 } |
| 240 | 243 |
| 241 Browser::~Browser() { | 244 Browser::~Browser() { |
| 242 // The tab strip should not have any significant tabs at this point. | 245 // The tab strip should not have any significant tabs at this point. |
| 243 DCHECK(!tabstrip_model_.HasNonPhantomTabs()); | 246 DCHECK(!tabstrip_model_.HasNonPhantomTabs()); |
| 244 tabstrip_model_.RemoveObserver(this); | 247 tabstrip_model_.RemoveObserver(this); |
| 245 | 248 |
| 249 if (profile_->GetProfileSyncService()) |
| 250 profile_->GetProfileSyncService()->RemoveObserver(this); |
| 251 |
| 246 BrowserList::RemoveBrowser(this); | 252 BrowserList::RemoveBrowser(this); |
| 247 | 253 |
| 248 #if defined(OS_WIN) || defined(OS_LINUX) | 254 #if defined(OS_WIN) || defined(OS_LINUX) |
| 249 if (!BrowserList::HasBrowserWithProfile(profile_)) { | 255 if (!BrowserList::HasBrowserWithProfile(profile_)) { |
| 250 // We're the last browser window with this profile. We need to nuke the | 256 // We're the last browser window with this profile. We need to nuke the |
| 251 // TabRestoreService, which will start the shutdown of the | 257 // TabRestoreService, which will start the shutdown of the |
| 252 // NavigationControllers and allow for proper shutdown. If we don't do this | 258 // NavigationControllers and allow for proper shutdown. If we don't do this |
| 253 // chrome won't shutdown cleanly, and may end up crashing when some | 259 // chrome won't shutdown cleanly, and may end up crashing when some |
| 254 // thread tries to use the IO thread (or another thread) that is no longer | 260 // thread tries to use the IO thread (or another thread) that is no longer |
| 255 // valid. | 261 // valid. |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 command_updater_.UpdateCommandEnabled( | 1058 command_updater_.UpdateCommandEnabled( |
| 1053 IDC_FOCUS_BOOKMARKS, main_not_fullscreen_or_popup); | 1059 IDC_FOCUS_BOOKMARKS, main_not_fullscreen_or_popup); |
| 1054 command_updater_.UpdateCommandEnabled( | 1060 command_updater_.UpdateCommandEnabled( |
| 1055 IDC_FOCUS_CHROMEOS_STATUS, main_not_fullscreen_or_popup); | 1061 IDC_FOCUS_CHROMEOS_STATUS, main_not_fullscreen_or_popup); |
| 1056 | 1062 |
| 1057 // Show various bits of UI | 1063 // Show various bits of UI |
| 1058 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 1064 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 1059 command_updater_.UpdateCommandEnabled(IDC_REPORT_BUG, show_main_ui); | 1065 command_updater_.UpdateCommandEnabled(IDC_REPORT_BUG, show_main_ui); |
| 1060 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, show_main_ui); | 1066 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, show_main_ui); |
| 1061 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, show_main_ui); | 1067 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, show_main_ui); |
| 1062 command_updater_.UpdateCommandEnabled( | 1068 command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, |
| 1063 IDC_SYNC_BOOKMARKS, show_main_ui && ProfileSyncService::IsSyncEnabled()); | 1069 show_main_ui && profile_->IsSyncAccessible()); |
| 1064 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, show_main_ui); | 1070 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, show_main_ui); |
| 1065 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1071 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 1066 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); | 1072 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 1067 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); | 1073 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 1068 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); | 1074 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| 1069 command_updater_.UpdateCommandEnabled(IDC_SHOW_PAGE_MENU, show_main_ui); | 1075 command_updater_.UpdateCommandEnabled(IDC_SHOW_PAGE_MENU, show_main_ui); |
| 1070 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); | 1076 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); |
| 1071 } | 1077 } |
| 1072 | 1078 |
| 1073 bool Browser::OpenAppsPanelAsNewTab() { | 1079 bool Browser::OpenAppsPanelAsNewTab() { |
| (...skipping 1950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3024 else | 3030 else |
| 3025 NOTREACHED(); | 3031 NOTREACHED(); |
| 3026 break; | 3032 break; |
| 3027 } | 3033 } |
| 3028 | 3034 |
| 3029 default: | 3035 default: |
| 3030 NOTREACHED() << "Got a notification we didn't register for."; | 3036 NOTREACHED() << "Got a notification we didn't register for."; |
| 3031 } | 3037 } |
| 3032 } | 3038 } |
| 3033 | 3039 |
| 3040 /////////////////////////////////////////////////////////////////////////////// |
| 3041 // Browser, ProfileSyncServiceObserver implementation: |
| 3042 |
| 3043 void Browser::OnStateChanged() { |
| 3044 DCHECK(profile_->GetProfileSyncService()); |
| 3045 |
| 3046 #if !defined(OS_MACOSX) |
| 3047 const bool show_main_ui = (type() == TYPE_NORMAL) && !window_->IsFullscreen(); |
| 3048 #else |
| 3049 const bool show_main_ui = (type() == TYPE_NORMAL); |
| 3050 #endif |
| 3051 |
| 3052 command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, |
| 3053 show_main_ui && profile_->IsSyncAccessible()); |
| 3054 } |
| 3034 | 3055 |
| 3035 /////////////////////////////////////////////////////////////////////////////// | 3056 /////////////////////////////////////////////////////////////////////////////// |
| 3036 // Browser, Command and state updating (private): | 3057 // Browser, Command and state updating (private): |
| 3037 | 3058 |
| 3038 void Browser::InitCommandState() { | 3059 void Browser::InitCommandState() { |
| 3039 // All browser commands whose state isn't set automagically some other way | 3060 // All browser commands whose state isn't set automagically some other way |
| 3040 // (like Back & Forward with initial page load) must have their state | 3061 // (like Back & Forward with initial page load) must have their state |
| 3041 // initialized here, otherwise they will be forever disabled. | 3062 // initialized here, otherwise they will be forever disabled. |
| 3042 | 3063 |
| 3043 // Navigation commands | 3064 // Navigation commands |
| (...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3974 } | 3995 } |
| 3975 | 3996 |
| 3976 bool Browser::IsPinned(TabContents* source) { | 3997 bool Browser::IsPinned(TabContents* source) { |
| 3977 int index = tabstrip_model_.GetIndexOfTabContents(source); | 3998 int index = tabstrip_model_.GetIndexOfTabContents(source); |
| 3978 if (index == TabStripModel::kNoTab) { | 3999 if (index == TabStripModel::kNoTab) { |
| 3979 NOTREACHED() << "IsPinned called for tab not in our strip"; | 4000 NOTREACHED() << "IsPinned called for tab not in our strip"; |
| 3980 return false; | 4001 return false; |
| 3981 } | 4002 } |
| 3982 return tabstrip_model_.IsTabPinned(index); | 4003 return tabstrip_model_.IsTabPinned(index); |
| 3983 } | 4004 } |
| OLD | NEW |