| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |  | 
| 2 // Use of this source code is governed by a BSD-style license that can be |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DEFERRED_FILE_SYSTEM_OPERATION_R
    UNNER_H_ |  | 
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DEFERRED_FILE_SYSTEM_OPERATION_R
    UNNER_H_ |  | 
| 7 |  | 
| 8 #include <string> |  | 
| 9 #include <vector> |  | 
| 10 |  | 
| 11 #include "base/callback_forward.h" |  | 
| 12 #include "base/macros.h" |  | 
| 13 #include "base/memory/weak_ptr.h" |  | 
| 14 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |  | 
| 15 #include "components/arc/arc_service.h" |  | 
| 16 #include "components/arc/common/file_system.mojom.h" |  | 
| 17 #include "components/arc/file_system/arc_file_system_operation_runner.h" |  | 
| 18 #include "components/arc/instance_holder.h" |  | 
| 19 |  | 
| 20 namespace arc { |  | 
| 21 |  | 
| 22 // Implements deferred ARC file system operations. |  | 
| 23 // |  | 
| 24 // When ARC is disabled or ARC has already booted, file system operations are |  | 
| 25 // performed immediately. While ARC boot is under progress, file operations are |  | 
| 26 // deferred until ARC boot finishes or the user disables ARC. |  | 
| 27 // |  | 
| 28 // This file system operation runner provides better UX when the user attempts |  | 
| 29 // to perform file operations while ARC is booting. For example: |  | 
| 30 // |  | 
| 31 // - Media views are mounted in Files app soon after the user logs into |  | 
| 32 //   the system. If the user attempts to open media views before ARC boots, |  | 
| 33 //   a spinner is shown until file system gets ready because ReadDirectory |  | 
| 34 //   operations are deferred. |  | 
| 35 // - When an Android content URL is opened soon after the user logs into |  | 
| 36 //   the system (because the user opened the tab before they logged out for |  | 
| 37 //   instance), the tab keeps loading until ARC boot finishes, instead of |  | 
| 38 //   failing immediately. |  | 
| 39 // |  | 
| 40 // All member functions must be called on the UI thread. |  | 
| 41 class ArcDeferredFileSystemOperationRunner |  | 
| 42     : public ArcFileSystemOperationRunner, |  | 
| 43       public ArcSessionManager::Observer, |  | 
| 44       public InstanceHolder<mojom::FileSystemInstance>::Observer { |  | 
| 45  public: |  | 
| 46   explicit ArcDeferredFileSystemOperationRunner( |  | 
| 47       ArcBridgeService* bridge_service); |  | 
| 48   ~ArcDeferredFileSystemOperationRunner() override; |  | 
| 49 |  | 
| 50   // ArcFileSystemOperationRunner overrides: |  | 
| 51   void GetFileSize(const GURL& url, |  | 
| 52                    const GetFileSizeCallback& callback) override; |  | 
| 53   void OpenFileToRead(const GURL& url, |  | 
| 54                       const OpenFileToReadCallback& callback) override; |  | 
| 55   void GetDocument(const std::string& authority, |  | 
| 56                    const std::string& document_id, |  | 
| 57                    const GetDocumentCallback& callback) override; |  | 
| 58   void GetChildDocuments(const std::string& authority, |  | 
| 59                          const std::string& parent_document_id, |  | 
| 60                          const GetChildDocumentsCallback& callback) override; |  | 
| 61 |  | 
| 62   // ArcSessionManager::Observer overrides: |  | 
| 63   void OnArcOptInChanged(bool enabled) override; |  | 
| 64 |  | 
| 65   // InstanceHolder<mojom::FileSystemInstance>::Observer overrides: |  | 
| 66   void OnInstanceReady() override; |  | 
| 67   void OnInstanceClosed() override; |  | 
| 68 |  | 
| 69  private: |  | 
| 70   friend class ArcDeferredFileSystemOperationRunnerTest; |  | 
| 71 |  | 
| 72   // Constructor called from unit tests. |  | 
| 73   ArcDeferredFileSystemOperationRunner(ArcBridgeService* bridge_service, |  | 
| 74                                        bool observe_events); |  | 
| 75 |  | 
| 76   // Called whenever ARC states related to |should_defer_| are changed. |  | 
| 77   void OnStateChanged(); |  | 
| 78 |  | 
| 79   // Enables/disables deferring. |  | 
| 80   void SetShouldDefer(bool should_defer); |  | 
| 81 |  | 
| 82   // Indicates if this instance should register observers to receive events. |  | 
| 83   // Usually true, but set to false in unit tests. |  | 
| 84   bool observe_events_; |  | 
| 85 |  | 
| 86   // Set to true if operations should be deferred at this moment. |  | 
| 87   bool should_defer_ = true; |  | 
| 88 |  | 
| 89   // List of deferred operations. |  | 
| 90   std::vector<base::Closure> deferred_operations_; |  | 
| 91 |  | 
| 92   base::WeakPtrFactory<ArcDeferredFileSystemOperationRunner> weak_ptr_factory_; |  | 
| 93 |  | 
| 94   DISALLOW_COPY_AND_ASSIGN(ArcDeferredFileSystemOperationRunner); |  | 
| 95 }; |  | 
| 96 |  | 
| 97 }  // namespace arc |  | 
| 98 |  | 
| 99 #endif  // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DEFERRED_FILE_SYSTEM_OPERATIO
    N_RUNNER_H_ |  | 
| OLD | NEW | 
|---|