| 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 "components/offline_pages/downloads/download_notifying_observer.h" | 5 #include "components/offline_pages/downloads/download_notifying_observer.h" |
| 6 | 6 |
| 7 #include "components/offline_pages/background/request_coordinator.h" | 7 #include "components/offline_pages/background/request_coordinator.h" |
| 8 #include "components/offline_pages/background/save_page_request.h" | 8 #include "components/offline_pages/background/save_page_request.h" |
| 9 #include "components/offline_pages/client_policy_controller.h" | 9 #include "components/offline_pages/client_policy_controller.h" |
| 10 #include "components/offline_pages/downloads/download_ui_adapter.h" | 10 #include "components/offline_pages/downloads/download_ui_adapter.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return; | 49 return; |
| 50 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); | 50 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void DownloadNotifyingObserver::OnChanged(const SavePageRequest& request) { | 53 void DownloadNotifyingObserver::OnChanged(const SavePageRequest& request) { |
| 54 DCHECK(notifier_.get()); | 54 DCHECK(notifier_.get()); |
| 55 if (!IsVisibleInUI(request.client_id())) | 55 if (!IsVisibleInUI(request.client_id())) |
| 56 return; | 56 return; |
| 57 if (request.request_state() == SavePageRequest::RequestState::PAUSED) | 57 if (request.request_state() == SavePageRequest::RequestState::PAUSED) |
| 58 notifier_->NotifyDownloadPaused(DownloadUIItem(request)); | 58 notifier_->NotifyDownloadPaused(DownloadUIItem(request)); |
| 59 else if (request.request_state() == SavePageRequest::RequestState::AVAILABLE) |
| 60 notifier_->NotifyDownloadInterrupted(DownloadUIItem(request)); |
| 59 else | 61 else |
| 60 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); | 62 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void DownloadNotifyingObserver::OnCompleted( | 65 void DownloadNotifyingObserver::OnCompleted( |
| 64 const SavePageRequest& request, | 66 const SavePageRequest& request, |
| 65 RequestCoordinator::BackgroundSavePageResult status) { | 67 RequestCoordinator::BackgroundSavePageResult status) { |
| 66 DCHECK(notifier_.get()); | 68 DCHECK(notifier_.get()); |
| 67 if (!IsVisibleInUI(request.client_id())) | 69 if (!IsVisibleInUI(request.client_id())) |
| 68 return; | 70 return; |
| 69 if (status == RequestCoordinator::BackgroundSavePageResult::SUCCESS) | 71 if (status == RequestCoordinator::BackgroundSavePageResult::SUCCESS) |
| 70 notifier_->NotifyDownloadSuccessful(DownloadUIItem(request)); | 72 notifier_->NotifyDownloadSuccessful(DownloadUIItem(request)); |
| 71 else if (status == RequestCoordinator::BackgroundSavePageResult::REMOVED) | 73 else if (status == RequestCoordinator::BackgroundSavePageResult::REMOVED) |
| 72 notifier_->NotifyDownloadCanceled(DownloadUIItem(request)); | 74 notifier_->NotifyDownloadCanceled(DownloadUIItem(request)); |
| 73 else | 75 else |
| 74 notifier_->NotifyDownloadFailed(DownloadUIItem(request)); | 76 notifier_->NotifyDownloadFailed(DownloadUIItem(request)); |
| 75 } | 77 } |
| 76 | 78 |
| 77 bool DownloadNotifyingObserver::IsVisibleInUI(const ClientId& page) { | 79 bool DownloadNotifyingObserver::IsVisibleInUI(const ClientId& page) { |
| 78 return policy_controller_->IsSupportedByDownload(page.name_space) && | 80 return policy_controller_->IsSupportedByDownload(page.name_space) && |
| 79 base::IsValidGUID(page.id); | 81 base::IsValidGUID(page.id); |
| 80 } | 82 } |
| 81 | 83 |
| 82 } // namespace offline_pages | 84 } // namespace offline_pages |
| OLD | NEW |