| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sessions/session_restore.h" | 15 #include "chrome/browser/sessions/session_restore.h" |
| 16 #include "chrome/browser/sync/engine/syncapi.h" | 16 #include "chrome/browser/sync/engine/syncapi.h" |
| 17 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
| 18 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 18 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 19 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "content/common/notification_details.h" | 20 #include "content/common/notification_details.h" |
| 20 #include "content/common/notification_service.h" | 21 #include "content/common/notification_service.h" |
| 21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 22 | 23 |
| 23 namespace browser_sync { | 24 namespace browser_sync { |
| 24 | 25 |
| 25 // Maximum number of session we're going to display on the NTP | 26 // Maximum number of session we're going to display on the NTP |
| 26 static const int kMaxSessionsToShow = 10; | 27 static const int kMaxSessionsToShow = 10; |
| 27 | 28 |
| 28 // Invalid value, used to note that we don't have a tab or window number. | 29 // Invalid value, used to note that we don't have a tab or window number. |
| 29 static const int kInvalidId = -1; | 30 static const int kInvalidId = -1; |
| 30 | 31 |
| 31 ForeignSessionHandler::ForeignSessionHandler() { | 32 ForeignSessionHandler::ForeignSessionHandler() { |
| 32 Init(); | 33 Init(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void ForeignSessionHandler::RegisterMessages() { | 36 void ForeignSessionHandler::RegisterMessages() { |
| 36 web_ui_->RegisterMessageCallback("getForeignSessions", | 37 web_ui_->RegisterMessageCallback("getForeignSessions", |
| 37 NewCallback(this, | 38 NewCallback(this, |
| 38 &ForeignSessionHandler::HandleGetForeignSessions)); | 39 &ForeignSessionHandler::HandleGetForeignSessions)); |
| 39 web_ui_->RegisterMessageCallback("openForeignSession", | 40 web_ui_->RegisterMessageCallback("openForeignSession", |
| 40 NewCallback(this, | 41 NewCallback(this, |
| 41 &ForeignSessionHandler::HandleOpenForeignSession)); | 42 &ForeignSessionHandler::HandleOpenForeignSession)); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void ForeignSessionHandler::Init() { | 45 void ForeignSessionHandler::Init() { |
| 45 registrar_.Add(this, NotificationType::SYNC_CONFIGURE_DONE, | 46 registrar_.Add(this, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
| 46 NotificationService::AllSources()); | 47 NotificationService::AllSources()); |
| 47 registrar_.Add(this, NotificationType::FOREIGN_SESSION_UPDATED, | 48 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, |
| 48 NotificationService::AllSources()); | 49 NotificationService::AllSources()); |
| 49 registrar_.Add(this, NotificationType::FOREIGN_SESSION_DISABLED, | 50 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, |
| 50 NotificationService::AllSources()); | 51 NotificationService::AllSources()); |
| 51 } | 52 } |
| 52 | 53 |
| 53 void ForeignSessionHandler::Observe(NotificationType type, | 54 void ForeignSessionHandler::Observe(int type, |
| 54 const NotificationSource& source, | 55 const NotificationSource& source, |
| 55 const NotificationDetails& details) { | 56 const NotificationDetails& details) { |
| 56 ListValue list_value; | 57 ListValue list_value; |
| 57 switch (type.value) { | 58 switch (type) { |
| 58 case NotificationType::SYNC_CONFIGURE_DONE: | 59 case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE: |
| 59 case NotificationType::FOREIGN_SESSION_UPDATED: | 60 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED: |
| 60 HandleGetForeignSessions(&list_value); | 61 HandleGetForeignSessions(&list_value); |
| 61 break; | 62 break; |
| 62 case NotificationType::FOREIGN_SESSION_DISABLED: | 63 case chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED: |
| 63 // Calling foreignSessions with empty list will automatically hide | 64 // Calling foreignSessions with empty list will automatically hide |
| 64 // foreign session section. | 65 // foreign session section. |
| 65 web_ui_->CallJavascriptFunction("foreignSessions", list_value); | 66 web_ui_->CallJavascriptFunction("foreignSessions", list_value); |
| 66 break; | 67 break; |
| 67 default: | 68 default: |
| 68 NOTREACHED(); | 69 NOTREACHED(); |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 SessionModelAssociator* ForeignSessionHandler::GetModelAssociator() { | 73 SessionModelAssociator* ForeignSessionHandler::GetModelAssociator() { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return false; | 233 return false; |
| 233 dictionary->SetString("type", "window"); | 234 dictionary->SetString("type", "window"); |
| 234 dictionary->SetDouble("timestamp", | 235 dictionary->SetDouble("timestamp", |
| 235 static_cast<double>(window.timestamp.ToInternalValue())); | 236 static_cast<double>(window.timestamp.ToInternalValue())); |
| 236 dictionary->SetInteger("sessionId", window.window_id.id()); | 237 dictionary->SetInteger("sessionId", window.window_id.id()); |
| 237 dictionary->Set("tabs", tab_values.release()); | 238 dictionary->Set("tabs", tab_values.release()); |
| 238 return true; | 239 return true; |
| 239 } | 240 } |
| 240 | 241 |
| 241 } // namespace browser_sync | 242 } // namespace browser_sync |
| OLD | NEW |