| 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/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/sessions/session_restore.h" | 17 #include "chrome/browser/sessions/session_restore.h" |
| 18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 19 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 20 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 23 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
| 24 | 25 |
| 25 namespace browser_sync { | 26 namespace browser_sync { |
| 26 | 27 |
| 27 // Maximum number of session we're going to display on the NTP | 28 // Maximum number of session we're going to display on the NTP |
| 28 static const int kMaxSessionsToShow = 10; | 29 static const int kMaxSessionsToShow = 10; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // Calling foreignSessions with empty list will automatically hide | 68 // Calling foreignSessions with empty list will automatically hide |
| 68 // foreign session section. | 69 // foreign session section. |
| 69 web_ui()->CallJavascriptFunction("foreignSessions", list_value); | 70 web_ui()->CallJavascriptFunction("foreignSessions", list_value); |
| 70 break; | 71 break; |
| 71 default: | 72 default: |
| 72 NOTREACHED(); | 73 NOTREACHED(); |
| 73 } | 74 } |
| 74 } | 75 } |
| 75 | 76 |
| 76 SessionModelAssociator* ForeignSessionHandler::GetModelAssociator() { | 77 SessionModelAssociator* ForeignSessionHandler::GetModelAssociator() { |
| 77 ProfileSyncService* service = | 78 ProfileSyncService* service(ProfileSyncServiceFactory:: |
| 78 Profile::FromWebUI(web_ui())->GetProfileSyncService(); | 79 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui()))); |
| 79 if (service == NULL) | 80 if (service == NULL) |
| 80 return NULL; | 81 return NULL; |
| 81 | 82 |
| 82 // We only want to set the model associator if there is one, and it is done | 83 // We only want to set the model associator if there is one, and it is done |
| 83 // syncing sessions. | 84 // syncing sessions. |
| 84 SessionModelAssociator* model_associator = | 85 SessionModelAssociator* model_associator = |
| 85 service->GetSessionModelAssociator(); | 86 service->GetSessionModelAssociator(); |
| 86 if (model_associator == NULL || | 87 if (model_associator == NULL || |
| 87 !service->ShouldPushChanges()) { | 88 !service->ShouldPushChanges()) { |
| 88 return NULL; | 89 return NULL; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 return false; | 237 return false; |
| 237 dictionary->SetString("type", "window"); | 238 dictionary->SetString("type", "window"); |
| 238 dictionary->SetDouble("timestamp", | 239 dictionary->SetDouble("timestamp", |
| 239 static_cast<double>(window.timestamp.ToInternalValue())); | 240 static_cast<double>(window.timestamp.ToInternalValue())); |
| 240 dictionary->SetInteger("sessionId", window.window_id.id()); | 241 dictionary->SetInteger("sessionId", window.window_id.id()); |
| 241 dictionary->Set("tabs", tab_values.release()); | 242 dictionary->Set("tabs", tab_values.release()); |
| 242 return true; | 243 return true; |
| 243 } | 244 } |
| 244 | 245 |
| 245 } // namespace browser_sync | 246 } // namespace browser_sync |
| OLD | NEW |