| 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/foreign_session_handler.h" | 5 #include "chrome/browser/ui/webui/foreign_session_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 std::vector<const ::sessions::SessionWindow*>::const_iterator( | 187 std::vector<const ::sessions::SessionWindow*>::const_iterator( |
| 188 windows.end()) : iter_begin + 1; | 188 windows.end()) : iter_begin + 1; |
| 189 SessionRestore::RestoreForeignSessionWindows(Profile::FromWebUI(web_ui), | 189 SessionRestore::RestoreForeignSessionWindows(Profile::FromWebUI(web_ui), |
| 190 iter_begin, iter_end); | 190 iter_begin, iter_end); |
| 191 } | 191 } |
| 192 | 192 |
| 193 // static | 193 // static |
| 194 sync_sessions::OpenTabsUIDelegate* ForeignSessionHandler::GetOpenTabsUIDelegate( | 194 sync_sessions::OpenTabsUIDelegate* ForeignSessionHandler::GetOpenTabsUIDelegate( |
| 195 content::WebUI* web_ui) { | 195 content::WebUI* web_ui) { |
| 196 Profile* profile = Profile::FromWebUI(web_ui); | 196 Profile* profile = Profile::FromWebUI(web_ui); |
| 197 ProfileSyncService* service = | 197 browser_sync::ProfileSyncService* service = |
| 198 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 198 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 199 | 199 |
| 200 // Only return the delegate if it exists and it is done syncing sessions. | 200 // Only return the delegate if it exists and it is done syncing sessions. |
| 201 if (service && service->IsSyncActive()) | 201 if (service && service->IsSyncActive()) |
| 202 return service->GetOpenTabsUIDelegate(); | 202 return service->GetOpenTabsUIDelegate(); |
| 203 | 203 |
| 204 return NULL; | 204 return NULL; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void ForeignSessionHandler::RegisterMessages() { | 207 void ForeignSessionHandler::RegisterMessages() { |
| 208 Profile* profile = Profile::FromWebUI(web_ui()); | 208 Profile* profile = Profile::FromWebUI(web_ui()); |
| 209 | 209 |
| 210 ProfileSyncService* service = | 210 browser_sync::ProfileSyncService* service = |
| 211 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 211 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 212 | 212 |
| 213 // NOTE: The ProfileSyncService can be null in tests. | 213 // NOTE: The ProfileSyncService can be null in tests. |
| 214 if (service) | 214 if (service) |
| 215 scoped_observer_.Add(service); | 215 scoped_observer_.Add(service); |
| 216 | 216 |
| 217 web_ui()->RegisterMessageCallback("deleteForeignSession", | 217 web_ui()->RegisterMessageCallback("deleteForeignSession", |
| 218 base::Bind(&ForeignSessionHandler::HandleDeleteForeignSession, | 218 base::Bind(&ForeignSessionHandler::HandleDeleteForeignSession, |
| 219 base::Unretained(this))); | 219 base::Unretained(this))); |
| 220 web_ui()->RegisterMessageCallback("getForeignSessions", | 220 web_ui()->RegisterMessageCallback("getForeignSessions", |
| (...skipping 10 matching lines...) Expand all Loading... |
| 231 void ForeignSessionHandler::OnSyncConfigurationCompleted() { | 231 void ForeignSessionHandler::OnSyncConfigurationCompleted() { |
| 232 HandleGetForeignSessions(nullptr); | 232 HandleGetForeignSessions(nullptr); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void ForeignSessionHandler::OnForeignSessionUpdated() { | 235 void ForeignSessionHandler::OnForeignSessionUpdated() { |
| 236 HandleGetForeignSessions(nullptr); | 236 HandleGetForeignSessions(nullptr); |
| 237 } | 237 } |
| 238 | 238 |
| 239 bool ForeignSessionHandler::IsTabSyncEnabled() { | 239 bool ForeignSessionHandler::IsTabSyncEnabled() { |
| 240 Profile* profile = Profile::FromWebUI(web_ui()); | 240 Profile* profile = Profile::FromWebUI(web_ui()); |
| 241 ProfileSyncService* service = | 241 browser_sync::ProfileSyncService* service = |
| 242 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 242 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 243 return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS); | 243 return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS); |
| 244 } | 244 } |
| 245 | 245 |
| 246 base::string16 ForeignSessionHandler::FormatSessionTime( | 246 base::string16 ForeignSessionHandler::FormatSessionTime( |
| 247 const base::Time& time) { | 247 const base::Time& time) { |
| 248 // Return a time like "1 hour ago", "2 days ago", etc. | 248 // Return a time like "1 hour ago", "2 days ago", etc. |
| 249 base::Time now = base::Time::Now(); | 249 base::Time now = base::Time::Now(); |
| 250 // TimeFormat does not support negative TimeDelta values, so then we use 0. | 250 // TimeFormat does not support negative TimeDelta values, so then we use 0. |
| 251 return ui::TimeFormat::Simple( | 251 return ui::TimeFormat::Simple( |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 // collapsed state persists. | 434 // collapsed state persists. |
| 435 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 435 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 436 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions); | 436 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions); |
| 437 if (is_collapsed) | 437 if (is_collapsed) |
| 438 update.Get()->SetBoolean(session_tag, true); | 438 update.Get()->SetBoolean(session_tag, true); |
| 439 else | 439 else |
| 440 update.Get()->Remove(session_tag, NULL); | 440 update.Get()->Remove(session_tag, NULL); |
| 441 } | 441 } |
| 442 | 442 |
| 443 } // namespace browser_sync | 443 } // namespace browser_sync |
| OLD | NEW |