| 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" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 base::Unretained(this))); | 55 base::Unretained(this))); |
| 56 web_ui()->RegisterMessageCallback("openForeignSession", | 56 web_ui()->RegisterMessageCallback("openForeignSession", |
| 57 base::Bind(&ForeignSessionHandler::HandleOpenForeignSession, | 57 base::Bind(&ForeignSessionHandler::HandleOpenForeignSession, |
| 58 base::Unretained(this))); | 58 base::Unretained(this))); |
| 59 web_ui()->RegisterMessageCallback("deleteForeignSession", | 59 web_ui()->RegisterMessageCallback("deleteForeignSession", |
| 60 base::Bind(&ForeignSessionHandler::HandleDeleteForeignSession, | 60 base::Bind(&ForeignSessionHandler::HandleDeleteForeignSession, |
| 61 base::Unretained(this))); | 61 base::Unretained(this))); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ForeignSessionHandler::Init() { | 64 void ForeignSessionHandler::Init() { |
| 65 // TODO(dubroy): Change this to only observe this notification on the current |
| 66 // profile, rather than all sources (crbug.com/124717). |
| 67 registrar_.Add(this, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
| 68 content::NotificationService::AllSources()); |
| 69 |
| 65 Profile* profile = Profile::FromWebUI(web_ui()); | 70 Profile* profile = Profile::FromWebUI(web_ui()); |
| 66 registrar_.Add(this, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | |
| 67 content::Source<Profile>(profile)); | |
| 68 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, | 71 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, |
| 69 content::Source<Profile>(profile)); | 72 content::Source<Profile>(profile)); |
| 70 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, | 73 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, |
| 71 content::Source<Profile>(profile)); | 74 content::Source<Profile>(profile)); |
| 72 } | 75 } |
| 73 | 76 |
| 74 void ForeignSessionHandler::Observe( | 77 void ForeignSessionHandler::Observe( |
| 75 int type, | 78 int type, |
| 76 const content::NotificationSource& source, | 79 const content::NotificationSource& source, |
| 77 const content::NotificationDetails& details) { | 80 const content::NotificationDetails& details) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 99 service->GetSessionModelAssociator(); | 102 service->GetSessionModelAssociator(); |
| 100 if (!service->ShouldPushChanges()) | 103 if (!service->ShouldPushChanges()) |
| 101 return NULL; | 104 return NULL; |
| 102 return model_associator; | 105 return model_associator; |
| 103 } | 106 } |
| 104 | 107 |
| 105 bool ForeignSessionHandler::IsTabSyncEnabled() { | 108 bool ForeignSessionHandler::IsTabSyncEnabled() { |
| 106 Profile* profile = Profile::FromWebUI(web_ui()); | 109 Profile* profile = Profile::FromWebUI(web_ui()); |
| 107 ProfileSyncService* service = | 110 ProfileSyncService* service = |
| 108 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 111 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 109 return service && service->GetSessionModelAssociator(); | 112 return service && service->GetPreferredDataTypes().Has(syncable::SESSIONS); |
| 110 } | 113 } |
| 111 | 114 |
| 112 string16 ForeignSessionHandler::FormatSessionTime(const base::Time& time) { | 115 string16 ForeignSessionHandler::FormatSessionTime(const base::Time& time) { |
| 113 // Return a time like "1 hour ago", "2 days ago", etc. | 116 // Return a time like "1 hour ago", "2 days ago", etc. |
| 114 return TimeFormat::TimeElapsed(base::Time::Now() - time); | 117 return TimeFormat::TimeElapsed(base::Time::Now() - time); |
| 115 } | 118 } |
| 116 | 119 |
| 117 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { | 120 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { |
| 118 SessionModelAssociator* associator = GetModelAssociator(); | 121 SessionModelAssociator* associator = GetModelAssociator(); |
| 119 std::vector<const SyncedSession*> sessions; | 122 std::vector<const SyncedSession*> sessions; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 return false; | 277 return false; |
| 275 dictionary->SetString("type", "window"); | 278 dictionary->SetString("type", "window"); |
| 276 dictionary->SetDouble("timestamp", | 279 dictionary->SetDouble("timestamp", |
| 277 static_cast<double>(window.timestamp.ToInternalValue())); | 280 static_cast<double>(window.timestamp.ToInternalValue())); |
| 278 dictionary->SetInteger("sessionId", window.window_id.id()); | 281 dictionary->SetInteger("sessionId", window.window_id.id()); |
| 279 dictionary->Set("tabs", tab_values.release()); | 282 dictionary->Set("tabs", tab_values.release()); |
| 280 return true; | 283 return true; |
| 281 } | 284 } |
| 282 | 285 |
| 283 } // namespace browser_sync | 286 } // namespace browser_sync |
| OLD | NEW |