Commit bd848fec authored by Risan's avatar Risan Committed by Commit Bot

Generalize ArcDownloadsWatcher for custom filepath

Currently, ArcDownloadsWatcher is used to watch only Downloads directory
in ChromeOS and triggers MediaScanner.scanFile when important file
changes events happen (for example, file creation, deletion, etc).

In exact same way, we want to watch changes under removable media. This
CL generalize ArcDownloadsWatcher to watch both paths.

BUG=b:69078137
TEST=existing unit test and manually observe logs during runtime

Change-Id: I9adce1964eb6b23c2e83ead8462b7a1d8985ae4a
Reviewed-on: https://chromium-review.googlesource.com/c/1288160
Commit-Queue: Risan <risan@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Reviewed-by: default avatarShuhei Takahashi <nya@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601802}
parent d8749fca
......@@ -404,14 +404,14 @@ source_set("chromeos") {
"arc/boot_phase_monitor/arc_instance_throttle.h",
"arc/cast_receiver/arc_cast_receiver_service.cc",
"arc/cast_receiver/arc_cast_receiver_service.h",
"arc/downloads_watcher/arc_downloads_watcher_service.cc",
"arc/downloads_watcher/arc_downloads_watcher_service.h",
"arc/enterprise/arc_cert_store_bridge.cc",
"arc/enterprise/arc_cert_store_bridge.h",
"arc/enterprise/arc_enterprise_reporting_service.cc",
"arc/enterprise/arc_enterprise_reporting_service.h",
"arc/extensions/arc_support_message_host.cc",
"arc/extensions/arc_support_message_host.h",
"arc/file_system_watcher/arc_file_system_watcher_service.cc",
"arc/file_system_watcher/arc_file_system_watcher_service.h",
"arc/fileapi/arc_content_file_system_async_file_util.cc",
"arc/fileapi/arc_content_file_system_async_file_util.h",
"arc/fileapi/arc_content_file_system_backend_delegate.cc",
......@@ -2053,8 +2053,8 @@ source_set("unit_tests") {
"arc/bluetooth/arc_bluetooth_bridge_unittest.cc",
"arc/bluetooth/arc_bluetooth_task_queue_unittest.cc",
"arc/boot_phase_monitor/arc_boot_phase_monitor_bridge_unittest.cc",
"arc/downloads_watcher/arc_downloads_watcher_service_unittest.cc",
"arc/extensions/arc_support_message_host_unittest.cc",
"arc/file_system_watcher/arc_file_system_watcher_service_unittest.cc",
"arc/fileapi/arc_content_file_system_async_file_util_unittest.cc",
"arc/fileapi/arc_content_file_system_file_stream_reader_unittest.cc",
"arc/fileapi/arc_content_file_system_url_util_unittest.cc",
......
......@@ -18,9 +18,9 @@
#include "chrome/browser/chromeos/arc/bluetooth/arc_bluetooth_bridge.h"
#include "chrome/browser/chromeos/arc/boot_phase_monitor/arc_boot_phase_monitor_bridge.h"
#include "chrome/browser/chromeos/arc/cast_receiver/arc_cast_receiver_service.h"
#include "chrome/browser/chromeos/arc/downloads_watcher/arc_downloads_watcher_service.h"
#include "chrome/browser/chromeos/arc/enterprise/arc_cert_store_bridge.h"
#include "chrome/browser/chromeos/arc/enterprise/arc_enterprise_reporting_service.h"
#include "chrome/browser/chromeos/arc/file_system_watcher/arc_file_system_watcher_service.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_file_system_bridge.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_file_system_mounter.h"
#include "chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_service.h"
......@@ -163,10 +163,10 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) {
ArcClipboardBridge::GetForBrowserContext(profile);
ArcCrashCollectorBridge::GetForBrowserContext(profile);
ArcDiskQuotaBridge::GetForBrowserContext(profile);
ArcDownloadsWatcherService::GetForBrowserContext(profile);
ArcEnterpriseReportingService::GetForBrowserContext(profile);
ArcFileSystemBridge::GetForBrowserContext(profile);
ArcFileSystemMounter::GetForBrowserContext(profile);
ArcFileSystemWatcherService::GetForBrowserContext(profile);
ArcImeService::GetForBrowserContext(profile);
ArcInputMethodManagerService::GetForBrowserContext(profile);
ArcIntentHelperBridge::GetForBrowserContext(profile);
......
......@@ -2,8 +2,8 @@
// 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_DOWNLOADS_WATCHER_ARC_DOWNLOADS_WATCHER_SERVICE_H_
#define CHROME_BROWSER_CHROMEOS_ARC_DOWNLOADS_WATCHER_ARC_DOWNLOADS_WATCHER_SERVICE_H_
#ifndef CHROME_BROWSER_CHROMEOS_ARC_FILE_SYSTEM_WATCHER_ARC_FILE_SYSTEM_WATCHER_SERVICE_H_
#define CHROME_BROWSER_CHROMEOS_ARC_FILE_SYSTEM_WATCHER_ARC_FILE_SYSTEM_WATCHER_SERVICE_H_
#include <memory>
#include <string>
......@@ -36,47 +36,49 @@ bool HasAndroidSupportedMediaExtension(const base::FilePath& path);
extern const char* kAndroidSupportedMediaExtensions[];
extern const int kAndroidSupportedMediaExtensionsSize;
// Watches Downloads directory and registers newly created media files to
// Watches file system directories and registers newly created media files to
// Android MediaProvider.
class ArcDownloadsWatcherService
class ArcFileSystemWatcherService
: public KeyedService,
public ConnectionObserver<mojom::FileSystemInstance> {
public:
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
static ArcDownloadsWatcherService* GetForBrowserContext(
static ArcFileSystemWatcherService* GetForBrowserContext(
content::BrowserContext* context);
ArcDownloadsWatcherService(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~ArcDownloadsWatcherService() override;
ArcFileSystemWatcherService(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~ArcFileSystemWatcherService() override;
// ConnectionObserver<mojom::FileSystemInstance> overrides.
void OnConnectionReady() override;
void OnConnectionClosed() override;
private:
class DownloadsWatcher;
class FileSystemWatcher;
void StartWatchingDownloads();
void StopWatchingDownloads();
void StartWatchingFileSystem();
void StopWatchingFileSystem();
void OnDownloadsChanged(const std::vector<std::string>& paths);
void OnFileSystemChanged(const std::vector<std::string>& paths);
content::BrowserContext* const context_;
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
std::unique_ptr<DownloadsWatcher> watcher_;
std::unique_ptr<FileSystemWatcher> downloads_watcher_;
std::unique_ptr<FileSystemWatcher> removable_media_watcher_;
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
// Note: This should remain the last member so it'll be destroyed and
// invalidate the weak pointers before any other members are destroyed.
base::WeakPtrFactory<ArcDownloadsWatcherService> weak_ptr_factory_;
base::WeakPtrFactory<ArcFileSystemWatcherService> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ArcDownloadsWatcherService);
DISALLOW_COPY_AND_ASSIGN(ArcFileSystemWatcherService);
};
} // namespace arc
#endif // CHROME_BROWSER_CHROMEOS_ARC_DOWNLOADS_WATCHER_ARC_DOWNLOADS_WATCHER_SERVICE_H_
#endif // CHROME_BROWSER_CHROMEOS_ARC_FILE_SYSTEM_WATCHER_ARC_FILE_SYSTEM_WATCHER_SERVICE_H_
......@@ -2,7 +2,7 @@
// 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/downloads_watcher/arc_downloads_watcher_service.h"
#include "chrome/browser/chromeos/arc/file_system_watcher/arc_file_system_watcher_service.h"
#include <string.h>
......@@ -13,7 +13,7 @@
namespace arc {
TEST(ArcDownloadsWatcherServiceTest, AndroidSupportedMediaExtensionsSorted) {
TEST(ArcFileSystemWatcherServiceTest, AndroidSupportedMediaExtensionsSorted) {
const auto less_comparator = [](const char* a, const char* b) {
return strcmp(a, b) < 0;
};
......@@ -23,7 +23,7 @@ TEST(ArcDownloadsWatcherServiceTest, AndroidSupportedMediaExtensionsSorted) {
less_comparator));
}
TEST(ArcDownloadsWatcherServiceTest, HasAndroidSupportedMediaExtension) {
TEST(ArcFileSystemWatcherServiceTest, HasAndroidSupportedMediaExtension) {
EXPECT_TRUE(HasAndroidSupportedMediaExtension(
base::FilePath(FILE_PATH_LITERAL("/tmp/kitten.3g2"))));
EXPECT_TRUE(HasAndroidSupportedMediaExtension(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment