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

Unified Diff: chrome/browser/ui/webui/ntp/foreign_session_handler.cc

Issue 9959030: Allow hiding of sessions from Other Devices via context menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/foreign_session_handler.cc
diff --git a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc
index 1a2f0dc737c8b19ce9cddc94bb36ea0e742dde56..525915052568ccc294e689dabf01db327e6504f0 100644
--- a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc
+++ b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc
@@ -9,6 +9,7 @@
#include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/i18n/time_formatting.h"
#include "base/memory/scoped_vector.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
@@ -20,6 +21,7 @@
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/browser/ui/webui/web_ui_util.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/time_format.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
@@ -54,6 +56,9 @@ void ForeignSessionHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("openForeignSession",
base::Bind(&ForeignSessionHandler::HandleOpenForeignSession,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback("deleteForeignSession",
+ base::Bind(&ForeignSessionHandler::HandleDeleteForeignSession,
+ base::Unretained(this)));
}
void ForeignSessionHandler::Init() {
@@ -104,6 +109,11 @@ bool ForeignSessionHandler::IsTabSyncEnabled() {
return service && service->GetSessionModelAssociator();
}
+string16 ForeignSessionHandler::FormatSessionTime(const base::Time& time) {
+ // Return a time like "1 hour ago", "2 days ago", etc.
+ return TimeFormat::TimeElapsed(base::Time::Now() - time);
+}
+
void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) {
SessionModelAssociator* associator = GetModelAssociator();
std::vector<const SyncedSession*> sessions;
@@ -119,6 +129,8 @@ void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) {
scoped_ptr<DictionaryValue> session_data(new DictionaryValue());
session_data->SetString("tag", session->session_tag);
session_data->SetString("name", session->session_name);
+ session_data->SetString("modifiedTime",
+ FormatSessionTime(session->modified_time));
scoped_ptr<ListValue> window_list(new ListValue());
for (SyncedSession::SyncedWindowMap::const_iterator it =
session->windows.begin(); it != session->windows.end(); ++it) {
@@ -138,8 +150,7 @@ void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) {
tab_sync_enabled);
}
-void ForeignSessionHandler::HandleOpenForeignSession(
- const ListValue* args) {
+void ForeignSessionHandler::HandleOpenForeignSession(const ListValue* args) {
size_t num_args = args->GetSize();
// Expect either 2 or 8 args. For restoring an entire window, only
// two arguments are required -- the session tag and the window id.
@@ -152,7 +163,7 @@ void ForeignSessionHandler::HandleOpenForeignSession(
return;
}
- // Extract the machine tag (always provided).
+ // Extract the session tag (always provided).
std::string session_string_value;
if (!args->GetString(0, &session_string_value)) {
LOG(ERROR) << "Failed to extract session tag.";
@@ -209,6 +220,20 @@ void ForeignSessionHandler::HandleOpenForeignSession(
}
}
+void ForeignSessionHandler::HandleDeleteForeignSession(const ListValue* args) {
+ if (args->GetSize() != 1U) {
+ LOG(ERROR) << "Wrong number of args to deleteForeignSession";
+ return;
+ }
+
+ // Get the session tag argument (required).
+ std::string session_tag = UTF16ToUTF8(ExtractStringValue(args));
+
+ SessionModelAssociator* associator = GetModelAssociator();
+ if (associator)
+ associator->DeleteForeignSession(session_tag);
+}
+
bool ForeignSessionHandler::SessionTabToValue(
const SessionTab& tab,
DictionaryValue* dictionary) {
« no previous file with comments | « chrome/browser/ui/webui/ntp/foreign_session_handler.h ('k') | chrome/browser/ui/webui/ntp/ntp_resource_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698