[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / sessions / session_types.cc
bloba7ec0221734f1406ad8ae9e677de7d71c05663a1
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.
5 #include "chrome/browser/sessions/session_types.h"
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"
12 using sessions::SerializedNavigationEntry;
14 // SessionTab -----------------------------------------------------------------
16 SessionTab::SessionTab()
17 : tab_visual_index(-1),
18 current_navigation_index(-1),
19 pinned(false) {
22 SessionTab::~SessionTab() {
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)));
40 session_storage_persistent_id.clear();
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();
55 return sync_data;
58 // SessionWindow ---------------------------------------------------------------
60 SessionWindow::SessionWindow()
61 : selected_tab_index(-1),
62 type(Browser::TYPE_TABBED),
63 is_constrained(true),
64 show_state(ui::SHOW_STATE_DEFAULT) {
67 SessionWindow::~SessionWindow() {
68 STLDeleteElements(&tabs);
71 sync_pb::SessionWindow SessionWindow::ToSyncData() const {
72 sync_pb::SessionWindow sync_data;
73 sync_data.set_window_id(window_id.id());
74 sync_data.set_selected_tab_index(selected_tab_index);
75 switch (type) {
76 case Browser::TYPE_TABBED:
77 sync_data.set_browser_type(
78 sync_pb::SessionWindow_BrowserType_TYPE_TABBED);
79 break;
80 case Browser::TYPE_POPUP:
81 sync_data.set_browser_type(
82 sync_pb::SessionWindow_BrowserType_TYPE_POPUP);
83 break;
84 default:
85 NOTREACHED() << "Unhandled browser type.";
88 for (size_t i = 0; i < tabs.size(); i++)
89 sync_data.add_tab(tabs[i]->tab_id.id());
91 return sync_data;