Chromium Code Reviews| 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/gtest_prod_util.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | |
| 16 #include "components/arc/arc_service.h" | |
| 17 #include "components/arc/common/file_system.mojom.h" | |
| 18 #include "components/arc/file_system/arc_file_system_operation_runner.h" | |
| 19 #include "components/arc/instance_holder.h" | |
| 20 | |
| 21 namespace arc { | |
| 22 | |
| 23 // Implements deferred ARC file system operations. | |
|
hidehiko
2017/01/20 08:01:49
Wow, nice comment!
Shuhei Takahashi
2017/01/20 09:13:04
:)
| |
| 24 // | |
| 25 // When ARC is disabled or ARC has already booted, file system operations are | |
| 26 // performed immediately. While ARC boot is under progress, file operations are | |
| 27 // deferred until ARC boot finishes or the user disables ARC. | |
| 28 // | |
| 29 // This file system oepration runner provides better UX when the user attempts | |
|
hidehiko
2017/01/20 08:01:49
s/oepration/operation/
Shuhei Takahashi
2017/01/20 09:13:03
Good catch.
| |
| 30 // to perform file operations while ARC is booting. For example: | |
| 31 // | |
| 32 // - Media views are mounted in Files app soon after the user logs into | |
| 33 // the system. If the user attempts to open media views before ARC boots, | |
| 34 // a spinner is shown until file system gets ready because ReadDirectory | |
| 35 // operations are deferred. | |
| 36 // - When an Android content URL is opened soon after the user logs into | |
| 37 // the system (because the user opened the tab before they logged out for | |
| 38 // instance), the tab keeps loading until ARC boot finishes, instead of | |
| 39 // failing immediately. | |
| 40 // | |
| 41 // All member functions must be called on the UI thread. | |
| 42 class ArcDeferredFileSystemOperationRunner | |
| 43 : public ArcFileSystemOperationRunner, | |
| 44 public ArcSessionManager::Observer, | |
| 45 public InstanceHolder<mojom::FileSystemInstance>::Observer { | |
| 46 public: | |
| 47 explicit ArcDeferredFileSystemOperationRunner( | |
| 48 ArcBridgeService* bridge_service); | |
| 49 ~ArcDeferredFileSystemOperationRunner() override; | |
| 50 | |
| 51 // ArcFileSystemOperationRunner overrides: | |
| 52 void GetFileSize(const std::string& url, | |
| 53 const GetFileSizeCallback& callback) override; | |
| 54 void OpenFileToRead(const std::string& url, | |
| 55 const OpenFileToReadCallback& callback) override; | |
| 56 void GetDocument(const std::string& authority, | |
| 57 const std::string& document_id, | |
| 58 const GetDocumentCallback& callback) override; | |
| 59 void GetChildDocuments(const std::string& authority, | |
| 60 const std::string& parent_document_id, | |
| 61 const GetChildDocumentsCallback& callback) override; | |
| 62 | |
| 63 // ArcSessionManager::Observer overrides: | |
|
hidehiko
2017/01/20 08:01:49
Optional: L63 - L68 can be private?
These are for
Shuhei Takahashi
2017/01/20 09:13:04
It is possible to make them private, but do we wan
| |
| 64 void OnArcOptInChanged(bool enabled) override; | |
| 65 | |
| 66 // InstanceHolder<mojom::FileSystemInstance>::Observer overrides: | |
| 67 void OnInstanceReady() override; | |
| 68 void OnInstanceClosed() override; | |
| 69 | |
| 70 private: | |
| 71 friend class ArcDeferredFileSystemOperationRunnerTest; | |
| 72 FRIEND_TEST_ALL_PREFIXES(ArcDeferredFileSystemOperationRunnerTest, | |
|
hidehiko
2017/01/20 08:01:49
Through my recent refactoring work, I felt maintai
Shuhei Takahashi
2017/01/20 09:13:04
Makes sense, done.
| |
| 73 RunImmediately); | |
| 74 FRIEND_TEST_ALL_PREFIXES(ArcDeferredFileSystemOperationRunnerTest, | |
| 75 DeferAndRun); | |
| 76 FRIEND_TEST_ALL_PREFIXES(ArcDeferredFileSystemOperationRunnerTest, | |
| 77 DeferAndDiscard); | |
| 78 | |
| 79 ArcDeferredFileSystemOperationRunner(ArcBridgeService* bridge_service, | |
|
hidehiko
2017/01/20 08:01:49
IIUC, this is for testing purpose (so that public
Shuhei Takahashi
2017/01/20 09:13:04
Sure, done.
| |
| 80 bool observe_events); | |
| 81 | |
| 82 // Called whenever ARC states related to |should_defer_| are changed. | |
| 83 void OnStateChanged(); | |
| 84 | |
| 85 // Enables/disables deferring. | |
| 86 void SetShouldDefer(bool should_defer); | |
| 87 | |
| 88 // Indicates if this instance should register observers to receive events. | |
| 89 // Usually true, but set to false in unit tests. | |
| 90 bool observe_events_; | |
| 91 | |
| 92 // Set to true if operations should be deferred at this moment. | |
| 93 bool should_defer_ = true; | |
| 94 | |
| 95 // List of deferred operations. | |
| 96 std::vector<base::Closure> deferred_operations_; | |
| 97 | |
| 98 base::WeakPtrFactory<ArcDeferredFileSystemOperationRunner> weak_ptr_factory_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(ArcDeferredFileSystemOperationRunner); | |
| 101 }; | |
| 102 | |
| 103 } // namespace arc | |
| 104 | |
| 105 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DEFERRED_FILE_SYSTEM_OPERATIO N_RUNNER_H_ | |
| OLD | NEW |