| 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() { |
| 189 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 190 StartWatchingDownloads(); | 191 StartWatchingDownloads(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 void ArcDownloadsWatcherService::OnFileSystemInstanceClosed() { | 194 void ArcDownloadsWatcherService::OnInstanceClosed() { |
| 194 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 195 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 195 StopWatchingDownloads(); | 196 StopWatchingDownloads(); |
| 196 } | 197 } |
| 197 | 198 |
| 198 void ArcDownloadsWatcherService::StartWatchingDownloads() { | 199 void ArcDownloadsWatcherService::StartWatchingDownloads() { |
| 199 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 200 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 200 StopWatchingDownloads(); | 201 StopWatchingDownloads(); |
| 201 DCHECK(!watcher_.get()); | 202 DCHECK(!watcher_.get()); |
| 202 watcher_ = base::MakeUnique<DownloadsWatcher>( | 203 watcher_ = base::MakeUnique<DownloadsWatcher>( |
| 203 base::Bind(&ArcDownloadsWatcherService::OnDownloadsChanged, | 204 base::Bind(&ArcDownloadsWatcherService::OnDownloadsChanged, |
| 204 weak_ptr_factory_.GetWeakPtr())); | 205 weak_ptr_factory_.GetWeakPtr())); |
| 205 BrowserThread::PostTask( | 206 BrowserThread::PostTask( |
| 206 BrowserThread::FILE, FROM_HERE, | 207 BrowserThread::FILE, FROM_HERE, |
| 207 base::Bind(&DownloadsWatcher::Start, base::Unretained(watcher_.get()))); | 208 base::Bind(&DownloadsWatcher::Start, base::Unretained(watcher_.get()))); |
| 208 } | 209 } |
| 209 | 210 |
| 210 void ArcDownloadsWatcherService::StopWatchingDownloads() { | 211 void ArcDownloadsWatcherService::StopWatchingDownloads() { |
| 211 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 212 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 212 if (watcher_.get()) { | 213 if (watcher_.get()) { |
| 213 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, | 214 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, |
| 214 watcher_.release()); | 215 watcher_.release()); |
| 215 } | 216 } |
| 216 } | 217 } |
| 217 | 218 |
| 218 void ArcDownloadsWatcherService::OnDownloadsChanged( | 219 void ArcDownloadsWatcherService::OnDownloadsChanged( |
| 219 const std::vector<base::FilePath>& paths) { | 220 const std::vector<base::FilePath>& paths) { |
| 220 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 221 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 221 | 222 |
| 222 auto instance = arc_bridge_service()->file_system_instance(); | 223 auto instance = arc_bridge_service()->file_system()->instance(); |
| 223 if (!instance) { | 224 if (!instance) { |
| 224 return; | 225 return; |
| 225 } | 226 } |
| 226 | 227 |
| 227 mojo::Array<mojo::String> mojo_paths(paths.size()); | 228 mojo::Array<mojo::String> mojo_paths(paths.size()); |
| 228 for (size_t i = 0; i < paths.size(); ++i) { | 229 for (size_t i = 0; i < paths.size(); ++i) { |
| 229 mojo_paths[i] = paths[i].value(); | 230 mojo_paths[i] = paths[i].value(); |
| 230 } | 231 } |
| 231 instance->RequestMediaScan(std::move(mojo_paths)); | 232 instance->RequestMediaScan(std::move(mojo_paths)); |
| 232 } | 233 } |
| 233 | 234 |
| 234 } // namespace arc | 235 } // namespace arc |
| OLD | NEW |