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"
21 class ProfileSyncService
;
23 // The implementation for the chrome://sync-internals page.
24 class SyncInternalsMessageHandler
25 : public content::WebUIMessageHandler
,
26 public syncer::JsEventHandler
,
27 public ProfileSyncServiceObserver
,
28 public browser_sync::ProtocolEventObserver
{
30 SyncInternalsMessageHandler();
31 virtual ~SyncInternalsMessageHandler();
33 virtual void RegisterMessages() OVERRIDE
;
35 // Sets up observers to receive events and forward them to the UI.
36 void HandleRegisterForEvents(const base::ListValue
* args
);
38 // Fires an event to send updated info back to the page.
39 void HandleRequestUpdatedAboutInfo(const base::ListValue
* args
);
41 // Fires and event to send the list of types back to the page.
42 void HandleRequestListOfTypes(const base::ListValue
* args
);
44 // Handler for getAllNodes message. Needs a |request_id| argument.
45 void HandleGetAllNodes(const base::ListValue
* args
);
47 // syncer::JsEventHandler implementation.
48 virtual void HandleJsEvent(
49 const std::string
& name
,
50 const syncer::JsEventDetails
& details
) OVERRIDE
;
52 // Callback used in GetAllNodes.
53 void OnReceivedAllNodes(int request_id
, scoped_ptr
<base::ListValue
> nodes
);
55 // ProfileSyncServiceObserver implementation.
56 virtual void OnStateChanged() OVERRIDE
;
58 // ProtocolEventObserver implementation.
59 virtual void OnProtocolEvent(const syncer::ProtocolEvent
& e
) OVERRIDE
;
62 // Fetches updated aboutInfo and sends it to the page in the form of an
63 // onAboutInfoUpdated event.
66 ProfileSyncService
* GetProfileSyncService();
68 base::WeakPtr
<syncer::JsController
> js_controller_
;
70 // A flag used to prevent double-registration with ProfileSyncService.
73 base::WeakPtrFactory
<SyncInternalsMessageHandler
> weak_ptr_factory_
;
75 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler
);
78 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_