1 // Copyright 2014 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.
5 #include "chrome/browser/ui/webui/invalidations_message_handler.h"
8 #include "chrome/browser/invalidation/invalidation_logger.h"
9 #include "chrome/browser/invalidation/invalidation_service.h"
10 #include "chrome/browser/invalidation/invalidation_service_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/web_ui.h"
14 namespace invalidation
{
15 class InvalidationLogger
;
16 } // namespace invalidation
19 class ObjectIdInvalidationMap
;
22 InvalidationsMessageHandler::InvalidationsMessageHandler()
23 : logger_(NULL
), isRegistered(false) {}
25 InvalidationsMessageHandler::~InvalidationsMessageHandler() {
27 logger_
->UnregisterForDebug(this);
30 void InvalidationsMessageHandler::RegisterMessages() {
31 web_ui()->RegisterMessageCallback(
33 base::Bind(&InvalidationsMessageHandler::UIReady
,
34 base::Unretained(this)));
37 void InvalidationsMessageHandler::UIReady(const base::ListValue
* args
) {
38 Profile
* profile
= Profile::FromWebUI(web_ui());
39 if (!isRegistered
&& profile
) {
40 invalidation::InvalidationService
* invalidation_service
=
41 invalidation::InvalidationServiceFactory::GetForProfile(profile
);
42 if (invalidation_service
)
43 logger_
= invalidation_service
->GetInvalidationLogger();
45 logger_
->RegisterForDebug(this);
52 void InvalidationsMessageHandler::UpdateContent(const base::ListValue
* args
) {
54 logger_
->EmitContent();
57 void InvalidationsMessageHandler::OnUnregistration(
58 const base::DictionaryValue
& newRegistrationState
) {}
60 void InvalidationsMessageHandler::OnRegistration(
61 const base::DictionaryValue
& newRegistrationState
) {}
63 void InvalidationsMessageHandler::OnStateChange(
64 const syncer::InvalidatorState
& newState
) {
65 std::string
state(syncer::InvalidatorStateToString(newState
));
66 web_ui()->CallJavascriptFunction("chrome.invalidations.updateState",
67 base::StringValue(state
));
70 void InvalidationsMessageHandler::OnUpdateIds(
71 const base::DictionaryValue
& newIds
) {}
73 void InvalidationsMessageHandler::OnDebugMessage(
74 const base::DictionaryValue
& details
) {}
76 void InvalidationsMessageHandler::OnInvalidation(
77 const syncer::ObjectIdInvalidationMap
& newInvalidations
) {
78 scoped_ptr
<base::ListValue
> invalidationsList
= newInvalidations
.ToValue();
79 web_ui()->CallJavascriptFunction("chrome.invalidations.logInvalidations",