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 #ifndef CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/scoped_observer.h"
14 #include "base/values.h"
15 #include "chrome/browser/sync/profile_sync_service_observer.h"
16 #include "chrome/browser/sync/protocol_event_observer.h"
17 #include "content/public/browser/web_ui_message_handler.h"
18 #include "sync/js/js_controller.h"
19 #include "sync/js/js_event_handler.h"
20 #include "sync/js/js_reply_handler.h"
22 class ProfileSyncService
;
24 // The implementation for the chrome://sync-internals page.
25 class SyncInternalsMessageHandler
26 : public content::WebUIMessageHandler
,
27 public syncer::JsEventHandler
,
28 public syncer::JsReplyHandler
,
29 public ProfileSyncServiceObserver
,
30 public browser_sync::ProtocolEventObserver
{
32 SyncInternalsMessageHandler();
33 virtual ~SyncInternalsMessageHandler();
35 virtual void RegisterMessages() OVERRIDE
;
37 // Forwards requests to the JsController.
38 void ForwardToJsController(const std::string
& name
, const base::ListValue
*);
40 // Fires an event to send updated info back to the page.
41 void HandleRequestUpdatedAboutInfo(const base::ListValue
* args
);
43 // Fires and event to send the list of types back to the page.
44 void HandleRequestListOfTypes(const base::ListValue
* args
);
46 // syncer::JsEventHandler implementation.
47 virtual void HandleJsEvent(
48 const std::string
& name
,
49 const syncer::JsEventDetails
& details
) OVERRIDE
;
51 // syncer::JsReplyHandler implementation.
52 virtual void HandleJsReply(
53 const std::string
& name
,
54 const syncer::JsArgList
& args
) OVERRIDE
;
56 // ProfileSyncServiceObserver implementation.
57 virtual void OnStateChanged() OVERRIDE
;
59 // ProtocolEventObserver implementation.
60 virtual void OnProtocolEvent(const syncer::ProtocolEvent
& e
) OVERRIDE
;
63 // Helper function to register JsController function callbacks.
64 void RegisterJsControllerCallback(const std::string
& name
);
66 // Fetches updated aboutInfo and sends it to the page in the form of an
67 // onAboutInfoUpdated event.
70 ProfileSyncService
* GetProfileSyncService();
72 base::WeakPtr
<syncer::JsController
> js_controller_
;
73 base::WeakPtrFactory
<SyncInternalsMessageHandler
> weak_ptr_factory_
;
75 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler
);
78 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_