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