| 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" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/sessions/session_restore.h" | 20 #include "chrome/browser/sessions/session_restore.h" |
| 21 #include "chrome/browser/sync/profile_sync_service.h" | 21 #include "chrome/browser/sync/profile_sync_service.h" |
| 22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 23 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 23 #include "chrome/browser/ui/webui/session_favicon_source.h" | 24 #include "chrome/browser/ui/webui/session_favicon_source.h" |
| 24 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | |
| 25 #include "chrome/browser/ui/webui/web_ui_util.h" | 25 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 26 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/common/time_format.h" | 28 #include "chrome/common/time_format.h" |
| 29 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
| 32 #include "content/public/browser/web_ui.h" | 32 #include "content/public/browser/web_ui.h" |
| 33 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (service && service->ShouldPushChanges()) | 120 if (service && service->ShouldPushChanges()) |
| 121 return service->GetSessionModelAssociator(); | 121 return service->GetSessionModelAssociator(); |
| 122 | 122 |
| 123 return NULL; | 123 return NULL; |
| 124 } | 124 } |
| 125 | 125 |
| 126 bool ForeignSessionHandler::IsTabSyncEnabled() { | 126 bool ForeignSessionHandler::IsTabSyncEnabled() { |
| 127 Profile* profile = Profile::FromWebUI(web_ui()); | 127 Profile* profile = Profile::FromWebUI(web_ui()); |
| 128 ProfileSyncService* service = | 128 ProfileSyncService* service = |
| 129 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 129 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 130 return service && service->GetPreferredDataTypes().Has(syncable::SESSIONS); | 130 return service && service->GetPreferredDataTypes().Has(syncer::SESSIONS); |
| 131 } | 131 } |
| 132 | 132 |
| 133 string16 ForeignSessionHandler::FormatSessionTime(const base::Time& time) { | 133 string16 ForeignSessionHandler::FormatSessionTime(const base::Time& time) { |
| 134 // Return a time like "1 hour ago", "2 days ago", etc. | 134 // Return a time like "1 hour ago", "2 days ago", etc. |
| 135 return TimeFormat::TimeElapsed(base::Time::Now() - time); | 135 return TimeFormat::TimeElapsed(base::Time::Now() - time); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { | 138 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { |
| 139 SessionModelAssociator* associator = GetModelAssociator(); | 139 SessionModelAssociator* associator = GetModelAssociator(); |
| 140 std::vector<const SyncedSession*> sessions; | 140 std::vector<const SyncedSession*> sessions; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 dictionary->SetString("userVisibleTimestamp", | 343 dictionary->SetString("userVisibleTimestamp", |
| 344 last_synced < base::TimeDelta::FromMinutes(1) ? | 344 last_synced < base::TimeDelta::FromMinutes(1) ? |
| 345 l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW) : | 345 l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW) : |
| 346 TimeFormat::TimeElapsed(last_synced)); | 346 TimeFormat::TimeElapsed(last_synced)); |
| 347 dictionary->SetInteger("sessionId", window.window_id.id()); | 347 dictionary->SetInteger("sessionId", window.window_id.id()); |
| 348 dictionary->Set("tabs", tab_values.release()); | 348 dictionary->Set("tabs", tab_values.release()); |
| 349 return true; | 349 return true; |
| 350 } | 350 } |
| 351 | 351 |
| 352 } // namespace browser_sync | 352 } // namespace browser_sync |
| OLD | NEW |