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 // |version| is the version of the available update and should be empty string 62 // when update is not available. 63 // |update_size| is the size of the available update in bytes and should be 0 64 // when update is not available. 65 // |message| is a message explaining a failure. 66 typedef base::Callback<void(Status status, 67 int progress, 68 bool rollback, 69 const std::string& version, 70 int64_t update_size, 71 const base::string16& message)> 72 StatusCallback; 73 74 // Used to show or hide the promote UI elements. Mac-only. 75 typedef base::Callback<void(PromotionState)> PromoteCallback; 76 ~VersionUpdater()77 virtual ~VersionUpdater() {} 78 79 // Sub-classes must implement this method to create the respective 80 // specialization. |web_contents| may be null, in which case any required UX 81 // (e.g., UAC to elevate on Windows) may not be associated with any existing 82 // browser windows. 83 static VersionUpdater* Create(content::WebContents* web_contents); 84 85 // Begins the update process by checking for update availability. 86 // |status_callback| is called for each status update. |promote_callback| 87 // (which is only used on the Mac) can be used to show or hide the promote UI 88 // elements. 89 virtual void CheckForUpdate(const StatusCallback& status_callback, 90 const PromoteCallback& promote_callback) = 0; 91 92 #if defined(OS_MACOSX) 93 // Make updates available for all users. 94 virtual void PromoteUpdater() const = 0; 95 #endif 96 97 #if defined(OS_CHROMEOS) 98 virtual void SetChannel(const std::string& channel, 99 bool is_powerwash_allowed) = 0; 100 virtual void GetChannel(bool get_current_channel, 101 const ChannelCallback& callback) = 0; 102 // Get the End of Life (Auto Update Expiration) Date. 103 virtual void GetEolInfo(EolInfoCallback callback) = 0; 104 105 // Sets a one time permission on a certain update in Update Engine. 106 // - update_version: the Chrome OS version we want to update to. 107 // - update_size: the size of that Chrome OS version in bytes. 108 // These two parameters are a failsafe to prevent downloading an update that 109 // the user didn't agree to. They should be set using the version and size we 110 // received from update engine when it broadcasts NEED_PERMISSION_TO_UPDATE. 111 // They are used by update engine to double-check with update server in case 112 // there's a new update available or a delta update becomes a full update with 113 // a larger size. 114 virtual void SetUpdateOverCellularOneTimePermission( 115 const StatusCallback& callback, 116 const std::string& update_version, 117 int64_t update_size) = 0; 118 #endif 119 }; 120 121 #endif // CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_H_ 122