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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/sessions/session_types.h" 6 7 #include "base/basictypes.h" 8 #include "base/stl_util.h" 9 #include "chrome/browser/sessions/session_command.h" 10 #include "chrome/browser/ui/browser.h" 11 12 using sessions::SerializedNavigationEntry; 13 14 // SessionTab ----------------------------------------------------------------- 15 16 SessionTab::SessionTab() 17 : tab_visual_index(-1), 18 current_navigation_index(-1), 19 pinned(false) { 20 } 21 22 SessionTab::~SessionTab() { 23 } 24 25 void SessionTab::SetFromSyncData(const sync_pb::SessionTab& sync_data, 26 base::Time timestamp) { 27 window_id.set_id(sync_data.window_id()); 28 tab_id.set_id(sync_data.tab_id()); 29 tab_visual_index = sync_data.tab_visual_index(); 30 current_navigation_index = sync_data.current_navigation_index(); 31 pinned = sync_data.pinned(); 32 extension_app_id = sync_data.extension_app_id(); 33 user_agent_override.clear(); 34 this->timestamp = timestamp; 35 navigations.clear(); 36 for (int i = 0; i < sync_data.navigation_size(); ++i) { 37 navigations.push_back( 38 SerializedNavigationEntry::FromSyncData(i, sync_data.navigation(i))); 39 } 40 session_storage_persistent_id.clear(); 41 } 42 43 sync_pb::SessionTab SessionTab::ToSyncData() const { 44 sync_pb::SessionTab sync_data; 45 sync_data.set_tab_id(tab_id.id()); 46 sync_data.set_window_id(window_id.id()); 47 sync_data.set_tab_visual_index(tab_visual_index); 48 sync_data.set_current_navigation_index(current_navigation_index); 49 sync_data.set_pinned(pinned); 50 sync_data.set_extension_app_id(extension_app_id); 51 for (std::vector<SerializedNavigationEntry>::const_iterator 52 it = navigations.begin(); it != navigations.end(); ++it) { 53 *sync_data.add_navigation() = it->ToSyncData(); 54 } 55 return sync_data; 56 } 57 58 // SessionWindow --------------------------------------------------------------- 59 60 SessionWindow::SessionWindow() 61 : selected_tab_index(-1), 62 type(Browser::TYPE_TABBED), 63 is_constrained(true), 64 show_state(ui::SHOW_STATE_DEFAULT) { 65 } 66 67 SessionWindow::~SessionWindow() { 68 STLDeleteElements(&tabs); 69 } 70