Skip to content

Commit

Permalink
mediaview: Implement ArcDocumentsProviderWatcherManager.
Browse files Browse the repository at this point in the history
ArcDocumentsProviderWatcherManager simply calls ArcDocumentsProviderRoot.

BUG=chromium:684233
TEST=trybot
TEST=Media view refreshes on media provider changes.

Review-Url: https://codereview.chromium.org/2709013003
Cr-Commit-Position: refs/heads/master@{#454598}
  • Loading branch information
nya3jp authored and Commit bot committed Mar 3, 2017
1 parent b41df0b commit 7b44260
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 3 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ source_set("chromeos") {
"arc/fileapi/arc_documents_provider_root_map.h",
"arc/fileapi/arc_documents_provider_util.cc",
"arc/fileapi/arc_documents_provider_util.h",
"arc/fileapi/arc_documents_provider_watcher_manager.cc",
"arc/fileapi/arc_documents_provider_watcher_manager.h",
"arc/fileapi/arc_file_system_mounter.cc",
"arc/fileapi/arc_file_system_mounter.h",
"arc/fileapi/arc_file_system_operation_runner.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using content::BrowserThread;
namespace arc {

ArcDocumentsProviderBackendDelegate::ArcDocumentsProviderBackendDelegate()
: async_file_util_(&roots_) {}
: async_file_util_(&roots_), watcher_manager_(&roots_) {}

ArcDocumentsProviderBackendDelegate::~ArcDocumentsProviderBackendDelegate() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
Expand Down Expand Up @@ -57,8 +57,7 @@ ArcDocumentsProviderBackendDelegate::CreateFileStreamWriter(
storage::WatcherManager* ArcDocumentsProviderBackendDelegate::GetWatcherManager(
storage::FileSystemType type) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
NOTREACHED(); // Non-watchable file system.
return nullptr;
return &watcher_manager_;
}

void ArcDocumentsProviderBackendDelegate::GetRedirectURLForContents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/macros.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_async_file_util.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_watcher_manager.h"
#include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h"

namespace arc {
Expand Down Expand Up @@ -42,6 +43,7 @@ class ArcDocumentsProviderBackendDelegate
private:
ArcDocumentsProviderRootMap roots_;
ArcDocumentsProviderAsyncFileUtil async_file_util_;
ArcDocumentsProviderWatcherManager watcher_manager_;

DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderBackendDelegate);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_watcher_manager.h"

#include "base/files/file.h"
#include "base/files/file_path.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.h"
#include "content/public/browser/browser_thread.h"
#include "storage/browser/fileapi/file_system_url.h"

using content::BrowserThread;
using storage::FileSystemURL;

namespace arc {

ArcDocumentsProviderWatcherManager::ArcDocumentsProviderWatcherManager(
ArcDocumentsProviderRootMap* roots)
: roots_(roots), weak_ptr_factory_(this) {}

ArcDocumentsProviderWatcherManager::~ArcDocumentsProviderWatcherManager() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
}

void ArcDocumentsProviderWatcherManager::AddWatcher(
const FileSystemURL& url,
bool recursive,
const StatusCallback& callback,
const NotificationCallback& notification_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

if (recursive) {
// Recursive watching is not supported.
callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
return;
}

base::FilePath path;
ArcDocumentsProviderRoot* root = roots_->ParseAndLookup(url, &path);
if (!root) {
callback.Run(base::File::FILE_ERROR_NOT_FOUND);
return;
}

root->AddWatcher(path, notification_callback, callback);
}

void ArcDocumentsProviderWatcherManager::RemoveWatcher(
const FileSystemURL& url,
bool recursive,
const StatusCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

if (recursive) {
// Recursive watching is not supported.
callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
return;
}

base::FilePath path;
ArcDocumentsProviderRoot* root = roots_->ParseAndLookup(url, &path);
if (!root) {
callback.Run(base::File::FILE_ERROR_NOT_FOUND);
return;
}

root->RemoveWatcher(path, callback);
}

} // namespace arc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_WATCHER_MANAGER_H_
#define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_WATCHER_MANAGER_H_

#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "storage/browser/fileapi/watcher_manager.h"

namespace arc {

class ArcDocumentsProviderRootMap;

// The implementation of storage::WatcherManager for ARC documents provider
// filesystem.
//
// Note that this WatcherManager is not always correct. See comments at
// ArcDocumentsProviderRoot::AddWatcher().
class ArcDocumentsProviderWatcherManager : public storage::WatcherManager {
public:
explicit ArcDocumentsProviderWatcherManager(
ArcDocumentsProviderRootMap* roots);
~ArcDocumentsProviderWatcherManager() override;

// storage::WatcherManager overrides.
void AddWatcher(const storage::FileSystemURL& url,
bool recursive,
const StatusCallback& callback,
const NotificationCallback& notification_callback) override;
void RemoveWatcher(const storage::FileSystemURL& url,
bool recursive,
const StatusCallback& callback) override;

private:
// Owned by ArcDocumentsProviderBackendDelegate.
ArcDocumentsProviderRootMap* const roots_;

base::WeakPtrFactory<ArcDocumentsProviderWatcherManager> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderWatcherManager);
};

} // namespace arc

#endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_WATCHER_MANAGER_H_
4 changes: 4 additions & 0 deletions chrome/browser/chromeos/fileapi/file_system_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stddef.h>

#include <memory>
#include <utility>

#include "base/command_line.h"
#include "base/logging.h"
Expand Down Expand Up @@ -301,6 +302,9 @@ storage::WatcherManager* FileSystemBackend::GetWatcherManager(
return mtp_delegate_->GetWatcherManager(type);
}

if (type == storage::kFileSystemTypeArcDocumentsProvider)
return arc_documents_provider_delegate_->GetWatcherManager(type);

// TODO(mtomasz): Add support for other backends.
return NULL;
}
Expand Down

0 comments on commit 7b44260

Please sign in to comment.