Chromium Code Reviews| 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 registrar_.Add(this, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | |
| 66 content::NotificationService::AllSources()); | |
|
Nicolas Zea
2012/04/23 18:18:52
This is going to listen to other profiles as well
| |
| 67 | |
| 65 Profile* profile = Profile::FromWebUI(web_ui()); | 68 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, | 69 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, |
| 69 content::Source<Profile>(profile)); | 70 content::Source<Profile>(profile)); |
| 70 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, | 71 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, |
| 71 content::Source<Profile>(profile)); | 72 content::Source<Profile>(profile)); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void ForeignSessionHandler::Observe( | 75 void ForeignSessionHandler::Observe( |
| 75 int type, | 76 int type, |
| 76 const content::NotificationSource& source, | 77 const content::NotificationSource& source, |
| 77 const content::NotificationDetails& details) { | 78 const content::NotificationDetails& details) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 99 service->GetSessionModelAssociator(); | 100 service->GetSessionModelAssociator(); |
| 100 if (!service->ShouldPushChanges()) | 101 if (!service->ShouldPushChanges()) |
| 101 return NULL; | 102 return NULL; |
| 102 return model_associator; | 103 return model_associator; |
| 103 } | 104 } |
| 104 | 105 |
| 105 bool ForeignSessionHandler::IsTabSyncEnabled() { | 106 bool ForeignSessionHandler::IsTabSyncEnabled() { |
| 106 Profile* profile = Profile::FromWebUI(web_ui()); | 107 Profile* profile = Profile::FromWebUI(web_ui()); |
| 107 ProfileSyncService* service = | 108 ProfileSyncService* service = |
| 108 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 109 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 109 return service && service->GetSessionModelAssociator(); | 110 return service && service->GetPreferredDataTypes().Has(syncable::SESSIONS); |
| 110 } | 111 } |
| 111 | 112 |
| 112 string16 ForeignSessionHandler::FormatSessionTime(const base::Time& time) { | 113 string16 ForeignSessionHandler::FormatSessionTime(const base::Time& time) { |
| 113 // Return a time like "1 hour ago", "2 days ago", etc. | 114 // Return a time like "1 hour ago", "2 days ago", etc. |
| 114 return TimeFormat::TimeElapsed(base::Time::Now() - time); | 115 return TimeFormat::TimeElapsed(base::Time::Now() - time); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { | 118 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { |
| 118 SessionModelAssociator* associator = GetModelAssociator(); | 119 SessionModelAssociator* associator = GetModelAssociator(); |
| 119 std::vector<const SyncedSession*> sessions; | 120 std::vector<const SyncedSession*> sessions; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 return false; | 275 return false; |
| 275 dictionary->SetString("type", "window"); | 276 dictionary->SetString("type", "window"); |
| 276 dictionary->SetDouble("timestamp", | 277 dictionary->SetDouble("timestamp", |
| 277 static_cast<double>(window.timestamp.ToInternalValue())); | 278 static_cast<double>(window.timestamp.ToInternalValue())); |
| 278 dictionary->SetInteger("sessionId", window.window_id.id()); | 279 dictionary->SetInteger("sessionId", window.window_id.id()); |
| 279 dictionary->Set("tabs", tab_values.release()); | 280 dictionary->Set("tabs", tab_values.release()); |
| 280 return true; | 281 return true; |
| 281 } | 282 } |
| 282 | 283 |
| 283 } // namespace browser_sync | 284 } // namespace browser_sync |
| OLD | NEW |