Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / ntp / new_tab_page_sync_handler.h
blob9fa8864301a492c4c10fb706bb8e31dec5da76ad
1 // Copyright (c) 2011 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_NTP_NEW_TAB_PAGE_SYNC_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_SYNC_HANDLER_H_
8 #include <string>
10 #include "base/prefs/pref_change_registrar.h"
11 #include "chrome/browser/sync/profile_sync_service.h"
12 #include "chrome/browser/sync/sync_ui_util.h"
13 #include "content/public/browser/web_ui_message_handler.h"
15 namespace base {
16 class ListValue;
19 // Sends sync-state changes to the New Tab Page for UI updating and forwards
20 // link clicks on the page to the sync service.
21 class NewTabPageSyncHandler : public content::WebUIMessageHandler,
22 public sync_driver::SyncServiceObserver {
23 public:
24 NewTabPageSyncHandler();
25 ~NewTabPageSyncHandler() override;
27 // WebUIMessageHandler implementation.
28 void RegisterMessages() override;
30 // Callback for "GetSyncMessage".
31 void HandleGetSyncMessage(const base::ListValue* args);
32 // Callback for "SyncLinkClicked".
33 void HandleSyncLinkClicked(const base::ListValue* args);
35 // sync_driver::SyncServiceObserver
36 void OnStateChanged() override;
38 void OnSigninAllowedPrefChange();
40 private:
41 friend class MockNewTabPageSyncHandler;
42 FRIEND_TEST_ALL_PREFIXES(NewTabPageSyncHandlerBrowserTest,
43 ChangeSigninAllowedToFalse);
45 enum MessageType {
46 HIDE,
47 SYNC_ERROR,
48 SYNC_PROMO
50 // Helper to invoke the |syncMessageChanged| JS function on the new tab page.
51 virtual void SendSyncMessageToPage(MessageType type,
52 std::string msg, std::string linktext);
54 // Helper to query the sync service and figure out what to send to
55 // the page, and send it via SendSyncMessageToPage.
56 // NOTE: precondition: sync must be enabled.
57 void BuildAndSendSyncStatus();
59 // Helper to send a message to the NNTP which hides the sync section.
60 void HideSyncStatusSection();
62 // Helper to convert from a sync status message type to an NTP specific one.
63 static MessageType FromSyncStatusMessageType(
64 sync_ui_util::MessageType type);
66 // Cached pointer to ProfileSyncService.
67 ProfileSyncService* sync_service_;
69 PrefChangeRegistrar profile_pref_registrar_;
71 // Used to make sure we don't register ourselves twice if the user refreshes
72 // the new tab page.
73 bool waiting_for_initial_page_load_;
75 DISALLOW_COPY_AND_ASSIGN(NewTabPageSyncHandler);
78 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_SYNC_HANDLER_H_