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/ui/webui/ntp/foreign_session_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 "SessionModelAssociator."; | 101 "SessionModelAssociator."; |
102 return; | 102 return; |
103 } | 103 } |
104 int added_count = 0; | 104 int added_count = 0; |
105 ListValue session_list; | 105 ListValue session_list; |
106 for (std::vector<const SyncedSession*>::const_iterator i = | 106 for (std::vector<const SyncedSession*>::const_iterator i = |
107 sessions.begin(); i != sessions.end() && | 107 sessions.begin(); i != sessions.end() && |
108 added_count < kMaxSessionsToShow; ++i) { | 108 added_count < kMaxSessionsToShow; ++i) { |
109 const SyncedSession* foreign_session = *i; | 109 const SyncedSession* foreign_session = *i; |
110 scoped_ptr<ListValue> window_list(new ListValue()); | 110 scoped_ptr<ListValue> window_list(new ListValue()); |
111 for (std::vector<SessionWindow*>::const_iterator it = | 111 for (SyncedSession::SyncedWindowMap::const_iterator it = |
112 foreign_session->windows.begin(); it != foreign_session->windows.end(); | 112 foreign_session->windows.begin(); it != foreign_session->windows.end(); |
113 ++it) { | 113 ++it) { |
114 SessionWindow* window = *it; | 114 SessionWindow* window = it->second; |
115 scoped_ptr<DictionaryValue> window_data(new DictionaryValue()); | 115 scoped_ptr<DictionaryValue> window_data(new DictionaryValue()); |
116 if (SessionWindowToValue(*window, window_data.get())) { | 116 if (SessionWindowToValue(*window, window_data.get())) { |
117 window_data->SetString("sessionTag", foreign_session->session_tag); | 117 window_data->SetString("sessionTag", foreign_session->session_tag); |
118 | 118 |
119 // Give ownership to |list_value|. | 119 // Give ownership to |list_value|. |
120 window_list->Append(window_data.release()); | 120 window_list->Append(window_data.release()); |
121 } | 121 } |
122 } | 122 } |
123 added_count++; | 123 added_count++; |
124 | 124 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 if (tab_id != kInvalidId) { | 168 if (tab_id != kInvalidId) { |
169 // We don't actually care about |window_num|, this is just a sanity check. | 169 // We don't actually care about |window_num|, this is just a sanity check. |
170 DCHECK_LT(kInvalidId, window_num); | 170 DCHECK_LT(kInvalidId, window_num); |
171 const SessionTab* tab; | 171 const SessionTab* tab; |
172 if (!associator->GetForeignTab(session_string_value, tab_id, &tab)) { | 172 if (!associator->GetForeignTab(session_string_value, tab_id, &tab)) { |
173 LOG(ERROR) << "Failed to load foreign tab."; | 173 LOG(ERROR) << "Failed to load foreign tab."; |
174 return; | 174 return; |
175 } | 175 } |
176 SessionRestore::RestoreForeignSessionTab(profile, *tab); | 176 SessionRestore::RestoreForeignSessionTab(profile, *tab); |
177 } else { | 177 } else { |
178 std::vector<SessionWindow*> windows; | 178 std::vector<const SessionWindow*> windows; |
179 // Note: we don't own the ForeignSessions themselves. | 179 // Note: we don't own the ForeignSessions themselves. |
180 if (!associator->GetForeignSession(session_string_value, &windows)) { | 180 if (!associator->GetForeignSession(session_string_value, &windows)) { |
181 LOG(ERROR) << "ForeignSessionHandler failed to get session data from" | 181 LOG(ERROR) << "ForeignSessionHandler failed to get session data from" |
182 "SessionModelAssociator."; | 182 "SessionModelAssociator."; |
183 return; | 183 return; |
184 } | 184 } |
185 std::vector<SessionWindow*>::const_iterator iter_begin = windows.begin() + | 185 std::vector<const SessionWindow*>::const_iterator iter_begin = |
186 ((window_num == kInvalidId) ? 0 : window_num); | 186 windows.begin() + ((window_num == kInvalidId) ? 0 : window_num); |
187 std::vector<SessionWindow*>::const_iterator iter_end = | 187 std::vector<const SessionWindow*>::const_iterator iter_end = |
188 ((window_num == kInvalidId) ? | 188 ((window_num == kInvalidId) ? |
189 std::vector<SessionWindow*>::const_iterator(windows.end()) : | 189 std::vector<const SessionWindow*>::const_iterator(windows.end()) : |
190 iter_begin + 1); | 190 iter_begin + 1); |
191 SessionRestore::RestoreForeignSessionWindows(profile, iter_begin, iter_end); | 191 SessionRestore::RestoreForeignSessionWindows(profile, iter_begin, iter_end); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 bool ForeignSessionHandler::SessionTabToValue( | 195 bool ForeignSessionHandler::SessionTabToValue( |
196 const SessionTab& tab, | 196 const SessionTab& tab, |
197 DictionaryValue* dictionary) { | 197 DictionaryValue* dictionary) { |
198 if (tab.navigations.empty()) | 198 if (tab.navigations.empty()) |
199 return false; | 199 return false; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 return false; | 232 return false; |
233 dictionary->SetString("type", "window"); | 233 dictionary->SetString("type", "window"); |
234 dictionary->SetDouble("timestamp", | 234 dictionary->SetDouble("timestamp", |
235 static_cast<double>(window.timestamp.ToInternalValue())); | 235 static_cast<double>(window.timestamp.ToInternalValue())); |
236 dictionary->SetInteger("sessionId", window.window_id.id()); | 236 dictionary->SetInteger("sessionId", window.window_id.id()); |
237 dictionary->Set("tabs", tab_values.release()); | 237 dictionary->Set("tabs", tab_values.release()); |
238 return true; | 238 return true; |
239 } | 239 } |
240 | 240 |
241 } // namespace browser_sync | 241 } // namespace browser_sync |
OLD | NEW |