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#ifndef CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_H_
6#define CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_H_
7
8#include <map>
9#include <string>
10
11#include "base/time/time.h"
12#include "chrome/browser/sessions/session_types.h"
13#include "components/sessions/session_id.h"
14#include "sync/protocol/session_specifics.pb.h"
15
16namespace content {
17class NavigationEntry;
18}
19
20namespace browser_sync {
21
22// Defines a synced session for use by session sync. A synced session is a
23// list of windows along with a unique session identifer (tag) and meta-data
24// about the device being synced.
25struct SyncedSession {
26  typedef std::map<SessionID::id_type, SessionWindow*> SyncedWindowMap;
27
28  // The type of device.
29  // Please keep in sync with ForeignSessionHelper.java
30  enum DeviceType {
31    TYPE_UNSET = 0,
32    TYPE_WIN = 1,
33    TYPE_MACOSX = 2,
34    TYPE_LINUX = 3,
35    TYPE_CHROMEOS = 4,
36    TYPE_OTHER = 5,
37    TYPE_PHONE = 6,
38    TYPE_TABLET = 7
39  };
40
41  SyncedSession();
42  ~SyncedSession();
43
44  // Unique tag for each session.
45  std::string session_tag;
46  // User-visible name
47  std::string session_name;
48
49  // Type of device this session is from.
50  DeviceType device_type;
51
52  // Last time this session was modified remotely.
53  base::Time modified_time;
54
55  // Map of windows that make up this session. Windowws are owned by the session
56  // itself and free'd on destruction.
57  SyncedWindowMap windows;
58
59  // Converts the DeviceType enum value to a string. This is used
60  // in the NTP handler for foreign sessions for matching session
61  // types to an icon style.
62  std::string DeviceTypeAsString() const {
63    switch (device_type) {
64      case SyncedSession::TYPE_WIN:
65        return "win";
66      case SyncedSession::TYPE_MACOSX:
67        return "macosx";
68      case SyncedSession::TYPE_LINUX:
69        return "linux";
70      case SyncedSession::TYPE_CHROMEOS:
71        return "chromeos";
72      case SyncedSession::TYPE_OTHER:
73        return "other";
74      case SyncedSession::TYPE_PHONE:
75        return "phone";
76      case SyncedSession::TYPE_TABLET:
77        return "tablet";
78      default:
79        return std::string();
80    }
81  }
82
83  // Convert this object to its protocol buffer equivalent. Shallow conversion,
84  // does not create SessionTab protobufs.
85  sync_pb::SessionHeader ToSessionHeader() const;
86
87 private:
88  DISALLOW_COPY_AND_ASSIGN(SyncedSession);
89};
90
91// Control which foreign tabs we're interested in syncing/displaying. Checks
92// that the tab has navigations and contains at least one valid url.
93// Note: chrome:// and file:// are not considered valid urls (for syncing).
94bool ShouldSyncSessionTab(const SessionTab& tab);
95
96// Checks whether the window has tabs to sync. If no tabs to sync, it returns
97// true, false otherwise.
98bool SessionWindowHasNoTabsToSync(const SessionWindow& window);
99
100}  // namespace browser_sync
101
102#endif  // CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_H_
103