Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(811)

Side by Side Diff: chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h

Issue 2715493002: mediaview: Support watchers in ArcFileSystemOperationRunner. (Closed)
Patch Set: Rebased to ToT. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_H_
7 7
8 #include <stdint.h>
9
10 #include <map>
8 #include <memory> 11 #include <memory>
9 #include <string> 12 #include <string>
10 #include <vector> 13 #include <vector>
11 14
12 #include "base/callback_forward.h" 15 #include "base/callback_forward.h"
13 #include "base/macros.h" 16 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/chromeos/arc/arc_session_manager.h" 18 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
16 #include "components/arc/arc_service.h" 19 #include "components/arc/arc_service.h"
17 #include "components/arc/common/file_system.mojom.h" 20 #include "components/arc/common/file_system.mojom.h"
18 #include "components/arc/instance_holder.h" 21 #include "components/arc/instance_holder.h"
22 #include "mojo/public/cpp/bindings/binding.h"
23 #include "storage/browser/fileapi/watcher_manager.h"
19 24
20 namespace arc { 25 namespace arc {
21 26
22 // Runs ARC file system operations. 27 // Runs ARC file system operations.
23 // 28 //
24 // This is an abstraction layer on top of mojom::FileSystemInstance. All ARC 29 // This is an abstraction layer on top of mojom::FileSystemInstance. All ARC
25 // file system operations should go through this class, rather than invoking 30 // file system operations should go through this class, rather than invoking
26 // mojom::FileSystemInstance directly. 31 // mojom::FileSystemInstance directly.
27 // 32 //
28 // When ARC is disabled or ARC has already booted, file system operations are 33 // When ARC is disabled or ARC has already booted, file system operations are
29 // performed immediately. While ARC boot is under progress, file operations are 34 // performed immediately. While ARC boot is under progress, file operations are
30 // deferred until ARC boot finishes or the user disables ARC. 35 // deferred until ARC boot finishes or the user disables ARC.
31 // 36 //
32 // This file system operation runner provides better UX when the user attempts 37 // This file system operation runner provides better UX when the user attempts
33 // to perform file operations while ARC is booting. For example: 38 // to perform file operations while ARC is booting. For example:
34 // 39 //
35 // - Media views are mounted in Files app soon after the user logs into 40 // - Media views are mounted in Files app soon after the user logs into
36 // the system. If the user attempts to open media views before ARC boots, 41 // the system. If the user attempts to open media views before ARC boots,
37 // a spinner is shown until file system gets ready because ReadDirectory 42 // a spinner is shown until file system gets ready because ReadDirectory
38 // operations are deferred. 43 // operations are deferred.
39 // - When an Android content URL is opened soon after the user logs into 44 // - When an Android content URL is opened soon after the user logs into
40 // the system (because the user opened the tab before they logged out for 45 // the system (because the user opened the tab before they logged out for
41 // instance), the tab keeps loading until ARC boot finishes, instead of 46 // instance), the tab keeps loading until ARC boot finishes, instead of
42 // failing immediately. 47 // failing immediately.
43 // 48 //
44 // All member functions must be called on the UI thread. 49 // All member functions must be called on the UI thread.
45 class ArcFileSystemOperationRunner 50 class ArcFileSystemOperationRunner
46 : public ArcService, 51 : public ArcService,
52 public mojom::FileSystemHost,
47 public ArcSessionManager::Observer, 53 public ArcSessionManager::Observer,
48 public InstanceHolder<mojom::FileSystemInstance>::Observer { 54 public InstanceHolder<mojom::FileSystemInstance>::Observer {
49 public: 55 public:
50 using GetFileSizeCallback = mojom::FileSystemInstance::GetFileSizeCallback; 56 using GetFileSizeCallback = mojom::FileSystemInstance::GetFileSizeCallback;
51 using OpenFileToReadCallback = 57 using OpenFileToReadCallback =
52 mojom::FileSystemInstance::OpenFileToReadCallback; 58 mojom::FileSystemInstance::OpenFileToReadCallback;
53 using GetDocumentCallback = mojom::FileSystemInstance::GetDocumentCallback; 59 using GetDocumentCallback = mojom::FileSystemInstance::GetDocumentCallback;
54 using GetChildDocumentsCallback = 60 using GetChildDocumentsCallback =
55 mojom::FileSystemInstance::GetChildDocumentsCallback; 61 mojom::FileSystemInstance::GetChildDocumentsCallback;
62 using AddWatcherCallback = base::Callback<void(int64_t watcher_id)>;
Luis Héctor Chávez 2017/03/06 17:10:48 nit: maybe sort lexicographically? I couldn't find
63 using RemoveWatcherCallback = base::Callback<void(bool success)>;
64 using ChangeType = storage::WatcherManager::ChangeType;
65 using WatcherCallback = base::Callback<void(ChangeType type)>;
56 66
57 // For supporting ArcServiceManager::GetService<T>(). 67 // For supporting ArcServiceManager::GetService<T>().
58 static const char kArcServiceName[]; 68 static const char kArcServiceName[];
59 69
60 // Creates an instance suitable for unit tests. 70 // Creates an instance suitable for unit tests.
61 // This instance will run all operations immediately without deferring by 71 // This instance will run all operations immediately without deferring by
62 // default. Also, deferring can be enabled/disabled by calling 72 // default. Also, deferring can be enabled/disabled by calling
63 // SetShouldDefer() from friend classes. 73 // SetShouldDefer() from friend classes.
64 static std::unique_ptr<ArcFileSystemOperationRunner> CreateForTesting( 74 static std::unique_ptr<ArcFileSystemOperationRunner> CreateForTesting(
65 ArcBridgeService* bridge_service); 75 ArcBridgeService* bridge_service);
66 76
67 // The standard constructor. A production instance should be created by 77 // The standard constructor. A production instance should be created by
68 // this constructor. 78 // this constructor.
69 ArcFileSystemOperationRunner(ArcBridgeService* bridge_service, 79 ArcFileSystemOperationRunner(ArcBridgeService* bridge_service,
70 const Profile* profile); 80 const Profile* profile);
71 ~ArcFileSystemOperationRunner() override; 81 ~ArcFileSystemOperationRunner() override;
72 82
73 // Runs file system operations. See file_system.mojom for documentation. 83 // Runs file system operations. See file_system.mojom for documentation.
74 void GetFileSize(const GURL& url, const GetFileSizeCallback& callback); 84 void GetFileSize(const GURL& url, const GetFileSizeCallback& callback);
75 void OpenFileToRead(const GURL& url, const OpenFileToReadCallback& callback); 85 void OpenFileToRead(const GURL& url, const OpenFileToReadCallback& callback);
76 void GetDocument(const std::string& authority, 86 void GetDocument(const std::string& authority,
77 const std::string& document_id, 87 const std::string& document_id,
78 const GetDocumentCallback& callback); 88 const GetDocumentCallback& callback);
79 void GetChildDocuments(const std::string& authority, 89 void GetChildDocuments(const std::string& authority,
80 const std::string& parent_document_id, 90 const std::string& parent_document_id,
81 const GetChildDocumentsCallback& callback); 91 const GetChildDocumentsCallback& callback);
92 void AddWatcher(const std::string& authority,
93 const std::string& document_id,
94 const WatcherCallback& watcher_callback,
95 const AddWatcherCallback& callback);
96 void RemoveWatcher(int64_t watcher_id, const RemoveWatcherCallback& callback);
97
98 // FileSystemHost overrides:
99 void OnDocumentChanged(int64_t watcher_id, mojom::ChangeType type) override;
82 100
83 // ArcSessionManager::Observer overrides: 101 // ArcSessionManager::Observer overrides:
84 void OnArcPlayStoreEnabledChanged(bool enabled) override; 102 void OnArcPlayStoreEnabledChanged(bool enabled) override;
85 103
86 // InstanceHolder<mojom::FileSystemInstance>::Observer overrides: 104 // InstanceHolder<mojom::FileSystemInstance>::Observer overrides:
87 void OnInstanceReady() override; 105 void OnInstanceReady() override;
88 void OnInstanceClosed() override; 106 void OnInstanceClosed() override;
89 107
90 private: 108 private:
91 friend class ArcFileSystemOperationRunnerTest; 109 friend class ArcFileSystemOperationRunnerTest;
92 110
93 ArcFileSystemOperationRunner(ArcBridgeService* bridge_service, 111 ArcFileSystemOperationRunner(ArcBridgeService* bridge_service,
94 const Profile* profile, 112 const Profile* profile,
95 bool observe_events); 113 bool set_should_defer_by_events);
114
115 void OnWatcherAdded(const WatcherCallback& watcher_callback,
116 const AddWatcherCallback& callback,
117 int64_t watcher_id);
96 118
97 // Called whenever ARC states related to |should_defer_| are changed. 119 // Called whenever ARC states related to |should_defer_| are changed.
98 void OnStateChanged(); 120 void OnStateChanged();
99 121
100 // Enables/disables deferring. 122 // Enables/disables deferring.
101 // Friend unit tests can call this function to simulate enabling/disabling 123 // Friend unit tests can call this function to simulate enabling/disabling
102 // deferring. 124 // deferring.
103 void SetShouldDefer(bool should_defer); 125 void SetShouldDefer(bool should_defer);
104 126
105 // Profile this runner is associated with. This can be nullptr in 127 // Profile this runner is associated with. This can be nullptr in
106 // unit tests. 128 // unit tests.
107 const Profile* const profile_; 129 const Profile* const profile_;
108 130
109 // Indicates if this instance should register observers to receive events. 131 // Indicates if this instance should enable/disable deferring by events.
110 // Usually true, but set to false in unit tests. 132 // Usually true, but set to false in unit tests.
111 const bool observe_events_; 133 bool set_should_defer_by_events_;
112 134
113 // Set to true if operations should be deferred at this moment. 135 // Set to true if operations should be deferred at this moment.
114 // The default is set to false so that operations are not deferred in 136 // The default is set to false so that operations are not deferred in
115 // unit tests. 137 // unit tests.
116 bool should_defer_ = false; 138 bool should_defer_ = false;
117 139
118 // List of deferred operations. 140 // List of deferred operations.
119 std::vector<base::Closure> deferred_operations_; 141 std::vector<base::Closure> deferred_operations_;
120 142
143 // Map from a watcher ID to a watcher callback.
144 std::map<int64_t, WatcherCallback> watcher_callbacks_;
145
146 mojo::Binding<mojom::FileSystemHost> binding_;
147
121 base::WeakPtrFactory<ArcFileSystemOperationRunner> weak_ptr_factory_; 148 base::WeakPtrFactory<ArcFileSystemOperationRunner> weak_ptr_factory_;
122 149
123 DISALLOW_COPY_AND_ASSIGN(ArcFileSystemOperationRunner); 150 DISALLOW_COPY_AND_ASSIGN(ArcFileSystemOperationRunner);
124 }; 151 };
125 152
126 } // namespace arc 153 } // namespace arc
127 154
128 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_ H_ 155 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698