             else
                 return false
 
+    class DropboxView extends SyncView
+        constructor: (syncMaster, path) ->
+            super(syncMaster)
+            @path = path
+            @lastProcessingTime = new Date()
+
+            spy.processDropbox = @processDropbox
+
+            setInterval(@heartbeat, 100)
+ 
+        onDataUpdated: (source, version, data) =>
+            slog "DropboxView.onDataUpdated()"
+            # @requestProcessing()
+            @dirty = true
+
+        heartbeat: () =>
+            now = new Date()
+            stale = (now - @lastProcessingTime) > (5 * 1000)
+            if (@dirty or stale) and not @processing
+                @lastProcessingTime = now
+                processDropbox()
+
+        processDropbox: () =>
+
+            finishProcessing = (done) =>
+                @processing = false
+                if done
+                    @dirty = false
+
+            slog 'processDropbox'
+            @startTime = new Date()
+
+            # Check Dropbox for changes
+            @processing = true
+            promise1 = loadDropboxPath(@path)
+            promise1.catch rejectCb
+            promise1.then (data) =>
+                slog.report = (title) =>
+                    slog title
+                    slog "syncView:  ", @version, @data
+                    slog "syncMaster:", @syncMaster.version, @syncMaster.data
+                    slog "Dropbox:   ", '0', data.text
+                    slog "Time:      ", (new Date() - @startTime)  / 1000
+
+                slog.report('BEFORE:')
+                # Only changed on syncMaster
+                if @data is data.text and @data isnt @syncMaster.data
+                    slog "Update syncView and Dropbox. (Only changed on SyncMaster)"
+                    @data = @syncMaster.data
+                    @version = @syncMaster.version
+
+                    # Update Dropbox
+                    promise2 = dbx.filesUpload options =
+                        path: path
+                        contents: @data
+                        mode:
+                            '.tag': 'update'
+                            update: data.rev
+                    promise2.then (metaData) =>
+                        data.text = @data
+                        slog.report('AFTER:')
+
+                        done = @data is @syncMaster.data and
+                               @data is data.text and
+                               @syncMaster.data is data.text
+
+                        finishProcessing(done)
+
+                # Only changed on Dropbox
+                else if @data is @syncMaster.data and @data isnt data.text
+                    slog "Update syncView and SyncMaster. (Only changed on Dropbox)"
+                    @data = data.text
+                    # Update syncMaster
+                    @syncMaster.update(this, @data)
+
+                    slog.report('AFTER:')
+                    done = @data is @syncMaster.data and
+                           @data is data.text and
+                           @syncMaster.data is data.text
+
+                    finishProcessing(done)
+
+                else if @data isnt @syncMaster.data and @data isnt data.text
+                    slog.report('CONFLICT!!\nAFTER:')
+                    finishProcessing(true)
+                else
+                    slog.report('No changes.\nAFTER:')
+                    finishProcessing(true)
+
+
+
     class DocView extends SyncView
         constructor: (syncMaster, doc) ->
             super(syncMaster)

        onDataUpdated: (source, version, data) =>
            if super(source, version, data)
                @outline.reloadSerialization(@data)

    panel = new DockPanel()
    panel.id = 'main'

                        log "ERROR: #{error.error} (Status: #{error.status})"
                        history.pushState(null, null, "#BLANK")
            else
                promise = loadDropboxPath(path)
                promise.then (data) ->
                    doc.setValue(data.text)
                    dropboxView = new DropboxView(syncMaster, path)
                    dropboxView.data = data.text
                    dropboxView.rev = data.rev

                    spy.dropboxView = dropboxView
                promise.catch (error) ->
                    slog 'ERROR'



