[gnome-documents/wip/rishi/onedrive: 12/13] documents: Add a generic load implementation to DocCommon



commit f0b1961a2dbc1f93c1863a6ad288df72f8a924d8
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Apr 7 18:08:17 2017 +0200

    documents: Add a generic load implementation to DocCommon
    
    All the remote document types have the exact same load implementation.
    Instead of keeping multiple copies of that code, it's better to share
    it via the base class. In theory, we can use the same code for
    LocalDocument too, but we already have a trivial implementation that
    avoids some needless I/O so it's better to retain it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781032

 src/documents.js |  136 +++++++++++++-----------------------------------------
 1 files changed, 32 insertions(+), 104 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 034b7ee..00fd572 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -407,8 +407,38 @@ const DocCommon = new Lang.Class({
         throw(new Error('DocCommon implementations must override downloadImpl'));
     },
 
-    load: function() {
-        throw(new Error('DocCommon implementations must override load'));
+    load: function(passwd, cancellable, callback) {
+        this.download(true, cancellable, Lang.bind(this,
+            function(fromCache, error) {
+                if (error) {
+                    callback(this, null, error);
+                    return;
+                }
+
+                this.loadLocal(passwd, cancellable, Lang.bind(this,
+                    function(doc, docModel, error) {
+                        if (error) {
+                            if (fromCache &&
+                                !error.matches(EvDocument.DocumentError, 
EvDocument.DocumentError.ENCRYPTED)) {
+                                this.download(false, cancellable, Lang.bind(this,
+                                    function(fromCache, error) {
+                                        if (error) {
+                                            callback(this, null, error);
+                                            return;
+                                        }
+
+                                        this.loadLocal(passwd, cancellable, callback);
+                                    }));
+                            } else {
+                                callback(this, null, error);
+                            }
+
+                            return;
+                        }
+
+                        callback(this, docModel, null);
+                    }));
+            }));
     },
 
     canEdit: function() {
@@ -983,40 +1013,6 @@ const GoogleDocument = new Lang.Class({
             }))
     },
 
-    load: function(passwd, cancellable, callback) {
-        this.download(true, cancellable, Lang.bind(this,
-            function(fromCache, error) {
-                if (error) {
-                    callback(this, null, error);
-                    return;
-                }
-
-                this.loadLocal(passwd, cancellable, Lang.bind(this,
-                    function(doc, docModel, error) {
-                        if (error) {
-                            if (fromCache &&
-                                !error.matches(EvDocument.DocumentError, 
EvDocument.DocumentError.ENCRYPTED)) {
-                                this.download(false, cancellable, Lang.bind(this,
-                                    function(fromCache, error) {
-                                        if (error) {
-                                            callback(this, null, error);
-                                            return;
-                                        }
-
-                                        this.loadLocal(passwd, cancellable, callback);
-                                    }));
-                            } else {
-                                callback(this, null, error);
-                            }
-
-                            return;
-                        }
-
-                        callback(this, docModel, null);
-                    }));
-            }));
-    },
-
     createThumbnail: function(callback) {
         this.createGDataEntry(null, Lang.bind(this,
             function(entry, service, exception) {
@@ -1234,40 +1230,6 @@ const OwncloudDocument = new Lang.Class({
             }));
     },
 
-    load: function(passwd, cancellable, callback) {
-        this.download(true, cancellable, Lang.bind(this,
-            function(fromCache, error) {
-                if (error) {
-                    callback(this, null, error);
-                    return;
-                }
-
-                this.loadLocal(passwd, cancellable, Lang.bind(this,
-                    function(doc, docModel, error) {
-                        if (error) {
-                            if (fromCache &&
-                                !error.matches(EvDocument.DocumentError, 
EvDocument.DocumentError.ENCRYPTED)) {
-                                this.download(false, cancellable, Lang.bind(this,
-                                    function(fromCache, error) {
-                                        if (error) {
-                                            callback(this, null, error);
-                                            return;
-                                        }
-
-                                        this.loadLocal(passwd, cancellable, callback);
-                                    }));
-                            } else {
-                                callback(this, null, error);
-                            }
-
-                            return;
-                        }
-
-                        callback(this, docModel, null);
-                    }));
-            }));
-    },
-
     canEdit: function() {
         return false;
     },
@@ -1400,40 +1362,6 @@ const SkydriveDocument = new Lang.Class({
             }));
     },
 
-    load: function(passwd, cancellable, callback) {
-        this.download(true, cancellable, Lang.bind(this,
-            function(fromCache, error) {
-                if (error) {
-                    callback(this, null, error);
-                    return;
-                }
-
-                this.loadLocal(passwd, cancellable, Lang.bind(this,
-                    function(doc, docModel, error) {
-                        if (error) {
-                            if (fromCache &&
-                                !error.matches(EvDocument.DocumentError, 
EvDocument.DocumentError.ENCRYPTED)) {
-                                this.download(false, cancellable, Lang.bind(this,
-                                    function(fromCache, error) {
-                                        if (error) {
-                                            callback(this, null, error);
-                                            return;
-                                        }
-
-                                        this.loadLocal(passwd, cancellable, callback);
-                                    }));
-                            } else {
-                                callback(this, null, error);
-                            }
-
-                            return;
-                        }
-
-                        callback(this, docModel, null);
-                    }));
-            }));
-    },
-
     updateTypeDescription: function() {
         let description;
 


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