NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / invalidations_message_handler.cc
blob6a55ec56893dd1a5aa1edc5c9702df7a6ad788ad
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"
7 #include "base/bind.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
18 namespace syncer {
19 class ObjectIdInvalidationMap;
20 } // namespace syncer
22 InvalidationsMessageHandler::InvalidationsMessageHandler()
23 : logger_(NULL), isRegistered(false) {}
25 InvalidationsMessageHandler::~InvalidationsMessageHandler() {
26 if (logger_)
27 logger_->UnregisterForDebug(this);
30 void InvalidationsMessageHandler::RegisterMessages() {
31 web_ui()->RegisterMessageCallback(
32 "doneLoading",
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();
44 if (logger_) {
45 logger_->RegisterForDebug(this);
46 isRegistered = true;
49 UpdateContent(args);
52 void InvalidationsMessageHandler::UpdateContent(const base::ListValue* args) {
53 if (logger_)
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",
80 *invalidationsList);