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_VERSION_UPDATER_H_
6 #define CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_H_
7 
8 #include <string>
9 
10 #include "base/callback.h"
11 #include "base/strings/string16.h"
12 #include "build/build_config.h"
13 
14 #if defined(OS_CHROMEOS)
15 #include "chromeos/dbus/update_engine_client.h"
16 #include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h"
17 #endif  // defined(OS_CHROMEOS)
18 
19 namespace content {
20 class WebContents;
21 }
22 
23 // Interface implemented to expose per-platform updating functionality.
24 class VersionUpdater {
25  public:
26   // Update process state machine.
27   enum Status {
28     CHECKING,
29     NEED_PERMISSION_TO_UPDATE,
30     UPDATING,
31     NEARLY_UPDATED,
32     UPDATED,
33     FAILED,
34     FAILED_OFFLINE,
35     FAILED_CONNECTION_TYPE_DISALLOWED,
36     DISABLED,
37     DISABLED_BY_ADMIN
38   };
39 
40   // Promotion state (Mac-only).
41   enum PromotionState {
42     PROMOTE_HIDDEN,
43     PROMOTE_ENABLED,
44     PROMOTE_DISABLED,
45     PROMOTED,
46   };
47 
48   // TODO(jhawkins): Use a delegate interface instead of multiple callback
49   // types.
50 #if defined(OS_CHROMEOS)
51   typedef base::Callback<void(const std::string&)> ChannelCallback;
52   using EolInfoCallback =
53       base::OnceCallback<void(chromeos::UpdateEngineClient::EolInfo eol_info)>;
54 #endif
55 
56   // Used to update the client of status changes.
57   // |status| is the current state of the update.
58   // |progress| should only be non-zero for the UPDATING state.
59   // |rollback| indicates whether the update is actually a rollback, which
60   //     requires wiping the device upon reboot.
61   // |powerwash| indicates whether the device will be wiped on reboot.
62   // |version| is the version of the available update and should be empty string
63   //     when update is not available.
64   // |update_size| is the size of the available update in bytes and should be 0
65   //     when update is not available.
66   // |message| is a message explaining a failure.
67   typedef base::Callback<void(Status status,
68                               int progress,
69                               bool rollback,
70                               bool powerwash,
71                               const std::string& version,
72                               int64_t update_size,
73                               const base::string16& message)>
74       StatusCallback;
75 
76   // Used to show or hide the promote UI elements. Mac-only.
77   typedef base::Callback<void(PromotionState)> PromoteCallback;
78 
~VersionUpdater()79   virtual ~VersionUpdater() {}
80 
81   // Sub-classes must implement this method to create the respective
82   // specialization. |web_contents| may be null, in which case any required UX
83   // (e.g., UAC to elevate on Windows) may not be associated with any existing
84   // browser windows.
85   static VersionUpdater* Create(content::WebContents* web_contents);
86 
87   // Begins the update process by checking for update availability.
88   // |status_callback| is called for each status update. |promote_callback|
89   // (which is only used on the Mac) can be used to show or hide the promote UI
90   // elements.
91   virtual void CheckForUpdate(const StatusCallback& status_callback,
92                               const PromoteCallback& promote_callback) = 0;
93 
94 #if defined(OS_MAC)
95   // Make updates available for all users.
96   virtual void PromoteUpdater() const = 0;
97 #endif
98 
99 #if defined(OS_CHROMEOS)
100   virtual void SetChannel(const std::string& channel,
101                           bool is_powerwash_allowed) = 0;
102   virtual void GetChannel(bool get_current_channel,
103                           const ChannelCallback& callback) = 0;
104   // Get the End of Life (Auto Update Expiration) Date.
105   virtual void GetEolInfo(EolInfoCallback callback) = 0;
106 
107   // Sets a one time permission on a certain update in Update Engine.
108   // - update_version: the Chrome OS version we want to update to.
109   // - update_size: the size of that Chrome OS version in bytes.
110   // These two parameters are a failsafe to prevent downloading an update that
111   // the user didn't agree to. They should be set using the version and size we
112   // received from update engine when it broadcasts NEED_PERMISSION_TO_UPDATE.
113   // They are used by update engine to double-check with update server in case
114   // there's a new update available or a delta update becomes a full update with
115   // a larger size.
116   virtual void SetUpdateOverCellularOneTimePermission(
117       const StatusCallback& callback,
118       const std::string& update_version,
119       int64_t update_size) = 0;
120 #endif
121 };
122 
123 #endif  // CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_H_
124