OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/dom_ui/sync_internals_message_handler.h" |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sync/profile_sync_service.h" |
| 12 #include "chrome/browser/sync/sync_ui_util.h" |
| 13 |
| 14 SyncInternalsMessageHandler::SyncInternalsMessageHandler(Profile* profile) |
| 15 : profile_(profile) { |
| 16 DCHECK(profile_); |
| 17 ProfileSyncService* service = profile_->GetProfileSyncService(); |
| 18 if (service) { |
| 19 service->AddObserver(this); |
| 20 } |
| 21 // TODO(akalin): Listen for when the service gets created/destroyed. |
| 22 } |
| 23 |
| 24 SyncInternalsMessageHandler::~SyncInternalsMessageHandler() { |
| 25 ProfileSyncService* service = profile_->GetProfileSyncService(); |
| 26 if (service) { |
| 27 service->RemoveObserver(this); |
| 28 } |
| 29 } |
| 30 |
| 31 void SyncInternalsMessageHandler::OnStateChanged() { |
| 32 dom_ui_->CallJavascriptFunction(L"onSyncServiceStateChanged"); |
| 33 } |
| 34 |
| 35 void SyncInternalsMessageHandler::RegisterMessages() { |
| 36 dom_ui_->RegisterMessageCallback( |
| 37 "getAboutInfo", |
| 38 NewCallback( |
| 39 this, &SyncInternalsMessageHandler::HandleGetAboutInfo)); |
| 40 } |
| 41 |
| 42 void SyncInternalsMessageHandler::HandleGetAboutInfo(const ListValue* args) { |
| 43 ProfileSyncService* service = profile_->GetProfileSyncService(); |
| 44 DictionaryValue about_info; |
| 45 sync_ui_util::ConstructAboutInformation(service, &about_info); |
| 46 |
| 47 dom_ui_->CallJavascriptFunction(L"onGetAboutInfoFinished", about_info); |
| 48 } |
OLD | NEW |