Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1221)

Side by Side Diff: chrome/browser/ui/webui/help/version_updater_chromeos.cc

Issue 476983002: About page should not automatically trigger OS updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and formatting Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); 65 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get();
66 if (!settings) 66 if (!settings)
67 return update_disabled; 67 return update_disabled;
68 const base::Value* update_disabled_value = 68 const base::Value* update_disabled_value =
69 settings->GetPref(chromeos::kUpdateDisabled); 69 settings->GetPref(chromeos::kUpdateDisabled);
70 if (update_disabled_value) 70 if (update_disabled_value)
71 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); 71 CHECK(update_disabled_value->GetAsBoolean(&update_disabled));
72 return update_disabled; 72 return update_disabled;
73 } 73 }
74 74
75 } // namespace 75 // Returns whether an update is allowed. If not, it calls the callback with
76 76 // the appropriate status.
77 VersionUpdater* VersionUpdater::Create() { 77 bool EnsureCanUpdate(const VersionUpdater::StatusCallback& callback) {
78 return new VersionUpdaterCros;
79 }
80
81 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) {
82 callback_ = callback;
83
84 if (IsAutoUpdateDisabled()) { 78 if (IsAutoUpdateDisabled()) {
85 callback_.Run(FAILED, 0, 79 callback.Run(VersionUpdater::FAILED, 0,
86 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); 80 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY));
87 return; 81 return false;
88 } 82 }
89 83
90 chromeos::NetworkStateHandler* network_state_handler = 84 chromeos::NetworkStateHandler* network_state_handler =
91 chromeos::NetworkHandler::Get()->network_state_handler(); 85 chromeos::NetworkHandler::Get()->network_state_handler();
92 const chromeos::NetworkState* network = 86 const chromeos::NetworkState* network =
93 network_state_handler->DefaultNetwork(); 87 network_state_handler->DefaultNetwork();
94 88
95 // Don't proceed to update if we're currently offline or connected 89 // Don't allow an update if we're currently offline or connected
96 // to a network for which updates are disallowed. 90 // to a network for which updates are disallowed.
97 NetworkStatus status = GetNetworkStatus(network); 91 NetworkStatus status = GetNetworkStatus(network);
98 if (status == NETWORK_STATUS_OFFLINE) { 92 if (status == NETWORK_STATUS_OFFLINE) {
99 callback_.Run(FAILED_OFFLINE, 0, 93 callback.Run(VersionUpdater::FAILED_OFFLINE, 0,
100 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); 94 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE));
101 return; 95 return false;
102 } else if (status == NETWORK_STATUS_DISALLOWED) { 96 } else if (status == NETWORK_STATUS_DISALLOWED) {
103 base::string16 message = 97 base::string16 message =
104 l10n_util::GetStringFUTF16( 98 l10n_util::GetStringFUTF16(
105 IDS_UPGRADE_DISALLOWED, 99 IDS_UPGRADE_DISALLOWED,
106 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); 100 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type()));
107 callback_.Run(FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); 101 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message);
102 return false;
103 }
104
105 return true;
106 }
107
108 } // namespace
109
110 VersionUpdater* VersionUpdater::Create() {
111 return new VersionUpdaterCros;
112 }
113
114 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) {
115 callback_ = callback;
116 if (!EnsureCanUpdate(callback))
108 return; 117 return;
109 }
110 118
111 UpdateEngineClient* update_engine_client = 119 UpdateEngineClient* update_engine_client =
112 DBusThreadManager::Get()->GetUpdateEngineClient(); 120 DBusThreadManager::Get()->GetUpdateEngineClient();
113 update_engine_client->AddObserver(this); 121 if (!update_engine_client->HasObserver(this))
122 update_engine_client->AddObserver(this);
123
124 this->UpdateStatusChanged(
125 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus());
126 }
127
128 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) {
129 callback_ = callback;
130
131 if (!EnsureCanUpdate(callback))
132 return;
133
134 UpdateEngineClient* update_engine_client =
135 DBusThreadManager::Get()->GetUpdateEngineClient();
136 if (!update_engine_client->HasObserver(this))
137 update_engine_client->AddObserver(this);
114 138
115 // Make sure that libcros is loaded and OOBE is complete. 139 // Make sure that libcros is loaded and OOBE is complete.
116 if (!WizardController::default_controller() || 140 if (!WizardController::default_controller() ||
117 chromeos::StartupUtils::IsDeviceRegistered()) { 141 chromeos::StartupUtils::IsDeviceRegistered()) {
118 update_engine_client->RequestUpdateCheck( 142 update_engine_client->RequestUpdateCheck(
119 base::Bind(&VersionUpdaterCros::OnUpdateCheck, 143 base::Bind(&VersionUpdaterCros::OnUpdateCheck,
120 weak_ptr_factory_.GetWeakPtr())); 144 weak_ptr_factory_.GetWeakPtr()));
121 } 145 }
122 } 146 }
123 147
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 last_operation_ = status.status; 231 last_operation_ = status.status;
208 } 232 }
209 233
210 void VersionUpdaterCros::OnUpdateCheck( 234 void VersionUpdaterCros::OnUpdateCheck(
211 UpdateEngineClient::UpdateCheckResult result) { 235 UpdateEngineClient::UpdateCheckResult result) {
212 // If version updating is not implemented, this binary is the most up-to-date 236 // If version updating is not implemented, this binary is the most up-to-date
213 // possible with respect to automatic updating. 237 // possible with respect to automatic updating.
214 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) 238 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED)
215 callback_.Run(UPDATED, 0, base::string16()); 239 callback_.Run(UPDATED, 0, base::string16());
216 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698