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

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

Issue 2726373002: mediaview: Hack to avoid Files app to freeze soon after login. (Closed)
Patch Set: Remove unnecessary branch. 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_DOCUMENTS_PROVIDER_ROOT_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // ArcFileSystemOperationRunner::Observer overrides: 115 // ArcFileSystemOperationRunner::Observer overrides:
116 void OnWatchersCleared() override; 116 void OnWatchersCleared() override;
117 117
118 private: 118 private:
119 // Thin representation of a document in documents provider. 119 // Thin representation of a document in documents provider.
120 struct ThinDocument { 120 struct ThinDocument {
121 std::string document_id; 121 std::string document_id;
122 bool is_directory; 122 bool is_directory;
123 }; 123 };
124 124
125 // Represents the status of a document watcher.
126 struct WatcherData {
127 // ID of a watcher in the remote file system service.
128 //
129 // Valid IDs are represented by positive integers. An invalid watcher is
130 // represented by |kInvalidWatcherId|, which occurs in several cases:
131 //
132 // - AddWatcher request is still in-flight. In this case, a valid ID is set
133 // to |inflight_request_id|.
134 //
135 // - The remote file system service notified us that it stopped and all
136 // watchers were forgotten. Such watchers are still tracked here, but they
137 // are not known by the remote service.
138 int64_t id;
139
140 // A unique ID of AddWatcher() request.
141 //
142 // While AddWatcher() is in-flight, a positive integer is set to this
143 // variable, and |id| is |kInvalidWatcherId|. Otherwise it is set to
144 // |kInvalidWatcherRequestId|.
145 uint64_t inflight_request_id;
146 };
147
148 static const int64_t kInvalidWatcherId;
149 static const uint64_t kInvalidWatcherRequestId;
150 static const WatcherData kInvalidWatcherData;
151
125 // Mapping from a file name to a ThinDocument. 152 // Mapping from a file name to a ThinDocument.
126 using NameToThinDocumentMap = 153 using NameToThinDocumentMap =
127 std::map<base::FilePath::StringType, ThinDocument>; 154 std::map<base::FilePath::StringType, ThinDocument>;
128 155
129 using ResolveToDocumentIdCallback = 156 using ResolveToDocumentIdCallback =
130 base::Callback<void(const std::string& document_id)>; 157 base::Callback<void(const std::string& document_id)>;
131 using ReadDirectoryInternalCallback = 158 using ReadDirectoryInternalCallback =
132 base::Callback<void(base::File::Error error, 159 base::Callback<void(base::File::Error error,
133 NameToThinDocumentMap mapping)>; 160 NameToThinDocumentMap mapping)>;
134 161
135 void GetFileInfoWithDocumentId(const GetFileInfoCallback& callback, 162 void GetFileInfoWithDocumentId(const GetFileInfoCallback& callback,
136 const std::string& document_id); 163 const std::string& document_id);
137 void GetFileInfoWithDocument(const GetFileInfoCallback& callback, 164 void GetFileInfoWithDocument(const GetFileInfoCallback& callback,
138 mojom::DocumentPtr document); 165 mojom::DocumentPtr document);
139 166
140 void ReadDirectoryWithDocumentId(const ReadDirectoryCallback& callback, 167 void ReadDirectoryWithDocumentId(const ReadDirectoryCallback& callback,
141 const std::string& document_id); 168 const std::string& document_id);
142 void ReadDirectoryWithNameToThinDocumentMap( 169 void ReadDirectoryWithNameToThinDocumentMap(
143 const ReadDirectoryCallback& callback, 170 const ReadDirectoryCallback& callback,
144 base::File::Error error, 171 base::File::Error error,
145 NameToThinDocumentMap mapping); 172 NameToThinDocumentMap mapping);
146 173
147 void AddWatcherWithDocumentId(const base::FilePath& path, 174 void AddWatcherWithDocumentId(const base::FilePath& path,
175 uint64_t watcher_request_id,
148 const WatcherCallback& watcher_callback, 176 const WatcherCallback& watcher_callback,
149 const StatusCallback& callback,
150 const std::string& document_id); 177 const std::string& document_id);
151 void OnWatcherAdded(const base::FilePath& path, 178 void OnWatcherAdded(const base::FilePath& path,
152 const StatusCallback& callback, 179 uint64_t watcher_request_id,
153 int64_t watcher_id); 180 int64_t watcher_id);
154 void OnWatcherAddedButRemoved(const StatusCallback& callback, bool success); 181 void OnWatcherAddedButRemoved(bool success);
155 182
156 void OnWatcherRemoved(const StatusCallback& callback, bool success); 183 void OnWatcherRemoved(const StatusCallback& callback, bool success);
157 184
185 // Returns true if the specified watcher request has been canceled.
186 // This function should be called only while the request is in-flight.
187 bool IsWatcherInflightRequestCanceled(const base::FilePath& path,
188 uint64_t watcher_request_id) const;
189
158 void ResolveToContentUrlWithDocumentId( 190 void ResolveToContentUrlWithDocumentId(
159 const ResolveToContentUrlCallback& callback, 191 const ResolveToContentUrlCallback& callback,
160 const std::string& document_id); 192 const std::string& document_id);
161 193
162 // Resolves |path| to a document ID. Failures are indicated by an empty 194 // Resolves |path| to a document ID. Failures are indicated by an empty
163 // document ID. 195 // document ID.
164 void ResolveToDocumentId(const base::FilePath& path, 196 void ResolveToDocumentId(const base::FilePath& path,
165 const ResolveToDocumentIdCallback& callback); 197 const ResolveToDocumentIdCallback& callback);
166 void ResolveToDocumentIdRecursively( 198 void ResolveToDocumentIdRecursively(
167 const std::string& document_id, 199 const std::string& document_id,
168 const std::vector<base::FilePath::StringType>& components, 200 const std::vector<base::FilePath::StringType>& components,
169 const ResolveToDocumentIdCallback& callback); 201 const ResolveToDocumentIdCallback& callback);
170 void ResolveToDocumentIdRecursivelyWithNameToThinDocumentMap( 202 void ResolveToDocumentIdRecursivelyWithNameToThinDocumentMap(
171 const std::vector<base::FilePath::StringType>& components, 203 const std::vector<base::FilePath::StringType>& components,
172 const ResolveToDocumentIdCallback& callback, 204 const ResolveToDocumentIdCallback& callback,
173 base::File::Error error, 205 base::File::Error error,
174 NameToThinDocumentMap mapping); 206 NameToThinDocumentMap mapping);
175 207
176 // Enumerates child documents of a directory specified by |document_id|. 208 // Enumerates child documents of a directory specified by |document_id|.
177 // The result is returned as a NameToThinDocumentMap. 209 // The result is returned as a NameToThinDocumentMap.
178 void ReadDirectoryInternal(const std::string& document_id, 210 void ReadDirectoryInternal(const std::string& document_id,
179 const ReadDirectoryInternalCallback& callback); 211 const ReadDirectoryInternalCallback& callback);
180 void ReadDirectoryInternalWithChildDocuments( 212 void ReadDirectoryInternalWithChildDocuments(
181 const ReadDirectoryInternalCallback& callback, 213 const ReadDirectoryInternalCallback& callback,
182 base::Optional<std::vector<mojom::DocumentPtr>> maybe_children); 214 base::Optional<std::vector<mojom::DocumentPtr>> maybe_children);
183 215
184 const std::string authority_; 216 const std::string authority_;
185 const std::string root_document_id_; 217 const std::string root_document_id_;
186 218
187 // Map from a file path to a watcher ID. 219 // Map from a file path to a watcher data.
188 //
189 // A watcher can be "orphan" when watchers are cleared as notified by
190 // OnWatchersCleared() callback. Such watchers are still tracked here,
191 // but they are not known by the remote service, so they are represented
192 // by the invalid watcher ID (-1).
193 // 220 //
194 // Note that we do not use a document ID as a key here to guarantee that 221 // Note that we do not use a document ID as a key here to guarantee that
195 // a watch installed by AddWatcher() can be always identified in 222 // a watch installed by AddWatcher() can be always identified in
196 // RemoveWatcher() with the same file path specified. 223 // RemoveWatcher() with the same file path specified.
197 // See the documentation of AddWatcher() for more details. 224 // See the documentation of AddWatcher() for more details.
198 std::map<base::FilePath, int64_t> path_to_watcher_id_; 225 std::map<base::FilePath, WatcherData> path_to_watcher_data_;
226
227 uint64_t next_watcher_request_id_ = 1;
199 228
200 // Can be null if this instance is not observing ArcFileSystemOperationRunner. 229 // Can be null if this instance is not observing ArcFileSystemOperationRunner.
201 // Observation is started on the first call of AddWatcher(). 230 // Observation is started on the first call of AddWatcher().
202 scoped_refptr<file_system_operation_runner_util::ObserverIOThreadWrapper> 231 scoped_refptr<file_system_operation_runner_util::ObserverIOThreadWrapper>
203 observer_wrapper_; 232 observer_wrapper_;
204 233
205 base::WeakPtrFactory<ArcDocumentsProviderRoot> weak_ptr_factory_; 234 base::WeakPtrFactory<ArcDocumentsProviderRoot> weak_ptr_factory_;
206 235
207 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot); 236 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot);
208 }; 237 };
209 238
210 } // namespace arc 239 } // namespace arc
211 240
212 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ 241 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698