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