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_ARC_DOWNLOADS_WATCHER_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_DOWNLOADS_WATCHER_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_DOWNLOADS_WATCHER_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_DOWNLOADS_WATCHER_SERVICE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "components/arc/arc_bridge_service.h" | 13 #include "components/arc/arc_bridge_service.h" |
14 #include "components/arc/arc_service.h" | 14 #include "components/arc/arc_service.h" |
| 15 #include "components/arc/instance_holder.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class FilePath; | 18 class FilePath; |
18 } | 19 } |
19 | 20 |
20 namespace arc { | 21 namespace arc { |
21 | 22 |
22 // Watches Downloads directory and registers newly created media files to | 23 // Watches Downloads directory and registers newly created media files to |
23 // Android MediaProvider. | 24 // Android MediaProvider. |
24 class ArcDownloadsWatcherService : public ArcService, | 25 class ArcDownloadsWatcherService |
25 public ArcBridgeService::Observer { | 26 : public ArcService, |
| 27 public InstanceHolder<mojom::FileSystemInstance>::Observer { |
26 public: | 28 public: |
27 explicit ArcDownloadsWatcherService(ArcBridgeService* bridge_service); | 29 explicit ArcDownloadsWatcherService(ArcBridgeService* bridge_service); |
28 ~ArcDownloadsWatcherService() override; | 30 ~ArcDownloadsWatcherService() override; |
29 | 31 |
30 // ArcBridgeService::Observer | 32 // InstanceHolder<mojom::FileSystemInstance>::Observer |
31 void OnFileSystemInstanceReady() override; | 33 void OnInstanceReady() override; |
32 void OnFileSystemInstanceClosed() override; | 34 void OnInstanceClosed() override; |
33 | 35 |
34 private: | 36 private: |
35 class DownloadsWatcher; | 37 class DownloadsWatcher; |
36 | 38 |
37 void StartWatchingDownloads(); | 39 void StartWatchingDownloads(); |
38 void StopWatchingDownloads(); | 40 void StopWatchingDownloads(); |
39 | 41 |
40 void OnDownloadsChanged(const std::vector<base::FilePath>& paths); | 42 void OnDownloadsChanged(const std::vector<base::FilePath>& paths); |
41 | 43 |
42 std::unique_ptr<DownloadsWatcher> watcher_; | 44 std::unique_ptr<DownloadsWatcher> watcher_; |
43 | 45 |
44 // Note: This should remain the last member so it'll be destroyed and | 46 // Note: This should remain the last member so it'll be destroyed and |
45 // invalidate the weak pointers before any other members are destroyed. | 47 // invalidate the weak pointers before any other members are destroyed. |
46 base::WeakPtrFactory<ArcDownloadsWatcherService> weak_ptr_factory_; | 48 base::WeakPtrFactory<ArcDownloadsWatcherService> weak_ptr_factory_; |
47 | 49 |
48 DISALLOW_COPY_AND_ASSIGN(ArcDownloadsWatcherService); | 50 DISALLOW_COPY_AND_ASSIGN(ArcDownloadsWatcherService); |
49 }; | 51 }; |
50 | 52 |
51 } // namespace arc | 53 } // namespace arc |
52 | 54 |
53 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_DOWNLOADS_WATCHER_SERVICE_H_ | 55 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_DOWNLOADS_WATCHER_SERVICE_H_ |
OLD | NEW |