diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 03:55:05 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 03:55:05 +0000 |
commit | 97d2c1ead3b1dfc2f40f0de9123a3d0ed5edff23 (patch) | |
tree | 22f9cdc287f64dbc1f7397264e110d001d963c31 /chrome/browser/sessions | |
parent | 7e5e9d2e535109d83b5c94aa928c397ce3b9bcc0 (diff) | |
download | chromium_src-97d2c1ead3b1dfc2f40f0de9123a3d0ed5edff23.zip chromium_src-97d2c1ead3b1dfc2f40f0de9123a3d0ed5edff23.tar.gz chromium_src-97d2c1ead3b1dfc2f40f0de9123a3d0ed5edff23.tar.bz2 |
Make SessionService use its own enum for storing window type in the session database. This allows us to modify Browser::Type without invalidating databases from older versions.
http://crbug.com/26500
TEST=see bug
Review URL: http://codereview.chromium.org/361016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions')
-rw-r--r-- | chrome/browser/sessions/session_service.cc | 43 | ||||
-rw-r--r-- | chrome/browser/sessions/session_service.h | 17 |
2 files changed, 55 insertions, 5 deletions
diff --git a/chrome/browser/sessions/session_service.cc b/chrome/browser/sessions/session_service.cc index 4682ca3..6b9bd65 100644 --- a/chrome/browser/sessions/session_service.cc +++ b/chrome/browser/sessions/session_service.cc @@ -278,7 +278,8 @@ void SessionService::SetWindowType(const SessionID& window_id, has_open_trackable_browsers_ = true; move_on_new_browser_ = true; - ScheduleCommand(CreateSetWindowTypeCommand(window_id, type)); + ScheduleCommand( + CreateSetWindowTypeCommand(window_id, WindowTypeForBrowserType(type))); } void SessionService::TabNavigationPathPrunedFromBack(const SessionID& window_id, @@ -588,7 +589,7 @@ SessionCommand* SessionService::CreateSetSelectedNavigationIndexCommand( SessionCommand* SessionService::CreateSetWindowTypeCommand( const SessionID& window_id, - Browser::Type type) { + WindowType type) { WindowTypePayload payload = { 0 }; payload.id = window_id.id(); payload.index = static_cast<int32>(type); @@ -898,7 +899,8 @@ bool SessionService::CreateTabsAndWindows( return true; GetWindow(payload.id, windows)->is_constrained = false; GetWindow(payload.id, windows)->type = - static_cast<Browser::Type>(payload.index); + BrowserTypeForWindowType( + static_cast<WindowType>(payload.index)); break; } @@ -978,7 +980,7 @@ void SessionService::BuildCommandsForBrowser( browser->window()->IsMaximized())); commands->push_back(CreateSetWindowTypeCommand( - browser->session_id(), browser->type())); + browser->session_id(), WindowTypeForBrowserType(browser->type()))); bool added_to_windows_to_track = false; for (int i = 0; i < browser->tab_count(); ++i) { @@ -1163,3 +1165,36 @@ bool SessionService::HasOpenTrackableBrowsers(const SessionID& window_id) { bool SessionService::ShouldTrackChangesToWindow(const SessionID& window_id) { return windows_tracking_.find(window_id.id()) != windows_tracking_.end(); } + + +SessionService::WindowType SessionService::WindowTypeForBrowserType( + Browser::Type type) { + // We don't support masks here, only discrete types. + switch (type) { + case Browser::TYPE_POPUP: + return TYPE_POPUP; + case Browser::TYPE_APP: + return TYPE_APP; + case Browser::TYPE_APP_POPUP: + return TYPE_APP_POPUP; + case Browser::TYPE_NORMAL: + default: + return TYPE_NORMAL; + } +} + +Browser::Type SessionService::BrowserTypeForWindowType( + SessionService::WindowType type) { + switch (type) { + case TYPE_POPUP: + return Browser::TYPE_POPUP; + case TYPE_APP: + return Browser::TYPE_APP; + case TYPE_APP_POPUP: + return Browser::TYPE_APP_POPUP; + case TYPE_NORMAL: + default: + return Browser::TYPE_NORMAL; + } +} + diff --git a/chrome/browser/sessions/session_service.h b/chrome/browser/sessions/session_service.h index 7fddaaa..d1b5f05 100644 --- a/chrome/browser/sessions/session_service.h +++ b/chrome/browser/sessions/session_service.h @@ -154,6 +154,16 @@ class SessionService : public BaseSessionService, typedef std::map<SessionID::id_type,SessionTab*> IdToSessionTab; typedef std::map<SessionID::id_type,SessionWindow*> IdToSessionWindow; + // These types mirror Browser::Type, but are re-defined here because these + // specific enumeration _values_ are written into the session database and + // are needed to maintain forward compatibility. + enum WindowType { + TYPE_NORMAL = 0, + TYPE_POPUP = 1, + TYPE_APP = 2, + TYPE_APP_POPUP = TYPE_APP + TYPE_POPUP + }; + void Init(); virtual void Observe(NotificationType type, @@ -184,7 +194,7 @@ class SessionService : public BaseSessionService, int index); SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id, - Browser::Type type); + WindowType type); SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id, bool is_pinned); @@ -320,6 +330,11 @@ class SessionService : public BaseSessionService, (type == Browser::TYPE_POPUP && browser_defaults::kRestorePopups); } + // Convert back/forward between the Browser and SessionService DB window + // types. + static WindowType WindowTypeForBrowserType(Browser::Type type); + static Browser::Type BrowserTypeForWindowType(WindowType type); + NotificationRegistrar registrar_; // Maps from session tab id to the range of navigation entries that has |