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. 4 5 #ifndef CHROME_BROWSER_UI_WEBUI_NEW_TAB_PAGE_SYNC_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_NEW_TAB_PAGE_SYNC_HANDLER_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "chrome/browser/sync/profile_sync_service.h" 12 #include "chrome/browser/sync/sync_ui_util.h" 13 #include "content/browser/webui/web_ui.h" 14 15 class ListValue; 16 17 // Sends sync-state changes to the New Tab Page for UI updating and forwards 18 // link clicks on the page to the sync service. 19 class NewTabPageSyncHandler : public WebUIMessageHandler, 20 public ProfileSyncServiceObserver { 21 public: 22 NewTabPageSyncHandler(); 23 virtual ~NewTabPageSyncHandler(); 24 25 // WebUIMessageHandler implementation. 26 virtual WebUIMessageHandler* Attach(WebUI* web_ui); 27 virtual void RegisterMessages(); 28 29 // Callback for "GetSyncMessage". 30 void HandleGetSyncMessage(const ListValue* args); 31 // Callback for "SyncLinkClicked". 32 void HandleSyncLinkClicked(const ListValue* args); 33 34 // ProfileSyncServiceObserver 35 virtual void OnStateChanged(); 36 37 private: 38 enum MessageType { 39 HIDE, 40 SYNC_ERROR, 41 SYNC_PROMO 42 }; 43 // Helper to invoke the |syncMessageChanged| JS function on the new tab page. 44 void SendSyncMessageToPage(MessageType type, 45 std::string msg, std::string linktext); 46 47 // Helper to query the sync service and figure out what to send to 48 // the page, and send it via SendSyncMessageToPage. 49 // NOTE: precondition: sync must be enabled. 50 void BuildAndSendSyncStatus(); 51 52 // Helper to send a message to the NNTP which hides the sync section. 53 void HideSyncStatusSection(); 54 55 // Helper to convert from a sync status message type to an NTP specific one. 56 static MessageType FromSyncStatusMessageType( 57 sync_ui_util::MessageType type); 58 59 // Cached pointer to ProfileSyncService. 60 ProfileSyncService* sync_service_; 61 62 // Used to make sure we don't register ourselves twice if the user refreshes 63 // the new tab page. 64 bool waiting_for_initial_page_load_; 65 66 DISALLOW_COPY_AND_ASSIGN(NewTabPageSyncHandler); 67 }; 68 69 #endif // CHROME_BROWSER_UI_WEBUI_NEW_TAB_PAGE_SYNC_HANDLER_H_ 70