diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 21:30:23 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 21:30:23 +0000 |
commit | 95484099a0e8b4be4074d6a39b4a4a0eba3f01d6 (patch) | |
tree | ab0f91e0da60f31ec73a6057df20fcbc0714a03a /chrome/browser/dom_ui/foreign_session_handler.cc | |
parent | f2c9df50f8acaa7818758f4fdb0b95ab41ee2706 (diff) | |
download | chromium_src-95484099a0e8b4be4074d6a39b4a4a0eba3f01d6.zip chromium_src-95484099a0e8b4be4074d6a39b4a4a0eba3f01d6.tar.gz chromium_src-95484099a0e8b4be4074d6a39b4a4a0eba3f01d6.tar.bz2 |
Revert 56423 - Added classes to enable session sync functionality.
TEST=ProfileSyncServiceSessionTest
BUG=30519
Original patch by jerrica@chromium.org
Original review: http://codereview.chromium.org/3168009
Review URL: http://codereview.chromium.org/3184004
TBR=tim@chromium.org
Review URL: http://codereview.chromium.org/3127017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56426 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui/foreign_session_handler.cc')
-rw-r--r-- | chrome/browser/dom_ui/foreign_session_handler.cc | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/chrome/browser/dom_ui/foreign_session_handler.cc b/chrome/browser/dom_ui/foreign_session_handler.cc deleted file mode 100644 index 1bf8c10..0000000 --- a/chrome/browser/dom_ui/foreign_session_handler.cc +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/dom_ui/foreign_session_handler.h" - -#include "base/scoped_vector.h" -#include "chrome/browser/browser.h" -#include "chrome/browser/dom_ui/value_helper.h" -#include "chrome/browser/sessions/session_restore.h" -#include "chrome/browser/sessions/tab_restore_service.h" -#include "chrome/browser/sync/engine/syncapi.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/notification_details.h" -#include "chrome/common/notification_service.h" - -namespace browser_sync { - -static const int kMaxSessionsToShow = 10; - -ForeignSessionHandler::ForeignSessionHandler() { - Init(); -} - -void ForeignSessionHandler::RegisterMessages() { - dom_ui_->RegisterMessageCallback("getForeignSessions", - NewCallback(this, - &ForeignSessionHandler::HandleGetForeignSessions)); - dom_ui_->RegisterMessageCallback("reopenForeignSession", - NewCallback(this, - &ForeignSessionHandler::HandleReopenForeignSession)); -} - -void ForeignSessionHandler::Init() { - registrar_.Add(this, NotificationType::SYNC_CONFIGURE_DONE, - NotificationService::AllSources()); - registrar_.Add(this, NotificationType::FOREIGN_SESSION_UPDATED, - NotificationService::AllSources()); - registrar_.Add(this, NotificationType::FOREIGN_SESSION_DELETED, - NotificationService::AllSources()); -} - -void ForeignSessionHandler::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type != NotificationType::SYNC_CONFIGURE_DONE && - type != NotificationType::FOREIGN_SESSION_UPDATED && - type != NotificationType::FOREIGN_SESSION_DELETED) { - NOTREACHED(); - return; - } - ListValue list_value; - HandleGetForeignSessions(&list_value); -} - -SessionModelAssociator* ForeignSessionHandler::GetModelAssociator() { - ProfileSyncService* service = dom_ui_->GetProfile()->GetProfileSyncService(); - if (service == NULL) - return NULL; - // We only want to set the model associator if there is one, and it is done - // syncing sessions. - SessionModelAssociator* model_associator = service-> - GetSessionModelAssociator(); - if (model_associator == NULL || - !service->ShouldPushChanges()) { - return NULL; - } - return dom_ui_->GetProfile()->GetProfileSyncService()-> - GetSessionModelAssociator(); -} - -void ForeignSessionHandler::HandleGetForeignSessions(const Value* content) { - SessionModelAssociator* associator = GetModelAssociator(); - if (associator) - GetForeignSessions(associator); -} - -void ForeignSessionHandler::HandleReopenForeignSession( - const Value* content) { - // Extract the machine tag and use it to obtain the id for the node we are - // looking for. Send it along with a valid associator to OpenForeignSessions. - if (content->GetType() == Value::TYPE_LIST) { - const ListValue* list_value = static_cast<const ListValue*>(content); - Value* list_member; - if (list_value->Get(0, &list_member) && - list_member->GetType() == Value::TYPE_STRING) { - const StringValue* string_value = - static_cast<const StringValue*>(list_member); - std::string session_string_value; - if (string_value->GetAsString(&session_string_value)) { - SessionModelAssociator* associator = GetModelAssociator(); - if (associator) { - int64 id = associator->GetSyncIdFromChromeId(session_string_value); - OpenForeignSession(associator, id); - } - } - } - } -} - -void ForeignSessionHandler::OpenForeignSession( - SessionModelAssociator* associator, int64 id) { - // Obtain the session windows for the foreign session. - // We don't have a ForeignSessionHandler in off the record mode, so we - // expect the ProfileSyncService to exist. - sync_api::ReadTransaction trans(dom_ui_->GetProfile()-> - GetProfileSyncService()->backend()->GetUserShareHandle()); - ScopedVector<ForeignSession> session; - associator->AppendForeignSessionWithID(id, &session.get(), &trans); - - DCHECK(session.size() == 1); - std::vector<SessionWindow*> windows = (*session.begin())->windows; - SessionRestore::RestoreForeignSessionWindows(dom_ui_->GetProfile(), &windows); -} - -void ForeignSessionHandler::GetForeignSessions( - SessionModelAssociator* associator) { - ScopedVector<ForeignSession> windows; - associator->GetSessionDataFromSyncModel(&windows.get()); - int added_count = 0; - ListValue list_value; - for (std::vector<ForeignSession*>::const_iterator i = - windows.begin(); i != windows.end() && - added_count < kMaxSessionsToShow; ++i) { - ForeignSession* foreign_session = *i; - std::vector<TabRestoreService::Entry*> entries; - dom_ui_->GetProfile()->GetTabRestoreService()->CreateEntriesFromWindows( - &foreign_session->windows, &entries); - for (std::vector<TabRestoreService::Entry*>::const_iterator it = - entries.begin(); it != entries.end(); ++it) { - TabRestoreService::Entry* entry = *it; - scoped_ptr<DictionaryValue> value(new DictionaryValue()); - if (entry->type == TabRestoreService::WINDOW && - ValueHelper::WindowToValue( - *static_cast<TabRestoreService::Window*>(entry), value.get())) { - // The javascript checks if the session id is a valid session id, - // when rendering session information to the new tab page, and it - // sends the sessionTag back when we need to restore a session. - value->SetString(L"sessionTag", foreign_session->foreign_tession_tag); - value->SetInteger(L"sessionId", entry->id); - list_value.Append(value.release()); // Give ownership to |list_value|. - } - } - added_count++; - } - dom_ui_->CallJavascriptFunction(L"foreignSessions", list_value); -} - -} // namespace browser_sync - |