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 if (num_populated == 0) | |
akalin
2011/10/03 18:50:21
return (num_populated == 0);
Nicolas Zea
2011/10/03 19:36:15
Done.
| |
50 return true; | |
51 return false; | |
18 } | 52 } |
19 | 53 |
20 } // namespace browser_sync | 54 } // namespace browser_sync |
OLD | NEW |