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