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/downloads/download_ui_adapter.h" |
9 #include "components/offline_pages/downloads/offline_page_download_notifier.h" | 10 #include "components/offline_pages/downloads/offline_page_download_notifier.h" |
10 | 11 |
11 namespace offline_pages { | 12 namespace offline_pages { |
12 namespace { | 13 namespace { |
13 int kUserDataKey; // Only address is used. | 14 int kUserDataKey; // Only address is used. |
14 } // namespace | 15 } // namespace |
15 | 16 |
16 DownloadNotifyingObserver::DownloadNotifyingObserver( | 17 DownloadNotifyingObserver::DownloadNotifyingObserver( |
17 std::unique_ptr<OfflinePageDownloadNotifier> notifier) | 18 std::unique_ptr<OfflinePageDownloadNotifier> notifier) |
18 : notifier_(std::move(notifier)) {} | 19 : notifier_(std::move(notifier)) {} |
(...skipping 16 matching lines...) Expand all Loading... |
35 DCHECK(notifier.get()); | 36 DCHECK(notifier.get()); |
36 DownloadNotifyingObserver* observer = | 37 DownloadNotifyingObserver* observer = |
37 new DownloadNotifyingObserver(std::move(notifier)); | 38 new DownloadNotifyingObserver(std::move(notifier)); |
38 request_coordinator->AddObserver(observer); | 39 request_coordinator->AddObserver(observer); |
39 // |request_coordinator| takes ownership of observer here. | 40 // |request_coordinator| takes ownership of observer here. |
40 request_coordinator->SetUserData(&kUserDataKey, observer); | 41 request_coordinator->SetUserData(&kUserDataKey, observer); |
41 } | 42 } |
42 | 43 |
43 void DownloadNotifyingObserver::OnAdded(const SavePageRequest& request) { | 44 void DownloadNotifyingObserver::OnAdded(const SavePageRequest& request) { |
44 DCHECK(notifier_.get()); | 45 DCHECK(notifier_.get()); |
| 46 if (!DownloadUIAdapter::IsVisibleInUI(request.client_id())) |
| 47 return; |
45 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); | 48 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); |
46 } | 49 } |
47 | 50 |
48 void DownloadNotifyingObserver::OnChanged(const SavePageRequest& request) { | 51 void DownloadNotifyingObserver::OnChanged(const SavePageRequest& request) { |
49 DCHECK(notifier_.get()); | 52 DCHECK(notifier_.get()); |
| 53 if (!DownloadUIAdapter::IsVisibleInUI(request.client_id())) |
| 54 return; |
50 if (request.request_state() == SavePageRequest::RequestState::PAUSED) | 55 if (request.request_state() == SavePageRequest::RequestState::PAUSED) |
51 notifier_->NotifyDownloadPaused(DownloadUIItem(request)); | 56 notifier_->NotifyDownloadPaused(DownloadUIItem(request)); |
52 else | 57 else |
53 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); | 58 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); |
54 } | 59 } |
55 | 60 |
56 void DownloadNotifyingObserver::OnCompleted( | 61 void DownloadNotifyingObserver::OnCompleted( |
57 const SavePageRequest& request, | 62 const SavePageRequest& request, |
58 RequestCoordinator::SavePageStatus status) { | 63 RequestCoordinator::SavePageStatus status) { |
59 DCHECK(notifier_.get()); | 64 DCHECK(notifier_.get()); |
| 65 if (!DownloadUIAdapter::IsVisibleInUI(request.client_id())) |
| 66 return; |
60 if (status == RequestCoordinator::SavePageStatus::SUCCESS) | 67 if (status == RequestCoordinator::SavePageStatus::SUCCESS) |
61 notifier_->NotifyDownloadSuccessful(DownloadUIItem(request)); | 68 notifier_->NotifyDownloadSuccessful(DownloadUIItem(request)); |
62 else if (status == RequestCoordinator::SavePageStatus::REMOVED) | 69 else if (status == RequestCoordinator::SavePageStatus::REMOVED) |
63 notifier_->NotifyDownloadCanceled(DownloadUIItem(request)); | 70 notifier_->NotifyDownloadCanceled(DownloadUIItem(request)); |
64 else | 71 else |
65 notifier_->NotifyDownloadFailed(DownloadUIItem(request)); | 72 notifier_->NotifyDownloadFailed(DownloadUIItem(request)); |
66 } | 73 } |
67 } // namespace offline_pages | 74 } // namespace offline_pages |
OLD | NEW |