OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" | 5 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 using chromeos::DBusThreadManager; | 30 using chromeos::DBusThreadManager; |
31 using chromeos::OwnerSettingsServiceChromeOS; | 31 using chromeos::OwnerSettingsServiceChromeOS; |
32 using chromeos::OwnerSettingsServiceChromeOSFactory; | 32 using chromeos::OwnerSettingsServiceChromeOSFactory; |
33 using chromeos::UpdateEngineClient; | 33 using chromeos::UpdateEngineClient; |
34 using chromeos::WizardController; | 34 using chromeos::WizardController; |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // Network status in the context of device update. | 38 // Network status in the context of device update. |
39 enum NetworkStatus { | 39 enum NetworkStatus { |
40 // It's allowed in device policy to use current network for update. | 40 // It's allowed to use current network for update. |
41 NETWORK_STATUS_ALLOWED = 0, | 41 NETWORK_STATUS_ALLOWED = 0, |
42 // It's disallowed in device policy to use current network for update. | 42 // It's disallowed to use current network for update. |
43 NETWORK_STATUS_DISALLOWED, | 43 NETWORK_STATUS_DISALLOWED, |
44 // Device is in offline state. | 44 // Device is in offline state. |
45 NETWORK_STATUS_OFFLINE | 45 NETWORK_STATUS_OFFLINE |
46 }; | 46 }; |
47 | 47 |
48 const bool kDefaultAutoUpdateDisabled = false; | 48 const bool kDefaultAutoUpdateDisabled = false; |
49 | 49 |
50 NetworkStatus GetNetworkStatus(const chromeos::NetworkState* network) { | 50 NetworkStatus GetNetworkStatus(bool interactive, |
51 const chromeos::NetworkState* network) { | |
51 if (!network || !network->IsConnectedState()) // Offline state. | 52 if (!network || !network->IsConnectedState()) // Offline state. |
52 return NETWORK_STATUS_OFFLINE; | 53 return NETWORK_STATUS_OFFLINE; |
53 // The connection type checking strategy must be the same as the one | 54 // The connection type checking strategy for non-cellular is the same as the |
54 // used in update engine. | 55 // one used in update engine. |
stevenjb
2017/05/22 22:57:32
The comment doesn't align very well with the logic
weidongg
2017/05/23 00:17:01
Ok, removed.
| |
55 if (network->type() == shill::kTypeBluetooth) | 56 if (network->type() == shill::kTypeBluetooth) |
56 return NETWORK_STATUS_DISALLOWED; | 57 return NETWORK_STATUS_DISALLOWED; |
57 // Allow updates over cellular by default in chrome, as update engine still | 58 // We leave the decision as to whether to allow updates over cellular up to |
58 // needs to check device policy and user preferences when checking for | 59 // update engine if the user is actively checking for updates and device |
59 // updates to decide whether to proceed to downloading. | 60 // policy is not set. |
stevenjb
2017/05/22 22:57:32
I think this comment just confuses things; we shou
weidongg
2017/05/23 00:17:00
Ok, removed
| |
61 if (network->type() == shill::kTypeCellular && | |
62 !help_utils_chromeos::IsUpdateOverCellularAllowed(interactive)) { | |
63 return NETWORK_STATUS_DISALLOWED; | |
64 } | |
60 return NETWORK_STATUS_ALLOWED; | 65 return NETWORK_STATUS_ALLOWED; |
61 } | 66 } |
62 | 67 |
63 // Returns true if auto-update is disabled by the system administrator. | 68 // Returns true if auto-update is disabled by the system administrator. |
64 bool IsAutoUpdateDisabled() { | 69 bool IsAutoUpdateDisabled() { |
65 bool update_disabled = kDefaultAutoUpdateDisabled; | 70 bool update_disabled = kDefaultAutoUpdateDisabled; |
66 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); | 71 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); |
67 if (!settings) | 72 if (!settings) |
68 return update_disabled; | 73 return update_disabled; |
69 const base::Value* update_disabled_value = | 74 const base::Value* update_disabled_value = |
70 settings->GetPref(chromeos::kUpdateDisabled); | 75 settings->GetPref(chromeos::kUpdateDisabled); |
71 if (update_disabled_value) | 76 if (update_disabled_value) |
72 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); | 77 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); |
73 return update_disabled; | 78 return update_disabled; |
74 } | 79 } |
75 | 80 |
76 // Returns whether an update is allowed. If not, it calls the callback with | 81 // Returns whether an update is allowed. If not, it calls the callback with |
77 // the appropriate status. | 82 // the appropriate status. |interactive| indicates whether the user is actively |
78 bool EnsureCanUpdate(const VersionUpdater::StatusCallback& callback) { | 83 // checking for updates. |
84 bool EnsureCanUpdate(bool interactive, | |
85 const VersionUpdater::StatusCallback& callback) { | |
79 if (IsAutoUpdateDisabled()) { | 86 if (IsAutoUpdateDisabled()) { |
80 callback.Run(VersionUpdater::DISABLED_BY_ADMIN, 0, std::string(), 0, | 87 callback.Run(VersionUpdater::DISABLED_BY_ADMIN, 0, std::string(), 0, |
81 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); | 88 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); |
82 return false; | 89 return false; |
83 } | 90 } |
84 | 91 |
85 chromeos::NetworkStateHandler* network_state_handler = | 92 chromeos::NetworkStateHandler* network_state_handler = |
86 chromeos::NetworkHandler::Get()->network_state_handler(); | 93 chromeos::NetworkHandler::Get()->network_state_handler(); |
87 const chromeos::NetworkState* network = | 94 const chromeos::NetworkState* network = |
88 network_state_handler->DefaultNetwork(); | 95 network_state_handler->DefaultNetwork(); |
89 | 96 |
90 // Don't allow an update if we're currently offline or connected | 97 // Don't allow an update if we're currently offline or connected |
91 // to a network for which updates are disallowed. | 98 // to a network for which updates are disallowed. |
92 NetworkStatus status = GetNetworkStatus(network); | 99 NetworkStatus status = GetNetworkStatus(interactive, network); |
93 if (status == NETWORK_STATUS_OFFLINE) { | 100 if (status == NETWORK_STATUS_OFFLINE) { |
94 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, std::string(), 0, | 101 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, std::string(), 0, |
95 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); | 102 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); |
96 return false; | 103 return false; |
97 } else if (status == NETWORK_STATUS_DISALLOWED) { | 104 } else if (status == NETWORK_STATUS_DISALLOWED) { |
98 base::string16 message = | 105 base::string16 message = |
99 l10n_util::GetStringFUTF16( | 106 l10n_util::GetStringFUTF16( |
100 IDS_UPGRADE_DISALLOWED, | 107 IDS_UPGRADE_DISALLOWED, |
101 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); | 108 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); |
102 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, | 109 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, |
103 std::string(), 0, message); | 110 std::string(), 0, message); |
104 return false; | 111 return false; |
105 } | 112 } |
106 | 113 |
107 return true; | 114 return true; |
108 } | 115 } |
109 | 116 |
110 } // namespace | 117 } // namespace |
111 | 118 |
112 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { | 119 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { |
113 return new VersionUpdaterCros(web_contents); | 120 return new VersionUpdaterCros(web_contents); |
114 } | 121 } |
115 | 122 |
116 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { | 123 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { |
117 callback_ = callback; | 124 callback_ = callback; |
118 | 125 |
119 if (!EnsureCanUpdate(callback)) | 126 // User is not actively checking for updates. |
127 if (!EnsureCanUpdate(false /* interactive */, callback)) | |
120 return; | 128 return; |
121 | 129 |
122 UpdateEngineClient* update_engine_client = | 130 UpdateEngineClient* update_engine_client = |
123 DBusThreadManager::Get()->GetUpdateEngineClient(); | 131 DBusThreadManager::Get()->GetUpdateEngineClient(); |
124 if (!update_engine_client->HasObserver(this)) | 132 if (!update_engine_client->HasObserver(this)) |
125 update_engine_client->AddObserver(this); | 133 update_engine_client->AddObserver(this); |
126 | 134 |
127 this->UpdateStatusChanged( | 135 this->UpdateStatusChanged( |
128 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus()); | 136 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus()); |
129 } | 137 } |
130 | 138 |
131 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback, | 139 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback, |
132 const PromoteCallback&) { | 140 const PromoteCallback&) { |
133 callback_ = callback; | 141 callback_ = callback; |
134 | 142 |
135 if (!EnsureCanUpdate(callback)) | 143 // User is actively checking for updates. |
144 if (!EnsureCanUpdate(true /* interactive */, callback)) | |
136 return; | 145 return; |
137 | 146 |
138 UpdateEngineClient* update_engine_client = | 147 UpdateEngineClient* update_engine_client = |
139 DBusThreadManager::Get()->GetUpdateEngineClient(); | 148 DBusThreadManager::Get()->GetUpdateEngineClient(); |
140 if (!update_engine_client->HasObserver(this)) | 149 if (!update_engine_client->HasObserver(this)) |
141 update_engine_client->AddObserver(this); | 150 update_engine_client->AddObserver(this); |
142 | 151 |
143 if (update_engine_client->GetLastStatus().status != | 152 if (update_engine_client->GetLastStatus().status != |
144 UpdateEngineClient::UPDATE_STATUS_IDLE) { | 153 UpdateEngineClient::UPDATE_STATUS_IDLE) { |
145 check_for_update_when_idle_ = true; | 154 check_for_update_when_idle_ = true; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 } | 311 } |
303 } | 312 } |
304 | 313 |
305 void VersionUpdaterCros::OnUpdateCheck( | 314 void VersionUpdaterCros::OnUpdateCheck( |
306 UpdateEngineClient::UpdateCheckResult result) { | 315 UpdateEngineClient::UpdateCheckResult result) { |
307 // If version updating is not implemented, this binary is the most up-to-date | 316 // If version updating is not implemented, this binary is the most up-to-date |
308 // possible with respect to automatic updating. | 317 // possible with respect to automatic updating. |
309 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) | 318 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) |
310 callback_.Run(UPDATED, 0, std::string(), 0, base::string16()); | 319 callback_.Run(UPDATED, 0, std::string(), 0, base::string16()); |
311 } | 320 } |
OLD | NEW |