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