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" | |
hashimoto
2017/01/23 08:28:42
nit: is this needed?
Shuhei Takahashi
2017/01/23 09:17:51
No longer needed.
| |
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. | |
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 operation runner provides better UX when the user attempts | |
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 GURL& url, | |
53 const GetFileSizeCallback& callback) override; | |
54 void OpenFileToRead(const GURL& 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: | |
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 | |
73 // Constructor called from unit tests. | |
74 ArcDeferredFileSystemOperationRunner(ArcBridgeService* bridge_service, | |
75 bool observe_events); | |
76 | |
77 // Called whenever ARC states related to |should_defer_| are changed. | |
78 void OnStateChanged(); | |
79 | |
80 // Enables/disables deferring. | |
81 void SetShouldDefer(bool should_defer); | |
82 | |
83 // Indicates if this instance should register observers to receive events. | |
84 // Usually true, but set to false in unit tests. | |
85 bool observe_events_; | |
86 | |
87 // Set to true if operations should be deferred at this moment. | |
88 bool should_defer_ = true; | |
89 | |
90 // List of deferred operations. | |
91 std::vector<base::Closure> deferred_operations_; | |
92 | |
93 base::WeakPtrFactory<ArcDeferredFileSystemOperationRunner> weak_ptr_factory_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(ArcDeferredFileSystemOperationRunner); | |
96 }; | |
97 | |
98 } // namespace arc | |
99 | |
100 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DEFERRED_FILE_SYSTEM_OPERATIO N_RUNNER_H_ | |
OLD | NEW |