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/sessions_ui.h" | 5 #include "chrome/browser/ui/webui/sessions_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sync/glue/session_model_associator.h" | 10 #include "chrome/browser/sync/glue/session_model_associator.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 // Sends the recent session list to JS. | 71 // Sends the recent session list to JS. |
72 void UpdateUI(); | 72 void UpdateUI(); |
73 | 73 |
74 // Returns the model associated for getting the list of sessions from sync. | 74 // Returns the model associated for getting the list of sessions from sync. |
75 browser_sync::SessionModelAssociator* GetModelAssociator(); | 75 browser_sync::SessionModelAssociator* GetModelAssociator(); |
76 | 76 |
77 // Appends each entry in |tabs| to |tab_list| as a DictonaryValue. | 77 // Appends each entry in |tabs| to |tab_list| as a DictonaryValue. |
78 void GetTabList(const std::vector<SessionTab*>& tabs, ListValue* tab_list); | 78 void GetTabList(const std::vector<SessionTab*>& tabs, ListValue* tab_list); |
79 | 79 |
80 // Appends each entry in |windows| to |window_list| as a DictonaryValue. | 80 // Appends each entry in |windows| to |window_list| as a DictonaryValue. |
81 void GetWindowList(const std::vector<SessionWindow*>& windows, | 81 void GetWindowList( |
82 ListValue* window_list); | 82 const browser_sync::SyncedSession::SyncedWindowMap& windows, |
83 ListValue* window_list); | |
83 | 84 |
84 // Appends each entry in |sessions| to |session_list| as a DictonaryValue. | 85 // Appends each entry in |sessions| to |session_list| as a DictonaryValue. |
85 void GetSessionList( | 86 void GetSessionList( |
86 const std::vector<const browser_sync::SyncedSession*>& sessions, | 87 const std::vector<const browser_sync::SyncedSession*>& sessions, |
87 ListValue* session_list); | 88 ListValue* session_list); |
88 | 89 |
89 // Traverses all tabs in |sessions| and adds them to |all_tabs|. | 90 // Traverses all tabs in |sessions| and adds them to |all_tabs|. |
90 void GetAllTabs( | 91 void GetAllTabs( |
91 const std::vector<const browser_sync::SyncedSession*>& sessions, | 92 const std::vector<const browser_sync::SyncedSession*>& sessions, |
92 std::vector<SessionTab*>* all_tabs); | 93 std::vector<SessionTab*>* all_tabs); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 if (nav.title().empty()) | 150 if (nav.title().empty()) |
150 tab_data->SetString("title", nav.virtual_url().spec()); | 151 tab_data->SetString("title", nav.virtual_url().spec()); |
151 else | 152 else |
152 tab_data->SetString("title", nav.title()); | 153 tab_data->SetString("title", nav.title()); |
153 tab_data->SetString("url", nav.virtual_url().spec()); | 154 tab_data->SetString("url", nav.virtual_url().spec()); |
154 tab_list->Append(tab_data.release()); | 155 tab_list->Append(tab_data.release()); |
155 } | 156 } |
156 } | 157 } |
157 | 158 |
158 void SessionsDOMHandler::GetWindowList( | 159 void SessionsDOMHandler::GetWindowList( |
159 const std::vector<SessionWindow*>& windows, ListValue* window_list) { | 160 const browser_sync::SyncedSession::SyncedWindowMap& windows, |
160 for (std::vector<SessionWindow*>::const_iterator it = | 161 ListValue* window_list) { |
162 for (browser_sync::SyncedSession::SyncedWindowMap::const_iterator it = | |
161 windows.begin(); it != windows.end(); ++it) { | 163 windows.begin(); it != windows.end(); ++it) { |
162 const SessionWindow* window = *it; | 164 const SessionWindow* window = it->second; |
163 scoped_ptr<DictionaryValue> window_data(new DictionaryValue()); | 165 scoped_ptr<DictionaryValue> window_data(new DictionaryValue()); |
164 window_data->SetInteger("id", window->window_id.id()); | 166 window_data->SetInteger("id", window->window_id.id()); |
165 window_data->SetDouble("timestamp", | 167 window_data->SetDouble("timestamp", |
166 static_cast<double> (window->timestamp.ToInternalValue())); | 168 static_cast<double> (window->timestamp.ToInternalValue())); |
167 scoped_ptr<ListValue> tab_list(new ListValue()); | 169 scoped_ptr<ListValue> tab_list(new ListValue()); |
168 GetTabList(window->tabs, tab_list.get()); | 170 GetTabList(window->tabs, tab_list.get()); |
169 window_data->Set("tabs", tab_list.release()); | 171 window_data->Set("tabs", tab_list.release()); |
170 window_list->Append(window_data.release()); | 172 window_list->Append(window_data.release()); |
171 } | 173 } |
172 } | 174 } |
(...skipping 10 matching lines...) Expand all Loading... | |
183 GetWindowList(session->windows, window_list.get()); | 185 GetWindowList(session->windows, window_list.get()); |
184 session_data->Set("windows", window_list.release()); | 186 session_data->Set("windows", window_list.release()); |
185 session_list->Append(session_data.release()); | 187 session_list->Append(session_data.release()); |
186 } | 188 } |
187 } | 189 } |
188 | 190 |
189 void SessionsDOMHandler::GetAllTabs( | 191 void SessionsDOMHandler::GetAllTabs( |
190 const std::vector<const browser_sync::SyncedSession*>& sessions, | 192 const std::vector<const browser_sync::SyncedSession*>& sessions, |
191 std::vector<SessionTab*>* all_tabs) { | 193 std::vector<SessionTab*>* all_tabs) { |
192 for (size_t i = 0; i < sessions.size(); i++) { | 194 for (size_t i = 0; i < sessions.size(); i++) { |
193 const std::vector<SessionWindow*>& windows = sessions[i]->windows; | 195 const browser_sync::SyncedSession::SyncedWindowMap& windows = |
194 for (size_t j = 0; j < windows.size(); j++) { | 196 sessions[i]->windows; |
195 const std::vector<SessionTab*>& tabs = windows[j]->tabs; | 197 browser_sync::SyncedSession::SyncedWindowMap::const_iterator iter = |
akalin
2011/09/26 21:57:24
prefer for loop (even though the indentation gets
Nicolas Zea
2011/09/26 22:55:26
Done.
| |
198 windows.begin(); | |
199 while (iter != windows.end()) { | |
200 const std::vector<SessionTab*>& tabs = iter->second->tabs; | |
196 all_tabs->insert(all_tabs->end(), tabs.begin(), tabs.end()); | 201 all_tabs->insert(all_tabs->end(), tabs.begin(), tabs.end()); |
202 ++iter; | |
197 } | 203 } |
198 } | 204 } |
199 } | 205 } |
200 | 206 |
201 // Comparator function for sort() in CreateMagicTabList() below. | 207 // Comparator function for sort() in CreateMagicTabList() below. |
202 bool CompareTabsByTimestamp(SessionTab* lhs, SessionTab* rhs) { | 208 bool CompareTabsByTimestamp(SessionTab* lhs, SessionTab* rhs) { |
203 return lhs->timestamp.ToInternalValue() > rhs->timestamp.ToInternalValue(); | 209 return lhs->timestamp.ToInternalValue() > rhs->timestamp.ToInternalValue(); |
204 } | 210 } |
205 | 211 |
206 void SessionsDOMHandler::CreateMagicTabList( | 212 void SessionsDOMHandler::CreateMagicTabList( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 262 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
257 profile->GetChromeURLDataManager()->AddDataSource( | 263 profile->GetChromeURLDataManager()->AddDataSource( |
258 CreateSessionsUIHTMLSource()); | 264 CreateSessionsUIHTMLSource()); |
259 } | 265 } |
260 | 266 |
261 // static | 267 // static |
262 RefCountedMemory* SessionsUI::GetFaviconResourceBytes() { | 268 RefCountedMemory* SessionsUI::GetFaviconResourceBytes() { |
263 return ResourceBundle::GetSharedInstance(). | 269 return ResourceBundle::GetSharedInstance(). |
264 LoadDataResourceBytes(IDR_HISTORY_FAVICON); | 270 LoadDataResourceBytes(IDR_HISTORY_FAVICON); |
265 } | 271 } |
OLD | NEW |