Chromium Code Reviews| Index: chrome/browser/ui/webui/ntp/foreign_session_handler.cc |
| diff --git a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc |
| index 4a6bbaed1601a893c36c1a9f65c796fe3fc52ed2..2c6b4accdc3eef43bfd053413f0f2a5b203f61b0 100644 |
| --- a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc |
| +++ b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc |
| @@ -21,6 +21,7 @@ |
| #include "chrome/browser/ui/webui/web_ui_util.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/url_constants.h" |
| +#include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_source.h" |
| #include "content/public/browser/web_ui.h" |
| @@ -94,38 +95,30 @@ void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { |
| SessionModelAssociator* associator = GetModelAssociator(); |
| std::vector<const SyncedSession*> sessions; |
| - if (associator == NULL) { |
| - // Called before associator created, exit. |
| - return; |
| - } |
| - |
| - // Note: we don't own the SyncedSessions themselves. |
| - if (!associator->GetAllForeignSessions(&sessions)) { |
| - LOG(ERROR) << "ForeignSessionHandler failed to get session data from" |
| - "SessionModelAssociator."; |
| - return; |
| - } |
| - int added_count = 0; |
| ListValue session_list; |
| - for (std::vector<const SyncedSession*>::const_iterator i = |
| - sessions.begin(); i != sessions.end() && |
| - added_count < kMaxSessionsToShow; ++i) { |
| - const SyncedSession* session = *i; |
| - scoped_ptr<DictionaryValue> session_data(new DictionaryValue()); |
| - session_data->SetString("tag", session->session_tag); |
| - session_data->SetString("name", session->session_name); |
| - scoped_ptr<ListValue> window_list(new ListValue()); |
| - for (SyncedSession::SyncedWindowMap::const_iterator it = |
| - session->windows.begin(); it != session->windows.end(); ++it) { |
| - SessionWindow* window = it->second; |
| - scoped_ptr<DictionaryValue> window_data(new DictionaryValue()); |
| - if (SessionWindowToValue(*window, window_data.get())) { |
| - window_list->Append(window_data.release()); |
| + if (associator && associator->GetAllForeignSessions(&sessions)) { |
| + // Note: we don't own the SyncedSessions themselves. |
| + int added_count = 0; |
| + for (std::vector<const SyncedSession*>::const_iterator i = |
|
Dan Beam
2012/03/26 20:42:39
change from iterator to index
Patrick Dubroy
2012/03/26 21:41:47
Done.
|
| + sessions.begin(); i != sessions.end() && |
| + added_count < kMaxSessionsToShow; ++i) { |
| + const SyncedSession* session = *i; |
| + scoped_ptr<DictionaryValue> session_data(new DictionaryValue()); |
| + session_data->SetString("tag", session->session_tag); |
| + session_data->SetString("name", session->session_name); |
| + scoped_ptr<ListValue> window_list(new ListValue()); |
| + for (SyncedSession::SyncedWindowMap::const_iterator it = |
| + session->windows.begin(); it != session->windows.end(); ++it) { |
| + SessionWindow* window = it->second; |
| + scoped_ptr<DictionaryValue> window_data(new DictionaryValue()); |
| + if (SessionWindowToValue(*window, window_data.get())) { |
|
Dan Beam
2012/03/26 20:57:38
nit: no curlies
Patrick Dubroy
2012/03/26 21:41:47
Done.
|
| + window_list->Append(window_data.release()); |
| + } |
| } |
| + session_data->Set("windows", window_list.release()); |
| + session_list.Append(session_data.release()); |
| + added_count++; |
| } |
| - session_data->Set("windows", window_list.release()); |
| - session_list.Append(session_data.release()); |
| - added_count++; |
| } |
| web_ui()->CallJavascriptFunction("ntp.foreignSessions", session_list); |
| } |