Commit 2391be9e authored by Paweł Wegner's avatar Paweł Wegner
Browse files

Removed invalid is_cancelled calls.

parent cc9eb72e
......@@ -456,8 +456,6 @@ AuthorizeRequest::Pointer MegaNz::authorizeAsync() {
shared_from_this(), [=](AuthorizeRequest::Pointer r,
AuthorizeRequest::AuthorizeCompleted complete) {
auto fetch = [=]() {
if (r->is_cancelled())
return complete(Error{IHttpRequest::Aborted, ""});
auto fetch_nodes_listener = std::make_shared<RequestListener>(
[=](EitherError<void> e, Listener*) {
if (!e.left()) authorized_ = true;
......@@ -826,10 +824,6 @@ void MegaNz::ensureAuthorized(typename Request<T>::Ptr r,
if (e.left()) {
on_error(e.left());
r->done(e.left());
} else if (r->is_cancelled()) {
Error e{IHttpRequest::Aborted, ""};
on_error(e);
r->done(e);
} else
on_success();
};
......
......@@ -29,7 +29,7 @@ namespace cloudstorage {
AuthorizeRequest::AuthorizeRequest(std::shared_ptr<CloudProvider> p,
AuthorizationFlow callback)
: Request(p), state_(provider()->auth()->state()) {
: Request(p), state_(provider()->auth()->state()), server_cancelled_() {
if (!provider()->auth_callback())
throw std::logic_error("CloudProvider's callback can't be null.");
set([=](Request::Ptr request) {
......@@ -62,6 +62,7 @@ AuthorizeRequest::~AuthorizeRequest() { cancel(); }
void AuthorizeRequest::sendCancel() {
std::unique_lock<std::mutex> lock(lock_);
auto auth_server = std::move(auth_server_);
server_cancelled_ = true;
lock.unlock();
if (auth_server) {
class Connection : public IHttpServer::IConnection {
......@@ -104,11 +105,12 @@ void AuthorizeRequest::cancel() {
}
void AuthorizeRequest::set_server(std::shared_ptr<IHttpServer> p) {
{
std::lock_guard<std::mutex> lock(lock_);
auth_server_ = p;
std::unique_lock<std::mutex> lock(lock_);
auth_server_ = p;
if (p && server_cancelled_) {
lock.unlock();
sendCancel();
}
if (p && is_cancelled()) sendCancel();
}
void AuthorizeRequest::oauth2Authorization(AuthorizeCompleted complete) {
......
......@@ -48,6 +48,7 @@ class AuthorizeRequest : public Request<EitherError<void>> {
private:
std::string state_;
std::mutex lock_;
bool server_cancelled_;
std::shared_ptr<IHttpServer> auth_server_;
};
......
......@@ -144,24 +144,19 @@ void Request<T>::reauthorize(AuthorizeCompleted c) {
auto p = provider();
if (!p) return;
std::unique_lock<std::mutex> lock(p->current_authorization_mutex_);
if (is_cancelled()) {
lock.unlock();
c(Error{IHttpRequest::Aborted, ""});
} else {
p->auth_callbacks_[this].push_back(c);
if (!p->current_authorization_) {
{
auto r = p->authorizeAsync();
p->current_authorization_ = r;
lock.unlock();
r->run();
}
lock.lock();
p->auth_callbacks_[this].push_back(c);
if (!p->current_authorization_) {
{
auto r = p->authorizeAsync();
p->current_authorization_ = r;
lock.unlock();
r->run();
}
auto r = p->current_authorization_;
lock.unlock();
if (r) subrequest(r);
lock.lock();
}
auto r = p->current_authorization_;
lock.unlock();
if (r) subrequest(r);
}
template <class T>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment