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

Unified Diff: chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.cc

Issue 2574173002: mediaview: Implement ArcDocumentsProviderRoot. (Closed)
Patch Set: Addressed hashimoto's comments. Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.cc
diff --git a/chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.cc b/chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.cc
index c2b4deba99e804f1112892774f0a942a41304837..6eb069e4097eb970f0c42a46df6eb6f624c6a68e 100644
--- a/chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.cc
+++ b/chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.cc
@@ -5,12 +5,17 @@
#include "chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.h"
#include <string>
+#include <utility>
+#include <vector>
+#include "base/optional.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_service_manager.h"
#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
+using content::BrowserThread;
+
namespace arc {
namespace file_system_instance_util {
@@ -19,13 +24,15 @@ namespace {
constexpr uint32_t kGetFileSizeVersion = 1;
constexpr uint32_t kOpenFileToReadVersion = 1;
+constexpr uint32_t kGetDocumentVersion = 2;
+constexpr uint32_t kGetChildDocumentsVersion = 2;
// Returns FileSystemInstance for the given |min_version|, if found.
// Otherwise, nullptr.
mojom::FileSystemInstance* GetFileSystemInstance(
const std::string& method_name_for_logging,
uint32_t min_version) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto* arc_service_manager = arc::ArcServiceManager::Get();
if (!arc_service_manager) {
LOG(ERROR) << "Failed to get ArcServiceManager.";
@@ -36,61 +43,106 @@ mojom::FileSystemInstance* GetFileSystemInstance(
->GetInstanceForMethod(method_name_for_logging, min_version);
}
-void OnGetFileSize(const GetFileSizeCallback& callback, int64_t size) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
- base::Bind(callback, size));
+template <typename T>
+void PostToIOThread(const base::Callback<void(T)>& callback, T result) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, base::Passed(std::move(result))));
}
void GetFileSizeOnUIThread(const GURL& arc_url,
const GetFileSizeCallback& callback) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto* file_system_instance =
GetFileSystemInstance("GetFileSize", kGetFileSizeVersion);
if (!file_system_instance) {
- OnGetFileSize(callback, -1);
+ callback.Run(-1);
return;
}
- file_system_instance->GetFileSize(arc_url.spec(),
- base::Bind(&OnGetFileSize, callback));
-}
-
-void OnOpenFileToRead(const OpenFileToReadCallback& callback,
- mojo::ScopedHandle handle) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
- base::Bind(callback, base::Passed(&handle)));
+ file_system_instance->GetFileSize(arc_url.spec(), callback);
}
void OpenFileToReadOnUIThread(const GURL& arc_url,
const OpenFileToReadCallback& callback) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto* file_system_instance =
GetFileSystemInstance("OpenFileToRead", kOpenFileToReadVersion);
if (!file_system_instance) {
- OnOpenFileToRead(callback, mojo::ScopedHandle());
+ callback.Run(mojo::ScopedHandle());
+ return;
+ }
+ file_system_instance->OpenFileToRead(arc_url.spec(), callback);
+}
+
+void GetDocumentOnUIThread(const std::string& authority,
+ const std::string& document_id,
+ const GetDocumentCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ auto* file_system_instance =
+ GetFileSystemInstance("GetDocument", kGetDocumentVersion);
+ if (!file_system_instance) {
+ callback.Run(mojom::DocumentPtr());
return;
}
- file_system_instance->OpenFileToRead(arc_url.spec(),
- base::Bind(&OnOpenFileToRead, callback));
+ file_system_instance->GetDocument(authority, document_id, callback);
+}
+
+void GetChildDocumentsOnUIThread(const std::string& authority,
+ const std::string& parent_document_id,
+ const GetChildDocumentsCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ auto* file_system_instance =
+ GetFileSystemInstance("GetChildDocuments", kGetChildDocumentsVersion);
+ if (!file_system_instance) {
+ callback.Run(base::nullopt);
+ return;
+ }
+ file_system_instance->GetChildDocuments(authority, parent_document_id,
+ callback);
}
} // namespace
void GetFileSizeOnIOThread(const GURL& arc_url,
const GetFileSizeCallback& callback) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(&GetFileSizeOnUIThread, arc_url, callback));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&GetFileSizeOnUIThread, arc_url,
+ base::Bind(&PostToIOThread<int64_t>, callback)));
}
void OpenFileToReadOnIOThread(const GURL& arc_url,
const OpenFileToReadCallback& callback) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(&OpenFileToReadOnUIThread, arc_url, callback));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&OpenFileToReadOnUIThread, arc_url,
+ base::Bind(&PostToIOThread<mojo::ScopedHandle>, callback)));
+}
+
+void GetDocumentOnIOThread(const std::string& authority,
+ const std::string& document_id,
+ const GetDocumentCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&GetDocumentOnUIThread, authority, document_id,
+ base::Bind(&PostToIOThread<mojom::DocumentPtr>, callback)));
+}
+
+void GetChildDocumentsOnIOThread(const std::string& authority,
+ const std::string& parent_document_id,
+ const GetChildDocumentsCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ &GetChildDocumentsOnUIThread, authority, parent_document_id,
+ base::Bind(
+ &PostToIOThread<base::Optional<std::vector<mojom::DocumentPtr>>>,
+ callback)));
}
} // namespace file_system_instance_util
« no previous file with comments | « chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698