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

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

Issue 2517243002: [Sync] Removing complexity around PROXY_TABS now that empty sessions are provided when disabled. (Closed)
Patch Set: Rebase and re-vulcanize after conflict. Created 4 years 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 230 }
231 231
232 void ForeignSessionHandler::OnSyncConfigurationCompleted() { 232 void ForeignSessionHandler::OnSyncConfigurationCompleted() {
233 HandleGetForeignSessions(nullptr); 233 HandleGetForeignSessions(nullptr);
234 } 234 }
235 235
236 void ForeignSessionHandler::OnForeignSessionUpdated() { 236 void ForeignSessionHandler::OnForeignSessionUpdated() {
237 HandleGetForeignSessions(nullptr); 237 HandleGetForeignSessions(nullptr);
238 } 238 }
239 239
240 bool ForeignSessionHandler::IsTabSyncEnabled() {
241 Profile* profile = Profile::FromWebUI(web_ui());
242 browser_sync::ProfileSyncService* service =
243 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
244 return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS);
245 }
246
247 base::string16 ForeignSessionHandler::FormatSessionTime( 240 base::string16 ForeignSessionHandler::FormatSessionTime(
248 const base::Time& time) { 241 const base::Time& time) {
249 // Return a time like "1 hour ago", "2 days ago", etc. 242 // Return a time like "1 hour ago", "2 days ago", etc.
250 base::Time now = base::Time::Now(); 243 base::Time now = base::Time::Now();
251 // TimeFormat does not support negative TimeDelta values, so then we use 0. 244 // TimeFormat does not support negative TimeDelta values, so then we use 0.
252 return ui::TimeFormat::Simple( 245 return ui::TimeFormat::Simple(
253 ui::TimeFormat::FORMAT_ELAPSED, ui::TimeFormat::LENGTH_SHORT, 246 ui::TimeFormat::FORMAT_ELAPSED, ui::TimeFormat::LENGTH_SHORT,
254 now < time ? base::TimeDelta() : now - time); 247 now < time ? base::TimeDelta() : now - time);
255 } 248 }
256 249
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 BuildWindowData(modification_time, 1)); 324 BuildWindowData(modification_time, 1));
332 window_data->Set("tabs", tab_values.release()); 325 window_data->Set("tabs", tab_values.release());
333 window_list->Append(std::move(window_data)); 326 window_list->Append(std::move(window_data));
334 } 327 }
335 } 328 }
336 329
337 session_data->Set("windows", window_list.release()); 330 session_data->Set("windows", window_list.release());
338 session_list.Append(std::move(session_data)); 331 session_list.Append(std::move(session_data));
339 } 332 }
340 } 333 }
341 base::FundamentalValue tab_sync_enabled(IsTabSyncEnabled()); 334 web_ui()->CallJavascriptFunctionUnsafe("setForeignSessions", session_list);
342 web_ui()->CallJavascriptFunctionUnsafe("setForeignSessions", session_list,
343 tab_sync_enabled);
344 } 335 }
345 336
346 void ForeignSessionHandler::HandleOpenForeignSession( 337 void ForeignSessionHandler::HandleOpenForeignSession(
347 const base::ListValue* args) { 338 const base::ListValue* args) {
348 size_t num_args = args->GetSize(); 339 size_t num_args = args->GetSize();
349 // Expect either 1 or 8 args. For restoring an entire session, only 340 // Expect either 1 or 8 args. For restoring an entire session, only
350 // one argument is required -- the session tag. To restore a tab, 341 // one argument is required -- the session tag. To restore a tab,
351 // the additional args required are the window id, the tab id, 342 // the additional args required are the window id, the tab id,
352 // and 4 properties of the event object (button, altKey, ctrlKey, 343 // and 4 properties of the event object (button, altKey, ctrlKey,
353 // metaKey, shiftKey) for determining how to open the tab. 344 // metaKey, shiftKey) for determining how to open the tab.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // collapsed state persists. 426 // collapsed state persists.
436 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 427 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
437 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions); 428 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions);
438 if (is_collapsed) 429 if (is_collapsed)
439 update.Get()->SetBoolean(session_tag, true); 430 update.Get()->SetBoolean(session_tag, true);
440 else 431 else
441 update.Get()->Remove(session_tag, NULL); 432 update.Get()->Remove(session_tag, NULL);
442 } 433 }
443 434
444 } // namespace browser_sync 435 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/foreign_session_handler.h ('k') | chrome/test/data/webui/md_history/history_metrics_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698