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

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: Review ready. 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)>;
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 explicit ArcFileSystemOperationRunner(ArcBridgeService* bridge_service); 79 explicit ArcFileSystemOperationRunner(ArcBridgeService* bridge_service);
70 ~ArcFileSystemOperationRunner() override; 80 ~ArcFileSystemOperationRunner() override;
71 81
72 // Runs file system operations. See file_system.mojom for documentation. 82 // Runs file system operations. See file_system.mojom for documentation.
73 void GetFileSize(const GURL& url, const GetFileSizeCallback& callback); 83 void GetFileSize(const GURL& url, const GetFileSizeCallback& callback);
74 void OpenFileToRead(const GURL& url, const OpenFileToReadCallback& callback); 84 void OpenFileToRead(const GURL& url, const OpenFileToReadCallback& callback);
75 void GetDocument(const std::string& authority, 85 void GetDocument(const std::string& authority,
76 const std::string& document_id, 86 const std::string& document_id,
77 const GetDocumentCallback& callback); 87 const GetDocumentCallback& callback);
78 void GetChildDocuments(const std::string& authority, 88 void GetChildDocuments(const std::string& authority,
79 const std::string& parent_document_id, 89 const std::string& parent_document_id,
80 const GetChildDocumentsCallback& callback); 90 const GetChildDocumentsCallback& callback);
91 void AddWatcher(const std::string& authority,
92 const std::string& document_id,
93 const WatcherCallback& watcher_callback,
94 const AddWatcherCallback& callback);
95 void RemoveWatcher(int64_t watcher_id, const RemoveWatcherCallback& callback);
96
97 // FileSystemHost overrides:
98 void OnDocumentChanged(int64_t watcher_id, mojom::ChangeType type) override;
81 99
82 // ArcSessionManager::Observer overrides: 100 // ArcSessionManager::Observer overrides:
83 void OnArcPlayStoreEnabledChanged(bool enabled) override; 101 void OnArcPlayStoreEnabledChanged(bool enabled) override;
84 102
85 // InstanceHolder<mojom::FileSystemInstance>::Observer overrides: 103 // InstanceHolder<mojom::FileSystemInstance>::Observer overrides:
86 void OnInstanceReady() override; 104 void OnInstanceReady() override;
87 void OnInstanceClosed() override; 105 void OnInstanceClosed() override;
88 106
89 private: 107 private:
90 friend class ArcFileSystemOperationRunnerTest; 108 friend class ArcFileSystemOperationRunnerTest;
91 109
92 ArcFileSystemOperationRunner(ArcBridgeService* bridge_service, 110 ArcFileSystemOperationRunner(ArcBridgeService* bridge_service,
93 bool observe_events); 111 bool set_should_defer_by_events);
112
113 void AddWatcherDone(const WatcherCallback& watcher_callback,
hidehiko 2017/02/23 11:55:28 Optional: OnWatcherAdded to be consistent with "On
Shuhei Takahashi 2017/02/24 06:10:39 Done.
114 const AddWatcherCallback& callback,
115 int64_t watcher_id);
94 116
95 // Called whenever ARC states related to |should_defer_| are changed. 117 // Called whenever ARC states related to |should_defer_| are changed.
96 void OnStateChanged(); 118 void OnStateChanged();
97 119
98 // Enables/disables deferring. 120 // Enables/disables deferring.
99 // Friend unit tests can call this function to simulate enabling/disabling 121 // Friend unit tests can call this function to simulate enabling/disabling
100 // deferring. 122 // deferring.
101 void SetShouldDefer(bool should_defer); 123 void SetShouldDefer(bool should_defer);
102 124
103 // Indicates if this instance should register observers to receive events. 125 // Indicates if this instance should enable/disable deferring by events.
104 // Usually true, but set to false in unit tests. 126 // Usually true, but set to false in unit tests.
105 bool observe_events_; 127 bool set_should_defer_by_events_;
106 128
107 // Set to true if operations should be deferred at this moment. 129 // Set to true if operations should be deferred at this moment.
108 // The default is set to false so that operations are not deferred in 130 // The default is set to false so that operations are not deferred in
109 // unit tests. 131 // unit tests.
110 bool should_defer_ = false; 132 bool should_defer_ = false;
111 133
112 // List of deferred operations. 134 // List of deferred operations.
113 std::vector<base::Closure> deferred_operations_; 135 std::vector<base::Closure> deferred_operations_;
114 136
137 // Map from a watcher ID to a watcher callback.
138 std::map<int64_t, WatcherCallback> watcher_callbacks_;
139
140 mojo::Binding<mojom::FileSystemHost> binding_;
141
115 base::WeakPtrFactory<ArcFileSystemOperationRunner> weak_ptr_factory_; 142 base::WeakPtrFactory<ArcFileSystemOperationRunner> weak_ptr_factory_;
116 143
117 DISALLOW_COPY_AND_ASSIGN(ArcFileSystemOperationRunner); 144 DISALLOW_COPY_AND_ASSIGN(ArcFileSystemOperationRunner);
118 }; 145 };
119 146
120 } // namespace arc 147 } // namespace arc
121 148
122 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_ H_ 149 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698