OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 if (!service->ShouldPushChanges()) | 88 if (!service->ShouldPushChanges()) |
89 return NULL; | 89 return NULL; |
90 return model_associator; | 90 return model_associator; |
91 } | 91 } |
92 | 92 |
93 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { | 93 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { |
94 SessionModelAssociator* associator = GetModelAssociator(); | 94 SessionModelAssociator* associator = GetModelAssociator(); |
95 std::vector<const SyncedSession*> sessions; | 95 std::vector<const SyncedSession*> sessions; |
96 | 96 |
97 if (associator == NULL) { | 97 if (associator == NULL) { |
98 // Called before associator created, exit. | 98 // Called before associator created, exit. |
Dan Beam
2012/03/23 21:12:47
possibly move comment above if, remove curlies and
Patrick Dubroy
2012/03/26 15:16:46
Done.
| |
99 return; | 99 return; |
100 } | 100 } |
101 | 101 |
102 if (associator->GetAllForeignSessions(&sessions)) { | |
Dan Beam
2012/03/23 21:12:47
no curlies, also should there be a ! in front of t
Patrick Dubroy
2012/03/26 15:16:46
Ummm...yeah. Nice catch. :-) Done.
| |
103 return; | |
104 } | |
105 | |
102 // Note: we don't own the SyncedSessions themselves. | 106 // Note: we don't own the SyncedSessions themselves. |
103 if (!associator->GetAllForeignSessions(&sessions)) { | |
104 LOG(ERROR) << "ForeignSessionHandler failed to get session data from" | |
105 "SessionModelAssociator."; | |
106 return; | |
107 } | |
108 int added_count = 0; | 107 int added_count = 0; |
109 ListValue session_list; | 108 ListValue session_list; |
110 for (std::vector<const SyncedSession*>::const_iterator i = | 109 for (std::vector<const SyncedSession*>::const_iterator i = |
111 sessions.begin(); i != sessions.end() && | 110 sessions.begin(); i != sessions.end() && |
112 added_count < kMaxSessionsToShow; ++i) { | 111 added_count < kMaxSessionsToShow; ++i) { |
113 const SyncedSession* session = *i; | 112 const SyncedSession* session = *i; |
114 scoped_ptr<DictionaryValue> session_data(new DictionaryValue()); | 113 scoped_ptr<DictionaryValue> session_data(new DictionaryValue()); |
115 session_data->SetString("tag", session->session_tag); | 114 session_data->SetString("tag", session->session_tag); |
116 session_data->SetString("name", session->session_name); | 115 session_data->SetString("name", session->session_name); |
117 scoped_ptr<ListValue> window_list(new ListValue()); | 116 scoped_ptr<ListValue> window_list(new ListValue()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 return false; | 240 return false; |
242 dictionary->SetString("type", "window"); | 241 dictionary->SetString("type", "window"); |
243 dictionary->SetDouble("timestamp", | 242 dictionary->SetDouble("timestamp", |
244 static_cast<double>(window.timestamp.ToInternalValue())); | 243 static_cast<double>(window.timestamp.ToInternalValue())); |
245 dictionary->SetInteger("sessionId", window.window_id.id()); | 244 dictionary->SetInteger("sessionId", window.window_id.id()); |
246 dictionary->Set("tabs", tab_values.release()); | 245 dictionary->Set("tabs", tab_values.release()); |
247 return true; | 246 return true; |
248 } | 247 } |
249 | 248 |
250 } // namespace browser_sync | 249 } // namespace browser_sync |
OLD | NEW |