Skip to content

Commit

Permalink
Cryptohome: Notify about error in async calls if cryptohome is not re…
Browse files Browse the repository at this point in the history
…ady yet.

BUG=451148

Review URL: https://codereview.chromium.org/880303003

Cr-Commit-Position: refs/heads/master@{#313687}
  • Loading branch information
antrim authored and Commit bot committed Jan 29, 2015
1 parent 86f137d commit 7df6f9f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions chrome/browser/chromeos/login/existing_user_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ void ExistingUserController::OnAuthFailure(const AuthFailure& failure) {
ShowTPMError();
} else if (!online_succeeded_for_.empty()) {
ShowGaiaPasswordChanged(online_succeeded_for_);
} else if (last_login_attempt_username_ == chromeos::login::kGuestUserName) {
// Show no errors, just re-enable input.
login_display_->ClearAndEnablePassword();
StartPublicSessionAutoLoginTimer();
} else {
// Check networking after trying to login in case user is
// cached locally or the local admin account.
Expand Down
16 changes: 15 additions & 1 deletion chromeos/cryptohome/async_method_caller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,17 @@ class AsyncMethodCallerImpl : public AsyncMethodCaller {
base::Bind(it->second.data_callback, return_status, return_data));
data_callback_map_.erase(it);
}

// Registers a callback which is called when the result for AsyncXXX is ready.
void RegisterAsyncCallback(
Callback callback, const char* error, int async_id) {
if (async_id == chromeos::CryptohomeClient::kNotReadyAsyncId) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(callback,
false, // return status
cryptohome::MOUNT_ERROR_FATAL));
return;
}

if (async_id == 0) {
LOG(ERROR) << error;
return;
Expand All @@ -325,6 +332,13 @@ class AsyncMethodCallerImpl : public AsyncMethodCaller {
// Registers a callback which is called when the result for AsyncXXX is ready.
void RegisterAsyncDataCallback(
DataCallback callback, const char* error, int async_id) {
if (async_id == chromeos::CryptohomeClient::kNotReadyAsyncId) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(callback,
false, // return status
std::string()));
return;
}
if (async_id == 0) {
LOG(ERROR) << error;
return;
Expand Down
6 changes: 5 additions & 1 deletion chromeos/dbus/cryptohome_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace chromeos {

const int CryptohomeClient::kNotReadyAsyncId = -1;

namespace {

// This suffix is appended to user_id to get hash in stub implementation:
Expand Down Expand Up @@ -882,8 +884,10 @@ class CryptohomeClientImpl : public CryptohomeClient {
// Handles the result of AsyncXXX methods.
void OnAsyncMethodCall(const AsyncMethodCallback& callback,
dbus::Response* response) {
if (!response)
if (!response) {
callback.Run(kNotReadyAsyncId);
return;
}
dbus::MessageReader reader(response);
int async_id = 0;
if (!reader.PopInt32(&async_id)) {
Expand Down
4 changes: 4 additions & 0 deletions chromeos/dbus/cryptohome_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace chromeos {
// initializes the DBusThreadManager instance.
class CHROMEOS_EXPORT CryptohomeClient : public DBusClient {
public:
// Constant that will be passed to AsyncMethodCallback to indicate that
// cryptohome is not ready yet.
static const int kNotReadyAsyncId;

// A callback to handle AsyncCallStatus signals.
typedef base::Callback<void(int async_id,
bool return_status,
Expand Down

0 comments on commit 7df6f9f

Please sign in to comment.