Skip to content

Commit

Permalink
Wire easy unlock settings UI
Browse files Browse the repository at this point in the history
- Add API to get/set/clear the pairing info into user prefs;
- Add an onTurnFlowFinished event so that the app can clear its state;
- Extend EasyUnlockService to store pairing info and provide
  turn-off flow support;
- Update settings UI to trigger turn off flow and observe
  the turn-off flow status to show pending/error or dismiss when done;
- Add EasyUnlockToggleFlow to wrap api calls to server;
- Update OAuth2ApiFlow to support application/json content-type and
  handle 204 as success;

BUG=397356,394640

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

Cr-Commit-Position: refs/heads/master@{#290019}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290019 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
xiyuan@chromium.org committed Aug 15, 2014
1 parent 648f811 commit 7c37d21
Show file tree
Hide file tree
Showing 20 changed files with 956 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,103 @@ bool EasyUnlockPrivateUpdateScreenlockStateFunction::RunSync() {
return false;
}

EasyUnlockPrivateSetPermitAccessFunction::
EasyUnlockPrivateSetPermitAccessFunction() {
}

EasyUnlockPrivateSetPermitAccessFunction::
~EasyUnlockPrivateSetPermitAccessFunction() {
}

bool EasyUnlockPrivateSetPermitAccessFunction::RunSync() {
scoped_ptr<easy_unlock_private::SetPermitAccess::Params> params(
easy_unlock_private::SetPermitAccess::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

Profile* profile = Profile::FromBrowserContext(browser_context());
EasyUnlockService::Get(profile)
->SetPermitAccess(*params->permit_access.ToValue());

return true;
}

EasyUnlockPrivateGetPermitAccessFunction::
EasyUnlockPrivateGetPermitAccessFunction() {
}

EasyUnlockPrivateGetPermitAccessFunction::
~EasyUnlockPrivateGetPermitAccessFunction() {
}

bool EasyUnlockPrivateGetPermitAccessFunction::RunSync() {
Profile* profile = Profile::FromBrowserContext(browser_context());
const base::DictionaryValue* permit_value =
EasyUnlockService::Get(profile)->GetPermitAccess();
if (permit_value) {
scoped_ptr<easy_unlock_private::PermitRecord> permit =
easy_unlock_private::PermitRecord::FromValue(*permit_value);
results_ = easy_unlock_private::GetPermitAccess::Results::Create(*permit);
}

return true;
}

EasyUnlockPrivateClearPermitAccessFunction::
EasyUnlockPrivateClearPermitAccessFunction() {
}

EasyUnlockPrivateClearPermitAccessFunction::
~EasyUnlockPrivateClearPermitAccessFunction() {
}

bool EasyUnlockPrivateClearPermitAccessFunction::RunSync() {
Profile* profile = Profile::FromBrowserContext(browser_context());
EasyUnlockService::Get(profile)->ClearPermitAccess();
return true;
}

EasyUnlockPrivateSetRemoteDevicesFunction::
EasyUnlockPrivateSetRemoteDevicesFunction() {
}

EasyUnlockPrivateSetRemoteDevicesFunction::
~EasyUnlockPrivateSetRemoteDevicesFunction() {
}

bool EasyUnlockPrivateSetRemoteDevicesFunction::RunSync() {
scoped_ptr<easy_unlock_private::SetRemoteDevices::Params> params(
easy_unlock_private::SetRemoteDevices::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

Profile* profile = Profile::FromBrowserContext(browser_context());
if (params->devices.empty()) {
EasyUnlockService::Get(profile)->ClearRemoteDevices();
} else {
base::ListValue devices;
for (size_t i = 0; i < params->devices.size(); ++i) {
devices.Append(params->devices[i]->ToValue().release());
}
EasyUnlockService::Get(profile)->SetRemoteDevices(devices);
}

return true;
}

EasyUnlockPrivateGetRemoteDevicesFunction::
EasyUnlockPrivateGetRemoteDevicesFunction() {
}

EasyUnlockPrivateGetRemoteDevicesFunction::
~EasyUnlockPrivateGetRemoteDevicesFunction() {
}

bool EasyUnlockPrivateGetRemoteDevicesFunction::RunSync() {
Profile* profile = Profile::FromBrowserContext(browser_context());
const base::ListValue* devices =
EasyUnlockService::Get(profile)->GetRemoteDevices();
SetResult(devices ? devices->DeepCopy() : new base::ListValue());
return true;
}

} // namespace api
} // namespace extensions
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"

Expand Down Expand Up @@ -180,6 +181,82 @@ class EasyUnlockPrivateUpdateScreenlockStateFunction
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUpdateScreenlockStateFunction);
};

class EasyUnlockPrivateSetPermitAccessFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setPermitAccess",
EASYUNLOCKPRIVATE_SETPERMITACCESS)
EasyUnlockPrivateSetPermitAccessFunction();

private:
virtual ~EasyUnlockPrivateSetPermitAccessFunction();

// SyncExtensionFunction:
virtual bool RunSync() OVERRIDE;

DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetPermitAccessFunction);
};

class EasyUnlockPrivateGetPermitAccessFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getPermitAccess",
EASYUNLOCKPRIVATE_GETPERMITACCESS)
EasyUnlockPrivateGetPermitAccessFunction();

private:
virtual ~EasyUnlockPrivateGetPermitAccessFunction();

// SyncExtensionFunction:
virtual bool RunSync() OVERRIDE;

DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetPermitAccessFunction);
};

class EasyUnlockPrivateClearPermitAccessFunction
: public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.clearPermitAccess",
EASYUNLOCKPRIVATE_CLEARPERMITACCESS)
EasyUnlockPrivateClearPermitAccessFunction();

private:
virtual ~EasyUnlockPrivateClearPermitAccessFunction();

// SyncExtensionFunction:
virtual bool RunSync() OVERRIDE;

DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateClearPermitAccessFunction);
};

class EasyUnlockPrivateSetRemoteDevicesFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setRemoteDevices",
EASYUNLOCKPRIVATE_SETREMOTEDEVICES)
EasyUnlockPrivateSetRemoteDevicesFunction();

private:
virtual ~EasyUnlockPrivateSetRemoteDevicesFunction();

// SyncExtensionFunction:
virtual bool RunSync() OVERRIDE;

DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetRemoteDevicesFunction);
};

class EasyUnlockPrivateGetRemoteDevicesFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getRemoteDevices",
EASYUNLOCKPRIVATE_GETREMOTEDEVICES)
EasyUnlockPrivateGetRemoteDevicesFunction();

private:
virtual ~EasyUnlockPrivateGetRemoteDevicesFunction();

// SyncExtensionFunction:
virtual bool RunSync() OVERRIDE;

DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetRemoteDevicesFunction);
};

} // namespace api
} // namespace extensions

Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/resources/options/browser_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,9 @@ cr.define('options', function() {
updateEasyUnlock_: function(hasPairing) {
$('easy-unlock-setup').hidden = hasPairing;
$('easy-unlock-enable').hidden = !hasPairing;
if (!hasPairing && EasyUnlockTurnOffOverlay.getInstance().visible) {
EasyUnlockTurnOffOverlay.dismiss();
}
},

/**
Expand Down
76 changes: 66 additions & 10 deletions chrome/browser/resources/options/easy_unlock_turn_off_overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ cr.define('options', function() {
var Page = cr.ui.pageManager.Page;
var PageManager = cr.ui.pageManager.PageManager;

// UI state of the turn off overlay.
// @enum {string}
var UIState = {
UNKNOWN: 'unknown',
OFFLINE: 'offline',
IDLE: 'idle',
PENDING: 'pending',
SERVER_ERROR: 'server-error',
};

/**
* EasyUnlockTurnOffOverlay class
* Encapsulated handling of the Factory Reset confirmation overlay page.
Expand All @@ -23,6 +33,37 @@ cr.define('options', function() {
// Inherit EasyUnlockTurnOffOverlay from Page.
__proto__: Page.prototype,

/** Current UI state */
uiState_: UIState.UNKNKOWN,
get uiState() {
return this.uiState_;
},
set uiState(newUiState) {
if (newUiState == this.uiState_)
return;

this.uiState_ = newUiState;
switch (this.uiState_) {
case UIState.OFFLINE:
this.setUpOfflineUI_();
break;
case UIState.IDLE:
this.setUpTurnOffUI_(false);
break;
case UIState.PENDING:
this.setUpTurnOffUI_(true);
break;
case UIState.SERVER_ERROR:
this.setUpServerErrorUI_();
break;
default:
console.error('Unknow Easy unlock turn off UI state: ' +
this.uiState_);
this.setUpTurnOffUI_(false);
break;
}
},

/** @override */
initializePage: function() {
Page.prototype.initializePage.call(this);
Expand All @@ -31,23 +72,26 @@ cr.define('options', function() {
EasyUnlockTurnOffOverlay.dismiss();
};
$('easy-unlock-turn-off-confirm').onclick = function(event) {
$('easy-unlock-turn-off-confirm').disabled = true;
this.setSpinnerVisible_(true);

// TODO(xiyuan): Wire this up.
// chrome.send('turnOffEasyUnlock');
this.uiState = UIState.PENDING;
chrome.send('easyUnlockRequestTurnOff');
}.bind(this);
},

/** @override */
didShowPage: function() {
if (navigator.onLine) {
this.setUpTurnOffUI_();
this.uiState = UIState.IDLE;
chrome.send('easyUnlockGetTurnOffFlowStatus');
} else {
this.setUpOfflineUI_();
this.uiState = UIState.OFFLINE;
}
},

/** @override */
didClosePage: function() {
chrome.send('easyUnlockTurnOffOverlayDismissed');
},

/**
* Returns the button strip element.
* @return {HTMLDivElement} The container div of action buttons.
Expand Down Expand Up @@ -91,9 +135,10 @@ cr.define('options', function() {

/**
* Set up UI for turning off Easy Unlock.
* @param {boolean} pending Whether there is a pending turn-off call.
* @private
*/
setUpTurnOffUI_: function() {
setUpTurnOffUI_: function(pending) {
$('easy-unlock-turn-off-title').textContent =
loadTimeData.getString('easyUnlockTurnOffTitle');
$('easy-unlock-turn-off-messagee').textContent =
Expand All @@ -102,8 +147,8 @@ cr.define('options', function() {
loadTimeData.getString('easyUnlockTurnOffButton');

this.setActionButtonsVisible_(true);
this.setSpinnerVisible_(false);
$('easy-unlock-turn-off-confirm').disabled = false;
this.setSpinnerVisible_(pending);
$('easy-unlock-turn-off-confirm').disabled = pending;
$('easy-unlock-turn-off-dismiss').hidden = false;
},

Expand All @@ -126,10 +171,21 @@ cr.define('options', function() {
},
};

/**
* Closes the Easy unlock turn off overlay.
*/
EasyUnlockTurnOffOverlay.dismiss = function() {
PageManager.closeOverlay();
};

/**
* Update UI to reflect the turn off operation status.
* @param {string} newState The UIState string representing the new state.
*/
EasyUnlockTurnOffOverlay.updateUIState = function(newState) {
EasyUnlockTurnOffOverlay.getInstance().uiState = newState;
};

// Export
return {
EasyUnlockTurnOffOverlay: EasyUnlockTurnOffOverlay
Expand Down
Loading

0 comments on commit 7c37d21

Please sign in to comment.