Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/ui/webui/ntp/foreign_session_handler.cc

Issue 9838064: Add a sign-in promo message to the Other Devices menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address dbeam's comments. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 service->GetSessionModelAssociator(); 87 service->GetSessionModelAssociator();
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 // Exit if the associator is not created or there are no foreign sessions.
98 // Called before associator created, exit. 98 if (!associator ||!associator->GetAllForeignSessions(&sessions))
99 return; 99 return;
100 }
101 100
102 // Note: we don't own the SyncedSessions themselves. 101 // 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; 102 int added_count = 0;
109 ListValue session_list; 103 ListValue session_list;
110 for (std::vector<const SyncedSession*>::const_iterator i = 104 for (std::vector<const SyncedSession*>::const_iterator i =
111 sessions.begin(); i != sessions.end() && 105 sessions.begin(); i != sessions.end() &&
112 added_count < kMaxSessionsToShow; ++i) { 106 added_count < kMaxSessionsToShow; ++i) {
113 const SyncedSession* session = *i; 107 const SyncedSession* session = *i;
114 scoped_ptr<DictionaryValue> session_data(new DictionaryValue()); 108 scoped_ptr<DictionaryValue> session_data(new DictionaryValue());
115 session_data->SetString("tag", session->session_tag); 109 session_data->SetString("tag", session->session_tag);
116 session_data->SetString("name", session->session_name); 110 session_data->SetString("name", session->session_name);
117 scoped_ptr<ListValue> window_list(new ListValue()); 111 scoped_ptr<ListValue> window_list(new ListValue());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 return false; 235 return false;
242 dictionary->SetString("type", "window"); 236 dictionary->SetString("type", "window");
243 dictionary->SetDouble("timestamp", 237 dictionary->SetDouble("timestamp",
244 static_cast<double>(window.timestamp.ToInternalValue())); 238 static_cast<double>(window.timestamp.ToInternalValue()));
245 dictionary->SetInteger("sessionId", window.window_id.id()); 239 dictionary->SetInteger("sessionId", window.window_id.id());
246 dictionary->Set("tabs", tab_values.release()); 240 dictionary->Set("tabs", tab_values.release());
247 return true; 241 return true;
248 } 242 }
249 243
250 } // namespace browser_sync 244 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698