| 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 | 10 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 Profile* profile = Profile::FromWebUI(web_ui()); | 214 Profile* profile = Profile::FromWebUI(web_ui()); |
| 215 ProfileSyncService* service = | 215 ProfileSyncService* service = |
| 216 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 216 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 217 return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS); | 217 return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS); |
| 218 } | 218 } |
| 219 | 219 |
| 220 base::string16 ForeignSessionHandler::FormatSessionTime( | 220 base::string16 ForeignSessionHandler::FormatSessionTime( |
| 221 const base::Time& time) { | 221 const base::Time& time) { |
| 222 // Return a time like "1 hour ago", "2 days ago", etc. | 222 // Return a time like "1 hour ago", "2 days ago", etc. |
| 223 base::Time now = base::Time::Now(); | 223 base::Time now = base::Time::Now(); |
| 224 // TimeElapsed does not support negative TimeDelta values, so then we use 0. | 224 // TimeFormat does not support negative TimeDelta values, so then we use 0. |
| 225 return ui::TimeFormat::TimeElapsed( | 225 return ui::TimeFormat::Simple( |
| 226 ui::TimeFormat::kElapsed, ui::TimeFormat::kShort, |
| 226 now < time ? base::TimeDelta() : now - time); | 227 now < time ? base::TimeDelta() : now - time); |
| 227 } | 228 } |
| 228 | 229 |
| 229 void ForeignSessionHandler::HandleGetForeignSessions( | 230 void ForeignSessionHandler::HandleGetForeignSessions( |
| 230 const base::ListValue* args) { | 231 const base::ListValue* args) { |
| 231 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui()); | 232 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui()); |
| 232 std::vector<const SyncedSession*> sessions; | 233 std::vector<const SyncedSession*> sessions; |
| 233 | 234 |
| 234 base::ListValue session_list; | 235 base::ListValue session_list; |
| 235 if (open_tabs && open_tabs->GetAllForeignSessions(&sessions)) { | 236 if (open_tabs && open_tabs->GetAllForeignSessions(&sessions)) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 if (tab_values->GetSize() == 0) | 402 if (tab_values->GetSize() == 0) |
| 402 return false; | 403 return false; |
| 403 dictionary->SetString("type", "window"); | 404 dictionary->SetString("type", "window"); |
| 404 dictionary->SetDouble("timestamp", modification_time.ToInternalValue()); | 405 dictionary->SetDouble("timestamp", modification_time.ToInternalValue()); |
| 405 const base::TimeDelta last_synced = base::Time::Now() - modification_time; | 406 const base::TimeDelta last_synced = base::Time::Now() - modification_time; |
| 406 // If clock skew leads to a future time, or we last synced less than a minute | 407 // If clock skew leads to a future time, or we last synced less than a minute |
| 407 // ago, output "Just now". | 408 // ago, output "Just now". |
| 408 dictionary->SetString("userVisibleTimestamp", | 409 dictionary->SetString("userVisibleTimestamp", |
| 409 last_synced < base::TimeDelta::FromMinutes(1) ? | 410 last_synced < base::TimeDelta::FromMinutes(1) ? |
| 410 l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW) : | 411 l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW) : |
| 411 ui::TimeFormat::TimeElapsed(last_synced)); | 412 ui::TimeFormat::Simple(ui::TimeFormat::kElapsed, |
| 413 ui::TimeFormat::kShort, last_synced)); |
| 412 dictionary->SetInteger("sessionId", window.window_id.id()); | 414 dictionary->SetInteger("sessionId", window.window_id.id()); |
| 413 dictionary->Set("tabs", tab_values.release()); | 415 dictionary->Set("tabs", tab_values.release()); |
| 414 return true; | 416 return true; |
| 415 } | 417 } |
| 416 | 418 |
| 417 } // namespace browser_sync | 419 } // namespace browser_sync |
| OLD | NEW |