1// Copyright (c) 2012 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_HELP_HELP_HANDLER_H_ 6#define CHROME_BROWSER_UI_WEBUI_HELP_HELP_HANDLER_H_ 7 8#include <string> 9 10#include "base/compiler_specific.h" 11#include "base/memory/weak_ptr.h" 12#include "chrome/browser/ui/webui/help/version_updater.h" 13#include "content/public/browser/notification_observer.h" 14#include "content/public/browser/notification_registrar.h" 15#include "content/public/browser/web_ui_message_handler.h" 16 17#if defined(OS_CHROMEOS) 18#include "chrome/browser/chromeos/version_loader.h" 19#endif // defined(OS_CHROMEOS) 20 21namespace content { 22class WebUIDataSource; 23} 24 25// WebUI message handler for the help page. 26class HelpHandler : public content::WebUIMessageHandler, 27 public content::NotificationObserver { 28 public: 29 HelpHandler(); 30 virtual ~HelpHandler(); 31 32 // WebUIMessageHandler implementation. 33 virtual void RegisterMessages() OVERRIDE; 34 35 // Fills |source| with string values for the UI. 36 void GetLocalizedValues(content::WebUIDataSource* source); 37 38 // NotificationObserver implementation. 39 virtual void Observe(int type, const content::NotificationSource& source, 40 const content::NotificationDetails& details) OVERRIDE; 41 42 private: 43 // Initializes querying values for the page. 44 void OnPageLoaded(const base::ListValue* args); 45 46#if defined(OS_MACOSX) 47 // Promotes the updater for all users. 48 void PromoteUpdater(const base::ListValue* args); 49#endif 50 51 // Relaunches the browser. |args| must be empty. 52 void RelaunchNow(const base::ListValue* args); 53 54 // Opens the feedback dialog. |args| must be empty. 55 void OpenFeedbackDialog(const base::ListValue* args); 56 57 // Opens the help page. |args| must be empty. 58 void OpenHelpPage(const base::ListValue* args); 59 60#if defined(OS_CHROMEOS) 61 // Sets the release track version. 62 void SetChannel(const base::ListValue* args); 63 64 // Performs relaunch and powerwash. 65 void RelaunchAndPowerwash(const base::ListValue* args); 66#endif 67 68 // Callback method which forwards status updates to the page. 69 void SetUpdateStatus(VersionUpdater::Status status, int progress, 70 const base::string16& fail_message); 71 72#if defined(OS_MACOSX) 73 // Callback method which forwards promotion state to the page. 74 void SetPromotionState(VersionUpdater::PromotionState state); 75#endif 76 77#if defined(OS_CHROMEOS) 78 // Callbacks from VersionLoader. 79 void OnOSVersion(const std::string& version); 80 void OnOSFirmware(const std::string& firmware); 81 void OnCurrentChannel(const std::string& channel); 82 void OnTargetChannel(const std::string& channel); 83#endif 84 85 // Specialized instance of the VersionUpdater used to update the browser. 86 scoped_ptr<VersionUpdater> version_updater_; 87 88 // Used to observe notifications. 89 content::NotificationRegistrar registrar_; 90 91#if defined(OS_CHROMEOS) 92 // Handles asynchronously loading the CrOS version info. 93 chromeos::VersionLoader loader_; 94 95 // Used to request the version. 96 base::CancelableTaskTracker tracker_; 97#endif // defined(OS_CHROMEOS) 98 99 // Used for callbacks. 100 base::WeakPtrFactory<HelpHandler> weak_factory_; 101 102 DISALLOW_COPY_AND_ASSIGN(HelpHandler); 103}; 104 105#endif // CHROME_BROWSER_UI_WEBUI_HELP_HELP_HANDLER_H_ 106