[aseprite] 32/64: Abort http requests when we quit the program

Tobias Hansen thansen at moszumanska.debian.org
Tue Jun 21 14:43:03 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit 61a933bee2b8b4ba03fc3c1923377c7aca4064d6
Author: David Capello <davidcapello at gmail.com>
Date:   Tue May 17 12:14:01 2016 -0300

    Abort http requests when we quit the program
---
 src/app/check_update.cpp     | 37 ++++++++++---------------------------
 src/net/http_request.cpp     |  2 +-
 src/updater/check_update.cpp | 21 +++++++++++----------
 src/updater/check_update.h   |  6 +-----
 4 files changed, 23 insertions(+), 43 deletions(-)

diff --git a/src/app/check_update.cpp b/src/app/check_update.cpp
index 19f049a..419aebc 100644
--- a/src/app/check_update.cpp
+++ b/src/app/check_update.cpp
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -27,50 +27,33 @@ static const int kMonitoringPeriod = 100;
 
 namespace app {
 
-class CheckUpdateBackgroundJob : public updater::CheckUpdateDelegate
-{
+class CheckUpdateBackgroundJob : public updater::CheckUpdateDelegate {
 public:
   CheckUpdateBackgroundJob()
-    : m_canceled(false)
-    , m_received(false) { }
-
-  virtual ~CheckUpdateBackgroundJob() { }
+    : m_received(false) { }
 
-  void cancel()
-  {
-    m_canceled = true;
+  void abort() {
+    m_checker.abort();
   }
 
-  bool isCanceled() const
-  {
-    return m_canceled;
-  }
-
-  bool isReceived() const
-  {
+  bool isReceived() const {
     return m_received;
   }
 
-  void sendRequest(const updater::Uuid& uuid, const std::string& extraParams)
-  {
+  void sendRequest(const updater::Uuid& uuid, const std::string& extraParams) {
     m_checker.checkNewVersion(uuid, extraParams, this);
   }
 
-  const updater::CheckUpdateResponse& getResponse() const
-  {
+  const updater::CheckUpdateResponse& getResponse() const {
     return m_response;
   }
 
 private:
-
-  // CheckUpdateDelegate implementation
-  virtual void onResponse(updater::CheckUpdateResponse& data)
-  {
+  void onResponse(updater::CheckUpdateResponse& data) override {
     m_response = data;
     m_received = true;
   }
 
-  bool m_canceled;
   bool m_received;
   updater::CheckUpdate m_checker;
   updater::CheckUpdateResponse m_response;
@@ -117,7 +100,7 @@ CheckUpdateThreadLauncher::~CheckUpdateThreadLauncher()
 
   if (m_thread) {
     if (m_bgJob)
-      m_bgJob->cancel();
+      m_bgJob->abort();
 
     m_thread->join();
   }
diff --git a/src/net/http_request.cpp b/src/net/http_request.cpp
index 2252ea5..3517802 100644
--- a/src/net/http_request.cpp
+++ b/src/net/http_request.cpp
@@ -71,7 +71,7 @@ public:
 
   void abort()
   {
-    // TODO
+    curl_easy_cleanup(m_curl);
   }
 
 private:
diff --git a/src/updater/check_update.cpp b/src/updater/check_update.cpp
index fcd9589..fd50de3 100644
--- a/src/updater/check_update.cpp
+++ b/src/updater/check_update.cpp
@@ -12,8 +12,9 @@
 #include "updater/check_update.h"
 
 #include "base/bind.h"
-#include "base/debug.h"
 #include "base/convert_to.h"
+#include "base/debug.h"
+#include "base/unique_ptr.h"
 #include "net/http_headers.h"
 #include "net/http_request.h"
 #include "net/http_response.h"
@@ -91,14 +92,12 @@ public:
 
   void abort()
   {
-    // TODO impl
+    if (m_request)
+      m_request->abort();
   }
 
   void checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate)
   {
-    using namespace base;
-    using namespace net;
-
 #ifndef UPDATE_URL
 #define UPDATE_URL ""
 #pragma message("warning: Define UPDATE_URL macro")
@@ -114,14 +113,14 @@ public:
       url += extraParams;
     }
 
-    HttpRequest request(url);
-    HttpHeaders headers;
+    m_request.reset(new net::HttpRequest(url));
+    net::HttpHeaders headers;
     headers.setHeader("User-Agent", getUserAgent());
-    request.setHeaders(headers);
+    m_request->setHeaders(headers);
 
     std::stringstream body;
-    HttpResponse response(&body);
-    request.send(response);
+    net::HttpResponse response(&body);
+    m_request->send(response);
 
     TRACE("Checking updates: %s (User-Agent: %s)\n", url.c_str(), getUserAgent().c_str());
     TRACE("Response:\n--\n%s--\n", body.str().c_str());
@@ -130,6 +129,8 @@ public:
     delegate->onResponse(data);
   }
 
+private:
+  base::UniquePtr<net::HttpRequest> m_request;
 };
 
 CheckUpdate::CheckUpdate()
diff --git a/src/updater/check_update.h b/src/updater/check_update.h
index c569835..20146b9 100644
--- a/src/updater/check_update.h
+++ b/src/updater/check_update.h
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -63,10 +63,6 @@ namespace updater {
   public:
     virtual ~CheckUpdateDelegate() { }
 
-    // Returns true when the user is quitting the application so he does
-    // not want to continue checking for updates.
-    // virtual bool abortRequest() = 0;
-
     // Called by CheckUpdate::checkNewVersion() when the response from
     // the "updates server" is received.
     virtual void onResponse(CheckUpdateResponse& data) = 0;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list