| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_DOWNLOADS_WATCHER_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_DOWNLOADS_WATCHER_SERVICE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "components/arc/arc_service.h" | |
| 13 #include "components/arc/common/file_system.mojom.h" | |
| 14 #include "components/arc/instance_holder.h" | |
| 15 #include "mojo/public/cpp/bindings/array.h" | |
| 16 #include "mojo/public/cpp/bindings/string.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class FilePath; | |
| 20 } // namespace base | |
| 21 | |
| 22 namespace arc { | |
| 23 | |
| 24 class ArcBridgeService; | |
| 25 | |
| 26 // Returns true if the file path has a media extension supported by Android. | |
| 27 bool HasAndroidSupportedMediaExtension(const base::FilePath& path); | |
| 28 | |
| 29 // Watches Downloads directory and registers newly created media files to | |
| 30 // Android MediaProvider. | |
| 31 class ArcDownloadsWatcherService | |
| 32 : public ArcService, | |
| 33 public InstanceHolder<mojom::FileSystemInstance>::Observer { | |
| 34 public: | |
| 35 explicit ArcDownloadsWatcherService(ArcBridgeService* bridge_service); | |
| 36 ~ArcDownloadsWatcherService() override; | |
| 37 | |
| 38 // InstanceHolder<mojom::FileSystemInstance>::Observer | |
| 39 void OnInstanceReady() override; | |
| 40 void OnInstanceClosed() override; | |
| 41 | |
| 42 private: | |
| 43 class DownloadsWatcher; | |
| 44 | |
| 45 void StartWatchingDownloads(); | |
| 46 void StopWatchingDownloads(); | |
| 47 | |
| 48 void OnDownloadsChanged(mojo::Array<mojo::String> paths); | |
| 49 | |
| 50 std::unique_ptr<DownloadsWatcher> watcher_; | |
| 51 | |
| 52 // Note: This should remain the last member so it'll be destroyed and | |
| 53 // invalidate the weak pointers before any other members are destroyed. | |
| 54 base::WeakPtrFactory<ArcDownloadsWatcherService> weak_ptr_factory_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(ArcDownloadsWatcherService); | |
| 57 }; | |
| 58 | |
| 59 } // namespace arc | |
| 60 | |
| 61 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_DOWNLOADS_WATCHER_SERVICE_H_ | |
| OLD | NEW |