[geary/wip/improve-claiming-folder-session: 2/9] Remove Geary.Folder.wait_for_remote_async()



commit 69ac6eb48f420ed54d6170a90391045048fac2e3
Author: Michael Gratton <mike vee net>
Date:   Sat Nov 10 23:38:54 2018 +1100

    Remove Geary.Folder.wait_for_remote_async()
    
    This doesn't make any sense for local-only folders, and only gets used
    for internal implementation details for IMAP folders, so remove the
    public API and replace its use internally.

 src/engine/api/geary-abstract-local-folder.vala    |  5 ---
 src/engine/api/geary-folder.vala                   | 16 ++-----
 .../imap-engine-account-synchronizer.vala          |  1 -
 .../imap-engine/imap-engine-minimal-folder.vala    | 52 +++++++++++-----------
 .../imap-engine/imap-engine-replay-queue.vala      |  2 +-
 test/engine/api/geary-folder-mock.vala             |  5 ---
 6 files changed, 29 insertions(+), 52 deletions(-)
---
diff --git a/src/engine/api/geary-abstract-local-folder.vala b/src/engine/api/geary-abstract-local-folder.vala
index c7e35658..06a38450 100644
--- a/src/engine/api/geary-abstract-local-folder.vala
+++ b/src/engine/api/geary-abstract-local-folder.vala
@@ -33,11 +33,6 @@ public abstract class Geary.AbstractLocalFolder : Geary.Folder {
         return open_count > 0;
     }
 
-    public override async void wait_for_remote_async(Cancellable? cancellable = null) throws Error {
-        if (open_count == 0)
-            throw new EngineError.OPEN_REQUIRED("%s not open", to_string());
-    }
-
     public override async bool open_async(Geary.Folder.OpenFlags open_flags, Cancellable? cancellable = null)
         throws Error {
         if (open_count++ > 0)
diff --git a/src/engine/api/geary-folder.vala b/src/engine/api/geary-folder.vala
index f6dbf7e6..afdd1ee7 100644
--- a/src/engine/api/geary-folder.vala
+++ b/src/engine/api/geary-folder.vala
@@ -498,7 +498,7 @@ public abstract class Geary.Folder : BaseObject {
      * possible for some methods to return early without waiting,
      * depending on prior information of the folder. See {@link
      * list_email_by_id_async} for special notes on its
-     * operation. Also see {@link wait_for_remote_async}.
+     * operation.
      *
      * In some cases, establishing a remote connection may be
      * performed lazily, that is only when first needed. If however
@@ -535,16 +535,6 @@ public abstract class Geary.Folder : BaseObject {
                                           Cancellable? cancellable = null)
         throws Error;
 
-    /**
-     * Blocks waiting for the folder to establish a remote session.
-     *
-     * @throws EngineError.OPEN_REQUIRED if the folder has not already
-     * been opened.
-     * @throws EngineError.ALREADY_CLOSED if not opened due to error.
-     */
-    public abstract async void wait_for_remote_async(Cancellable? cancellable = null)
-        throws Error;
-
     /**
      * Marks one use of the folder's operations as being completed.
      *
@@ -572,8 +562,8 @@ public abstract class Geary.Folder : BaseObject {
     /**
      * Wait for the {@link Folder} to fully close.
      *
-     * Unlike {@link wait_for_remote_async}, this will ''always'' block until a {@link Folder} is
-     * closed, even if it's not open.
+     * This will ''always'' block until the folder is closed, even if
+     * it's not open.
      */
     public abstract async void wait_for_close_async(Cancellable? cancellable = null) throws Error;
 
diff --git a/src/engine/imap-engine/imap-engine-account-synchronizer.vala 
b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
index 7d70b303..54b587dd 100644
--- a/src/engine/imap-engine/imap-engine-account-synchronizer.vala
+++ b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
@@ -105,7 +105,6 @@ private class Geary.ImapEngine.RefreshFolderSync : FolderOperation {
         bool was_opened = false;
         try {
             yield this.folder.open_async(Folder.OpenFlags.NONE, cancellable);
-            yield this.folder.wait_for_remote_async(cancellable);
             was_opened = true;
             debug("Synchronising %s", this.folder.to_string());
             yield sync_folder(cancellable);
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala 
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index 6b0c0ba0..05bc44d3 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -220,20 +220,6 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         return opening;
     }
 
-    /** {@inheritDoc} */
-    public override async void wait_for_remote_async(Cancellable? cancellable = null) throws Error {
-        check_open("wait_for_remote_async");
-
-        // If remote has not yet been opened and we are not in the
-        // process of closing the folder, open a session right away.
-        if (this.remote_session == null && !this.open_cancellable.is_cancelled()) {
-            this.open_remote_session.begin();
-        }
-
-        if (!yield this.remote_wait_semaphore.wait_for_result_async(cancellable))
-            throw new EngineError.ALREADY_CLOSED("%s failed to open", to_string());
-    }
-
     /**
      * Returns a valid IMAP folder session when one is available.
      *
@@ -251,7 +237,17 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         throws Error {
         check_open("claim_remote_session");
         debug("%s: Claiming folder session", this.to_string());
-        yield this.wait_for_remote_async(cancellable);
+
+
+        // If remote has not yet been opened and we are not in the
+        // process of closing the folder, open a session right away.
+        if (this.remote_session == null && !this.open_cancellable.is_cancelled()) {
+            this.open_remote_session.begin();
+        }
+
+        if (!yield this.remote_wait_semaphore.wait_for_result_async(cancellable))
+            throw new EngineError.ALREADY_CLOSED("%s failed to open", to_string());
+
         return this.remote_session;
     }
 
@@ -771,17 +767,20 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
             this.local_folder.get_properties().email_total
         );
 
-        // Unless NO_DELAY is set, do NOT open the remote side here; wait for the ReplayQueue to
-        // require a remote connection or wait_for_remote_async() to be called ... this allows for
-        // fast local-only operations to occur, local-only either because (a) the folder has all
-        // the information required (for a list or fetch operation), or (b) the operation was de
-        // facto local-only.  In particular, EmailStore will open and close lots of folders,
-        // causing a lot of connection setup and teardown
+        // Unless NO_DELAY is set, do NOT open the remote side here;
+        // wait for a folder session to be claimed ... this allows for
+        // fast local-only operations to occur, local-only either
+        // because (a) the folder has all the information required
+        // (for a list or fetch operation), or (b) the operation was
+        // de facto local-only.  In particular, EmailStore will open
+        // and close lots of folders, causing a lot of connection
+        // setup and teardown
         //
-        // However, want to eventually open, otherwise if there's no user interaction (i.e. a
-        // second account Inbox they don't manipulate), no remote connection will ever be made,
-        // meaning that folder normalization never happens and unsolicited notifications never
-        // arrive
+        // However, want to eventually open, otherwise if there's no
+        // user interaction (i.e. a second account Inbox they don't
+        // manipulate), no remote connection will ever be made,
+        // meaning that folder normalization never happens and
+        // unsolicited notifications never arrive
         this._account.session_pool.ready.connect(on_remote_ready);
         if (open_flags.is_all_set(OpenFlags.NO_DELAY)) {
             this.open_remote_session.begin();
@@ -1448,8 +1447,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // we support IMAP CONDSTORE (Bug 713117).
         int chunk_size = FLAG_UPDATE_START_CHUNK;
         Geary.EmailIdentifier? lowest = null;
-        for (;;) {
-            yield wait_for_remote_async(cancellable);
+        while (get_open_state() != Geary.Folder.OpenState.CLOSED) {
             Gee.List<Geary.Email>? list_local = yield list_email_by_id_async(
                 lowest, chunk_size,
                 Geary.Email.Field.FLAGS,
diff --git a/src/engine/imap-engine/imap-engine-replay-queue.vala 
b/src/engine/imap-engine/imap-engine-replay-queue.vala
index dd8d81e6..6457ef79 100644
--- a/src/engine/imap-engine/imap-engine-replay-queue.vala
+++ b/src/engine/imap-engine/imap-engine-replay-queue.vala
@@ -494,7 +494,7 @@ private class Geary.ImapEngine.ReplayQueue : Geary.BaseObject {
             // wait until the remote folder is opened (or throws an exception, in which case closed)
             try {
                 if (!is_close_op && folder_opened && state == State.OPEN)
-                    yield owner.wait_for_remote_async(this.remote_wait_cancellable);
+                    yield owner.claim_remote_session(this.remote_wait_cancellable);
             } catch (Error remote_err) {
                 debug("Folder %s closed or failed to open, remote replay queue closing: %s",
                       to_string(), remote_err.message);
diff --git a/test/engine/api/geary-folder-mock.vala b/test/engine/api/geary-folder-mock.vala
index fee33d42..35f56020 100644
--- a/test/engine/api/geary-folder-mock.vala
+++ b/test/engine/api/geary-folder-mock.vala
@@ -66,11 +66,6 @@ public class Geary.MockFolder : Folder, MockObject {
         );
     }
 
-    public override async void wait_for_remote_async(Cancellable? cancellable = null)
-    throws Error {
-        throw new EngineError.UNSUPPORTED("Mock method");
-    }
-
     public override async bool close_async(Cancellable? cancellable = null)
     throws Error {
         return boolean_call(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]