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 #include "chrome/browser/chromeos/arc/arc_downloads_watcher_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_downloads_watcher_service.h" |
6 | 6 |
| 7 #include <map> |
7 #include <memory> | 8 #include <memory> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/files/file_path_watcher.h" | 14 #include "base/files/file_path_watcher.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "chrome/browser/download/download_prefs.h" | 17 #include "chrome/browser/download/download_prefs.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 const base::FileEnumerator::FileInfo& info = enumerator.GetInfo(); | 169 const base::FileEnumerator::FileInfo& info = enumerator.GetInfo(); |
169 timestamp_map[android_path] = info.GetLastModifiedTime(); | 170 timestamp_map[android_path] = info.GetLastModifiedTime(); |
170 } | 171 } |
171 return timestamp_map; | 172 return timestamp_map; |
172 } | 173 } |
173 | 174 |
174 ArcDownloadsWatcherService::ArcDownloadsWatcherService( | 175 ArcDownloadsWatcherService::ArcDownloadsWatcherService( |
175 ArcBridgeService* bridge_service) | 176 ArcBridgeService* bridge_service) |
176 : ArcService(bridge_service), weak_ptr_factory_(this) { | 177 : ArcService(bridge_service), weak_ptr_factory_(this) { |
177 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 178 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
178 arc_bridge_service()->AddObserver(this); | 179 arc_bridge_service()->file_system()->AddObserver(this); |
179 } | 180 } |
180 | 181 |
181 ArcDownloadsWatcherService::~ArcDownloadsWatcherService() { | 182 ArcDownloadsWatcherService::~ArcDownloadsWatcherService() { |
182 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 183 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
183 arc_bridge_service()->RemoveObserver(this); | 184 arc_bridge_service()->file_system()->RemoveObserver(this); |
184 StopWatchingDownloads(); | 185 StopWatchingDownloads(); |
185 DCHECK(!watcher_.get()); | 186 DCHECK(!watcher_.get()); |
186 } | 187 } |
187 | 188 |
188 void ArcDownloadsWatcherService::OnFileSystemInstanceReady() { | 189 void ArcDownloadsWatcherService::OnInstanceReady(mojom::FileSystemInstance*, |
| 190 uint32_t version) { |
189 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 191 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
190 StartWatchingDownloads(); | 192 StartWatchingDownloads(); |
191 } | 193 } |
192 | 194 |
193 void ArcDownloadsWatcherService::OnFileSystemInstanceClosed() { | 195 void ArcDownloadsWatcherService::OnInstanceClosed(mojom::FileSystemInstance*) { |
194 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 196 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
195 StopWatchingDownloads(); | 197 StopWatchingDownloads(); |
196 } | 198 } |
197 | 199 |
198 void ArcDownloadsWatcherService::StartWatchingDownloads() { | 200 void ArcDownloadsWatcherService::StartWatchingDownloads() { |
199 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 201 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
200 StopWatchingDownloads(); | 202 StopWatchingDownloads(); |
201 DCHECK(!watcher_.get()); | 203 DCHECK(!watcher_.get()); |
202 watcher_ = base::MakeUnique<DownloadsWatcher>( | 204 watcher_ = base::MakeUnique<DownloadsWatcher>( |
203 base::Bind(&ArcDownloadsWatcherService::OnDownloadsChanged, | 205 base::Bind(&ArcDownloadsWatcherService::OnDownloadsChanged, |
204 weak_ptr_factory_.GetWeakPtr())); | 206 weak_ptr_factory_.GetWeakPtr())); |
205 BrowserThread::PostTask( | 207 BrowserThread::PostTask( |
206 BrowserThread::FILE, FROM_HERE, | 208 BrowserThread::FILE, FROM_HERE, |
207 base::Bind(&DownloadsWatcher::Start, base::Unretained(watcher_.get()))); | 209 base::Bind(&DownloadsWatcher::Start, base::Unretained(watcher_.get()))); |
208 } | 210 } |
209 | 211 |
210 void ArcDownloadsWatcherService::StopWatchingDownloads() { | 212 void ArcDownloadsWatcherService::StopWatchingDownloads() { |
211 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 213 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
212 if (watcher_.get()) { | 214 if (watcher_.get()) { |
213 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, | 215 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, |
214 watcher_.release()); | 216 watcher_.release()); |
215 } | 217 } |
216 } | 218 } |
217 | 219 |
218 void ArcDownloadsWatcherService::OnDownloadsChanged( | 220 void ArcDownloadsWatcherService::OnDownloadsChanged( |
219 const std::vector<base::FilePath>& paths) { | 221 const std::vector<base::FilePath>& paths) { |
220 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 222 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
221 | 223 |
222 auto instance = arc_bridge_service()->file_system_instance(); | 224 auto instance = arc_bridge_service()->file_system()->instance(); |
223 if (!instance) { | 225 if (!instance) { |
224 return; | 226 return; |
225 } | 227 } |
226 | 228 |
227 mojo::Array<mojo::String> mojo_paths(paths.size()); | 229 mojo::Array<mojo::String> mojo_paths(paths.size()); |
228 for (size_t i = 0; i < paths.size(); ++i) { | 230 for (size_t i = 0; i < paths.size(); ++i) { |
229 mojo_paths[i] = paths[i].value(); | 231 mojo_paths[i] = paths[i].value(); |
230 } | 232 } |
231 instance->RequestMediaScan(std::move(mojo_paths)); | 233 instance->RequestMediaScan(std::move(mojo_paths)); |
232 } | 234 } |
233 | 235 |
234 } // namespace arc | 236 } // namespace arc |
OLD | NEW |