Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_FILE_SYSTEM_OPERATION_RUNNER_UTI L_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_UTI L_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_UTI L_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_UTI L_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "components/arc/common/file_system.mojom.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h " | |
| 11 | 12 |
| 12 class GURL; | 13 class GURL; |
| 13 | 14 |
| 14 namespace arc { | 15 namespace arc { |
| 16 | |
| 17 // Wraps an ArcFileSystemOperationRunner::Observer so it is called on the IO | |
| 18 // thread. | |
| 19 class ObserverIOThreadWrapper | |
| 20 : public base::RefCountedThreadSafe<ObserverIOThreadWrapper>, | |
|
dcheng
2017/03/02 07:21:45
Reading through, I'm not quite sure why this is re
Shuhei Takahashi
2017/03/02 07:30:50
This object is refcounted because it does not stay
| |
| 21 public ArcFileSystemOperationRunner::Observer { | |
| 22 public: | |
| 23 explicit ObserverIOThreadWrapper( | |
| 24 ArcFileSystemOperationRunner::Observer* underlying_observer); | |
| 25 | |
| 26 // Disables the observer. After calling this function, the underlying observer | |
| 27 // will never be called. | |
| 28 // This function should be called on the IO thread. | |
| 29 void Disable(); | |
| 30 | |
| 31 // ArcFileSystemOperationRunner::Observer overrides: | |
| 32 void OnWatchersCleared() override; | |
| 33 | |
| 34 private: | |
| 35 friend class base::RefCountedThreadSafe<ObserverIOThreadWrapper>; | |
| 36 | |
| 37 ~ObserverIOThreadWrapper() override; | |
| 38 | |
| 39 void OnWatchersClearedOnIOThread(); | |
| 40 | |
| 41 ArcFileSystemOperationRunner::Observer* const underlying_observer_; | |
| 42 | |
| 43 // If set to true, |observer_| will not be called. This variable should be | |
| 44 // accessed only on the IO thread. | |
| 45 bool disabled_ = false; | |
| 46 | |
| 47 DISALLOW_COPY_AND_ASSIGN(ObserverIOThreadWrapper); | |
| 48 }; | |
| 49 | |
| 15 namespace file_system_operation_runner_util { | 50 namespace file_system_operation_runner_util { |
| 16 | 51 |
| 17 using GetFileSizeCallback = mojom::FileSystemInstance::GetFileSizeCallback; | 52 using GetFileSizeCallback = ArcFileSystemOperationRunner::GetFileSizeCallback; |
| 18 using OpenFileToReadCallback = | 53 using OpenFileToReadCallback = |
| 19 mojom::FileSystemInstance::OpenFileToReadCallback; | 54 ArcFileSystemOperationRunner::OpenFileToReadCallback; |
| 20 using GetDocumentCallback = mojom::FileSystemInstance::GetDocumentCallback; | 55 using GetDocumentCallback = ArcFileSystemOperationRunner::GetDocumentCallback; |
| 21 using GetChildDocumentsCallback = | 56 using GetChildDocumentsCallback = |
| 22 mojom::FileSystemInstance::GetChildDocumentsCallback; | 57 ArcFileSystemOperationRunner::GetChildDocumentsCallback; |
| 58 using AddWatcherCallback = ArcFileSystemOperationRunner::AddWatcherCallback; | |
| 59 using RemoveWatcherCallback = | |
| 60 ArcFileSystemOperationRunner::RemoveWatcherCallback; | |
| 61 using WatcherCallback = ArcFileSystemOperationRunner::WatcherCallback; | |
| 23 | 62 |
| 24 // Utility functions to post a task to run ArcFileSystemOperationRunner methods. | 63 // Utility functions to post a task to run ArcFileSystemOperationRunner methods. |
| 25 // These functions must be called on the IO thread. | 64 // These functions must be called on the IO thread. Callbacks and observers will |
| 65 // be called on the IO thread. | |
| 26 void GetFileSizeOnIOThread(const GURL& url, | 66 void GetFileSizeOnIOThread(const GURL& url, |
| 27 const GetFileSizeCallback& callback); | 67 const GetFileSizeCallback& callback); |
| 28 void OpenFileToReadOnIOThread(const GURL& url, | 68 void OpenFileToReadOnIOThread(const GURL& url, |
| 29 const OpenFileToReadCallback& callback); | 69 const OpenFileToReadCallback& callback); |
| 30 void GetDocumentOnIOThread(const std::string& authority, | 70 void GetDocumentOnIOThread(const std::string& authority, |
| 31 const std::string& document_id, | 71 const std::string& document_id, |
| 32 const GetDocumentCallback& callback); | 72 const GetDocumentCallback& callback); |
| 33 void GetChildDocumentsOnIOThread(const std::string& authority, | 73 void GetChildDocumentsOnIOThread(const std::string& authority, |
| 34 const std::string& parent_document_id, | 74 const std::string& parent_document_id, |
| 35 const GetChildDocumentsCallback& callback); | 75 const GetChildDocumentsCallback& callback); |
| 76 void AddWatcherOnIOThread(const std::string& authority, | |
| 77 const std::string& document_id, | |
| 78 const WatcherCallback& watcher_callback, | |
| 79 const AddWatcherCallback& callback); | |
| 80 void RemoveWatcherOnIOThread(int64_t watcher_id, | |
| 81 const RemoveWatcherCallback& callback); | |
| 82 void AddObserverOnIOThread(scoped_refptr<ObserverIOThreadWrapper> observer); | |
| 83 void RemoveObserverOnIOThread(scoped_refptr<ObserverIOThreadWrapper> observer); | |
| 36 | 84 |
| 37 } // namespace file_system_operation_runner_util | 85 } // namespace file_system_operation_runner_util |
| 38 } // namespace arc | 86 } // namespace arc |
| 39 | 87 |
| 40 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_ UTIL_H_ | 88 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_FILE_SYSTEM_OPERATION_RUNNER_ UTIL_H_ |
| OLD | NEW |