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

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

Issue 1148203002: Fix crash when logging in with an open uber page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 500? Created 5 years, 7 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
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/foreign_session_handler.h" 5 #include "chrome/browser/ui/webui/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 10
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); 151 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
152 152
153 // Only return the delegate if it exists and it is done syncing sessions. 153 // Only return the delegate if it exists and it is done syncing sessions.
154 if (service && service->SyncActive()) 154 if (service && service->SyncActive())
155 return service->GetOpenTabsUIDelegate(); 155 return service->GetOpenTabsUIDelegate();
156 156
157 return NULL; 157 return NULL;
158 } 158 }
159 159
160 void ForeignSessionHandler::RegisterMessages() { 160 void ForeignSessionHandler::RegisterMessages() {
161 Init(); 161 Profile* profile = Profile::FromWebUI(web_ui());
Dan Beam 2015/05/20 18:40:02 only called one place
162 ProfileSyncService* service =
163 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
164 registrar_.Add(this, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE,
165 content::Source<ProfileSyncService>(service));
166 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED,
167 content::Source<Profile>(profile));
168 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED,
169 content::Source<Profile>(profile));
170
162 web_ui()->RegisterMessageCallback("deleteForeignSession", 171 web_ui()->RegisterMessageCallback("deleteForeignSession",
163 base::Bind(&ForeignSessionHandler::HandleDeleteForeignSession, 172 base::Bind(&ForeignSessionHandler::HandleDeleteForeignSession,
164 base::Unretained(this))); 173 base::Unretained(this)));
165 web_ui()->RegisterMessageCallback("getForeignSessions", 174 web_ui()->RegisterMessageCallback("getForeignSessions",
166 base::Bind(&ForeignSessionHandler::HandleGetForeignSessions, 175 base::Bind(&ForeignSessionHandler::HandleGetForeignSessions,
167 base::Unretained(this))); 176 base::Unretained(this)));
168 web_ui()->RegisterMessageCallback("openForeignSession", 177 web_ui()->RegisterMessageCallback("openForeignSession",
169 base::Bind(&ForeignSessionHandler::HandleOpenForeignSession, 178 base::Bind(&ForeignSessionHandler::HandleOpenForeignSession,
170 base::Unretained(this))); 179 base::Unretained(this)));
171 web_ui()->RegisterMessageCallback("setForeignSessionCollapsed", 180 web_ui()->RegisterMessageCallback("setForeignSessionCollapsed",
172 base::Bind(&ForeignSessionHandler::HandleSetForeignSessionCollapsed, 181 base::Bind(&ForeignSessionHandler::HandleSetForeignSessionCollapsed,
173 base::Unretained(this))); 182 base::Unretained(this)));
174 } 183 }
175 184
176 void ForeignSessionHandler::Init() {
177 Profile* profile = Profile::FromWebUI(web_ui());
178 ProfileSyncService* service =
179 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
180 registrar_.Add(this, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE,
181 content::Source<ProfileSyncService>(service));
182 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED,
183 content::Source<Profile>(profile));
184 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED,
185 content::Source<Profile>(profile));
186 }
187
188 void ForeignSessionHandler::Observe( 185 void ForeignSessionHandler::Observe(
189 int type, 186 int type,
190 const content::NotificationSource& source, 187 const content::NotificationSource& source,
191 const content::NotificationDetails& details) { 188 const content::NotificationDetails& details) {
192 base::ListValue list_value;
Dan Beam 2015/05/20 18:40:02 not needed, declared too high. just axed.
193
194 switch (type) { 189 switch (type) {
195 case chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED: 190 case chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED:
196 // Tab sync is disabled, so clean up data about collapsed sessions. 191 // Tab sync is disabled, so clean up data about collapsed sessions.
197 Profile::FromWebUI(web_ui())->GetPrefs()->ClearPref( 192 Profile::FromWebUI(web_ui())->GetPrefs()->ClearPref(
198 prefs::kNtpCollapsedForeignSessions); 193 prefs::kNtpCollapsedForeignSessions);
199 // Fall through. 194 // Fall through.
200 case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE: 195 case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE:
201 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED: 196 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED:
202 HandleGetForeignSessions(&list_value); 197 HandleGetForeignSessions(nullptr);
203 break; 198 break;
204 default: 199 default:
205 NOTREACHED(); 200 NOTREACHED();
206 } 201 }
207 } 202 }
208 203
209
210 bool ForeignSessionHandler::IsTabSyncEnabled() { 204 bool ForeignSessionHandler::IsTabSyncEnabled() {
211 Profile* profile = Profile::FromWebUI(web_ui()); 205 Profile* profile = Profile::FromWebUI(web_ui());
212 ProfileSyncService* service = 206 ProfileSyncService* service =
213 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); 207 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
214 return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS); 208 return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS);
215 } 209 }
216 210
217 base::string16 ForeignSessionHandler::FormatSessionTime( 211 base::string16 ForeignSessionHandler::FormatSessionTime(
218 const base::Time& time) { 212 const base::Time& time) {
219 // Return a time like "1 hour ago", "2 days ago", etc. 213 // Return a time like "1 hour ago", "2 days ago", etc.
220 base::Time now = base::Time::Now(); 214 base::Time now = base::Time::Now();
221 // TimeFormat does not support negative TimeDelta values, so then we use 0. 215 // TimeFormat does not support negative TimeDelta values, so then we use 0.
222 return ui::TimeFormat::Simple( 216 return ui::TimeFormat::Simple(
223 ui::TimeFormat::FORMAT_ELAPSED, ui::TimeFormat::LENGTH_SHORT, 217 ui::TimeFormat::FORMAT_ELAPSED, ui::TimeFormat::LENGTH_SHORT,
224 now < time ? base::TimeDelta() : now - time); 218 now < time ? base::TimeDelta() : now - time);
225 } 219 }
226 220
227 void ForeignSessionHandler::HandleGetForeignSessions( 221 void ForeignSessionHandler::HandleGetForeignSessions(
228 const base::ListValue* args) { 222 const base::ListValue* /*args*/) {
229 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui()); 223 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui());
230 std::vector<const SyncedSession*> sessions; 224 std::vector<const SyncedSession*> sessions;
231 225
232 base::ListValue session_list; 226 base::ListValue session_list;
233 if (open_tabs && open_tabs->GetAllForeignSessions(&sessions)) { 227 if (open_tabs && open_tabs->GetAllForeignSessions(&sessions)) {
234 // Sort sessions from most recent to least recent. 228 // Sort sessions from most recent to least recent.
235 std::sort(sessions.begin(), sessions.end(), SortSessionsByRecency); 229 std::sort(sessions.begin(), sessions.end(), SortSessionsByRecency);
236 230
237 // Use a pref to keep track of sessions that were collapsed by the user. 231 // Use a pref to keep track of sessions that were collapsed by the user.
238 // To prevent the pref from accumulating stale sessions, clear it each time 232 // To prevent the pref from accumulating stale sessions, clear it each time
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 last_synced < base::TimeDelta::FromMinutes(1) ? 407 last_synced < base::TimeDelta::FromMinutes(1) ?
414 l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW) : 408 l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW) :
415 ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, 409 ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED,
416 ui::TimeFormat::LENGTH_SHORT, last_synced)); 410 ui::TimeFormat::LENGTH_SHORT, last_synced));
417 dictionary->SetInteger("sessionId", window.window_id.id()); 411 dictionary->SetInteger("sessionId", window.window_id.id());
418 dictionary->Set("tabs", tab_values.release()); 412 dictionary->Set("tabs", tab_values.release());
419 return true; 413 return true;
420 } 414 }
421 415
422 } // namespace browser_sync 416 } // namespace browser_sync
OLDNEW
« chrome/browser/prefs/browser_prefs.cc ('K') | « chrome/browser/ui/webui/foreign_session_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698