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