OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/sync/glue/synced_session.h" | 5 #include "chrome/browser/sync/glue/synced_session.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "chrome/browser/sessions/session_types.h" | 8 #include "chrome/browser/sessions/session_types.h" |
| 9 #include "chrome/common/url_constants.h" |
9 | 10 |
10 namespace browser_sync { | 11 namespace browser_sync { |
11 | 12 |
12 SyncedSession::SyncedSession() : session_tag("invalid"), | 13 SyncedSession::SyncedSession() : session_tag("invalid"), |
13 device_type(TYPE_UNSET) { | 14 device_type(TYPE_UNSET) { |
14 } | 15 } |
15 | 16 |
16 SyncedSession::~SyncedSession() { | 17 SyncedSession::~SyncedSession() { |
17 STLDeleteElements(&windows); | 18 STLDeleteContainerPairSecondPointers(windows.begin(), windows.end()); |
| 19 } |
| 20 |
| 21 // Note: if you modify this, make sure you modify IsValidTab in |
| 22 // SessionModelAssociator. |
| 23 bool IsValidSessionTab(const SessionTab& tab) { |
| 24 if (tab.navigations.empty()) |
| 25 return false; |
| 26 int selected_index = tab.current_navigation_index; |
| 27 selected_index = std::max( |
| 28 0, |
| 29 std::min(selected_index, |
| 30 static_cast<int>(tab.navigations.size() - 1))); |
| 31 if (selected_index == 0 && |
| 32 tab.navigations.size() == 1 && |
| 33 tab.navigations.at(selected_index).virtual_url().GetOrigin() == |
| 34 GURL(chrome::kChromeUINewTabURL)) { |
| 35 // This is a new tab with no further history, skip. |
| 36 return false; |
| 37 } |
| 38 return true; |
| 39 } |
| 40 |
| 41 bool SessionWindowHasNoTabsToSync(const SessionWindow& window) { |
| 42 int num_populated = 0; |
| 43 for (std::vector<SessionTab*>::const_iterator i = window.tabs.begin(); |
| 44 i != window.tabs.end(); ++i) { |
| 45 const SessionTab* tab = *i; |
| 46 if (IsValidSessionTab(*tab)) |
| 47 num_populated++; |
| 48 } |
| 49 return (num_populated == 0); |
18 } | 50 } |
19 | 51 |
20 } // namespace browser_sync | 52 } // namespace browser_sync |
OLD | NEW |