OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_ | 5 #ifndef COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_ |
6 #define COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_ | 6 #define COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "components/sessions/core/session_id.h" | 15 #include "components/sessions/core/session_id.h" |
16 #include "components/sessions/core/session_types.h" | 16 #include "components/sessions/core/session_types.h" |
17 #include "components/sync/protocol/session_specifics.pb.h" | 17 #include "components/sync/protocol/session_specifics.pb.h" |
18 | 18 |
19 namespace sessions { | 19 namespace sync_sessions { |
20 struct SessionWindow; | |
21 } | |
22 | 20 |
23 namespace sync_sessions { | 21 // A Sync wrapper for a SessionWindow. |
| 22 struct SyncedSessionWindow { |
| 23 SyncedSessionWindow(); |
| 24 ~SyncedSessionWindow(); |
| 25 |
| 26 // Convert this object into its sync protocol buffer equivalent. |
| 27 sync_pb::SessionWindow ToSessionWindowProto() const; |
| 28 |
| 29 // Type of the window. See session_specifics.proto. |
| 30 sync_pb::SessionWindow::BrowserType window_type; |
| 31 |
| 32 // The SessionWindow this object wraps. |
| 33 sessions::SessionWindow wrapped_window; |
| 34 |
| 35 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(SyncedSessionWindow); |
| 37 }; |
24 | 38 |
25 // Defines a synced session for use by session sync. A synced session is a | 39 // Defines a synced session for use by session sync. A synced session is a |
26 // list of windows along with a unique session identifer (tag) and meta-data | 40 // list of windows along with a unique session identifer (tag) and meta-data |
27 // about the device being synced. | 41 // about the device being synced. |
28 struct SyncedSession { | 42 struct SyncedSession { |
29 // The type of device. | 43 // The type of device. |
30 // Please keep in sync with ForeignSessionHelper.java | 44 // Please keep in sync with ForeignSessionHelper.java |
31 enum DeviceType { | 45 enum DeviceType { |
32 TYPE_UNSET = 0, | 46 TYPE_UNSET = 0, |
33 TYPE_WIN = 1, | 47 TYPE_WIN = 1, |
(...skipping 14 matching lines...) Expand all Loading... |
48 std::string session_name; | 62 std::string session_name; |
49 | 63 |
50 // Type of device this session is from. | 64 // Type of device this session is from. |
51 DeviceType device_type; | 65 DeviceType device_type; |
52 | 66 |
53 // Last time this session was modified remotely. This is the max of the header | 67 // Last time this session was modified remotely. This is the max of the header |
54 // and all children tab mtimes. | 68 // and all children tab mtimes. |
55 base::Time modified_time; | 69 base::Time modified_time; |
56 | 70 |
57 // Map of windows that make up this session. | 71 // Map of windows that make up this session. |
58 std::map<SessionID::id_type, std::unique_ptr<sessions::SessionWindow>> | 72 std::map<SessionID::id_type, std::unique_ptr<SyncedSessionWindow>> windows; |
59 windows; | |
60 | 73 |
61 // A tab node id is part of the identifier for the sync tab objects. Tab node | 74 // A tab node id is part of the identifier for the sync tab objects. Tab node |
62 // ids are not used for interacting with the model/browser tabs. However, when | 75 // ids are not used for interacting with the model/browser tabs. However, when |
63 // when we want to delete a foreign session, we use these values to inform | 76 // when we want to delete a foreign session, we use these values to inform |
64 // sync which tabs to delete. We are extracting these tab node ids from | 77 // sync which tabs to delete. We are extracting these tab node ids from |
65 // individual session (tab, not header) specifics, but store them here in the | 78 // individual session (tab, not header) specifics, but store them here in the |
66 // SyncedSession during runtime. We do this because tab node ids may be reused | 79 // SyncedSession during runtime. We do this because tab node ids may be reused |
67 // for different tabs, and tracking which tab id is currently associated with | 80 // for different tabs, and tracking which tab id is currently associated with |
68 // each tab node id is both difficult and unnecessary. See comments at | 81 // each tab node id is both difficult and unnecessary. See comments at |
69 // SyncedSessionTracker::GetTabImpl for a concrete example of id reuse. | 82 // SyncedSessionTracker::GetTabImpl for a concrete example of id reuse. |
(...skipping 18 matching lines...) Expand all Loading... |
88 return "phone"; | 101 return "phone"; |
89 case SyncedSession::TYPE_TABLET: | 102 case SyncedSession::TYPE_TABLET: |
90 return "tablet"; | 103 return "tablet"; |
91 default: | 104 default: |
92 return std::string(); | 105 return std::string(); |
93 } | 106 } |
94 } | 107 } |
95 | 108 |
96 // Convert this object to its protocol buffer equivalent. Shallow conversion, | 109 // Convert this object to its protocol buffer equivalent. Shallow conversion, |
97 // does not create SessionTab protobufs. | 110 // does not create SessionTab protobufs. |
98 sync_pb::SessionHeader ToSessionHeader() const; | 111 sync_pb::SessionHeader ToSessionHeaderProto() const; |
99 | 112 |
100 private: | 113 private: |
101 DISALLOW_COPY_AND_ASSIGN(SyncedSession); | 114 DISALLOW_COPY_AND_ASSIGN(SyncedSession); |
102 }; | 115 }; |
103 | 116 |
104 } // namespace sync_sessions | 117 } // namespace sync_sessions |
105 | 118 |
106 #endif // COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_ | 119 #endif // COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_ |
OLD | NEW |