[Cleanup] Add CreateWebContentsWithID helper to TabStripModelTest
[chromium-blink-merge.git] / components / sessions / session_types.cc
blobfcbe44d44e180f4a1e46b0392c2ecd452bb6aa69
1 // Copyright 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.
5 #include "components/sessions/session_types.h"
7 #include "base/basictypes.h"
8 #include "base/stl_util.h"
9 #include "components/sessions/session_command.h"
11 namespace sessions {
13 //using class SerializedNavigationEntry;
15 // SessionTab -----------------------------------------------------------------
17 SessionTab::SessionTab()
18 : tab_visual_index(-1),
19 current_navigation_index(-1),
20 pinned(false) {
23 SessionTab::~SessionTab() {
26 void SessionTab::SetFromSyncData(const sync_pb::SessionTab& sync_data,
27 base::Time timestamp) {
28 window_id.set_id(sync_data.window_id());
29 tab_id.set_id(sync_data.tab_id());
30 tab_visual_index = sync_data.tab_visual_index();
31 current_navigation_index = sync_data.current_navigation_index();
32 pinned = sync_data.pinned();
33 extension_app_id = sync_data.extension_app_id();
34 user_agent_override.clear();
35 this->timestamp = timestamp;
36 navigations.clear();
37 for (int i = 0; i < sync_data.navigation_size(); ++i) {
38 navigations.push_back(
39 SerializedNavigationEntry::FromSyncData(i, sync_data.navigation(i)));
41 session_storage_persistent_id.clear();
44 sync_pb::SessionTab SessionTab::ToSyncData() const {
45 sync_pb::SessionTab sync_data;
46 sync_data.set_tab_id(tab_id.id());
47 sync_data.set_window_id(window_id.id());
48 sync_data.set_tab_visual_index(tab_visual_index);
49 sync_data.set_current_navigation_index(current_navigation_index);
50 sync_data.set_pinned(pinned);
51 sync_data.set_extension_app_id(extension_app_id);
52 for (std::vector<SerializedNavigationEntry>::const_iterator
53 it = navigations.begin(); it != navigations.end(); ++it) {
54 *sync_data.add_navigation() = it->ToSyncData();
56 return sync_data;
59 // SessionWindow ---------------------------------------------------------------
61 SessionWindow::SessionWindow()
62 : selected_tab_index(-1),
63 type(TYPE_TABBED),
64 is_constrained(true),
65 show_state(ui::SHOW_STATE_DEFAULT) {
68 SessionWindow::~SessionWindow() {
69 STLDeleteElements(&tabs);
72 sync_pb::SessionWindow SessionWindow::ToSyncData() const {
73 sync_pb::SessionWindow sync_data;
74 sync_data.set_window_id(window_id.id());
75 sync_data.set_selected_tab_index(selected_tab_index);
76 switch (type) {
77 case SessionWindow::TYPE_TABBED:
78 sync_data.set_browser_type(
79 sync_pb::SessionWindow_BrowserType_TYPE_TABBED);
80 break;
81 case SessionWindow::TYPE_POPUP:
82 sync_data.set_browser_type(
83 sync_pb::SessionWindow_BrowserType_TYPE_POPUP);
84 break;
85 default:
86 NOTREACHED() << "Unhandled browser type.";
89 for (size_t i = 0; i < tabs.size(); i++)
90 sync_data.add_tab(tabs[i]->tab_id.id());
92 return sync_data;
95 } // namespace sessions