Add ability to gather metrics to BubbleManager.
[chromium-blink-merge.git] / chrome / browser / ui / webui / sync_internals_message_handler.h
blobaaf5a456291d5a86389afe8f1fbe05d0c860b555
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_
8 #include <string>
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 "components/sync_driver/protocol_event_observer.h"
16 #include "components/sync_driver/sync_service_observer.h"
17 #include "content/public/browser/web_ui_message_handler.h"
18 #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
19 #include "sync/js/js_controller.h"
20 #include "sync/js/js_event_handler.h"
22 class ProfileSyncService;
24 // The implementation for the chrome://sync-internals page.
25 class SyncInternalsMessageHandler : public content::WebUIMessageHandler,
26 public syncer::JsEventHandler,
27 public sync_driver::SyncServiceObserver,
28 public browser_sync::ProtocolEventObserver,
29 public syncer::TypeDebugInfoObserver {
30 public:
31 SyncInternalsMessageHandler();
32 ~SyncInternalsMessageHandler() override;
34 void RegisterMessages() override;
36 // Sets up observers to receive events and forward them to the UI.
37 void HandleRegisterForEvents(const base::ListValue* args);
39 // Sets up observers to receive per-type counters and forward them to the UI.
40 void HandleRegisterForPerTypeCounters(const base::ListValue* args);
42 // Fires an event to send updated info back to the page.
43 void HandleRequestUpdatedAboutInfo(const base::ListValue* args);
45 // Fires and event to send the list of types back to the page.
46 void HandleRequestListOfTypes(const base::ListValue* args);
48 // Handler for getAllNodes message. Needs a |request_id| argument.
49 void HandleGetAllNodes(const base::ListValue* args);
51 // syncer::JsEventHandler implementation.
52 void HandleJsEvent(const std::string& name,
53 const syncer::JsEventDetails& details) override;
55 // Callback used in GetAllNodes.
56 void OnReceivedAllNodes(int request_id, scoped_ptr<base::ListValue> nodes);
58 // sync_driver::SyncServiceObserver implementation.
59 void OnStateChanged() override;
61 // ProtocolEventObserver implementation.
62 void OnProtocolEvent(const syncer::ProtocolEvent& e) override;
64 // TypeDebugInfoObserver implementation.
65 void OnCommitCountersUpdated(syncer::ModelType type,
66 const syncer::CommitCounters& counters) override;
67 void OnUpdateCountersUpdated(syncer::ModelType type,
68 const syncer::UpdateCounters& counters) override;
69 void OnStatusCountersUpdated(syncer::ModelType type,
70 const syncer::StatusCounters& counters) override;
72 // Helper to emit counter updates.
74 // Used in implementation of On*CounterUpdated methods. Emits the given
75 // dictionary value with additional data to specify the model type and
76 // counter type.
77 void EmitCounterUpdate(syncer::ModelType type,
78 const std::string& counter_type,
79 scoped_ptr<base::DictionaryValue> value);
81 private:
82 // Fetches updated aboutInfo and sends it to the page in the form of an
83 // onAboutInfoUpdated event.
84 void SendAboutInfo();
86 ProfileSyncService* GetProfileSyncService();
88 base::WeakPtr<syncer::JsController> js_controller_;
90 // A flag used to prevent double-registration with ProfileSyncService.
91 bool is_registered_;
93 // A flag used to prevent double-registration as TypeDebugInfoObserver with
94 // ProfileSyncService.
95 bool is_registered_for_counters_;
97 base::WeakPtrFactory<SyncInternalsMessageHandler> weak_ptr_factory_;
99 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler);
102 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_