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 "base/guid.h" | |
7 #include "components/offline_pages/background/request_coordinator.h" | 8 #include "components/offline_pages/background/request_coordinator.h" |
8 #include "components/offline_pages/background/save_page_request.h" | 9 #include "components/offline_pages/background/save_page_request.h" |
10 #include "components/offline_pages/client_namespace_constants.h" | |
9 #include "components/offline_pages/downloads/offline_page_download_notifier.h" | 11 #include "components/offline_pages/downloads/offline_page_download_notifier.h" |
10 | 12 |
11 namespace offline_pages { | 13 namespace offline_pages { |
12 namespace { | 14 namespace { |
13 int kUserDataKey; // Only address is used. | 15 int kUserDataKey; // Only address is used. |
16 | |
17 bool IsVisibleInUI(const ClientId& client_id) { | |
Dmitry Titov
2016/08/30 16:35:09
Any reason not to make this function public static
dewittj
2016/08/30 16:52:24
Done.
| |
18 const std::string& name_space = client_id.name_space; | |
19 return (name_space == kAsyncNamespace || name_space == kDownloadNamespace) && | |
20 base::IsValidGUID(client_id.id); | |
21 } | |
22 | |
14 } // namespace | 23 } // namespace |
15 | 24 |
16 DownloadNotifyingObserver::DownloadNotifyingObserver( | 25 DownloadNotifyingObserver::DownloadNotifyingObserver( |
17 std::unique_ptr<OfflinePageDownloadNotifier> notifier) | 26 std::unique_ptr<OfflinePageDownloadNotifier> notifier) |
18 : notifier_(std::move(notifier)) {} | 27 : notifier_(std::move(notifier)) {} |
19 | 28 |
20 DownloadNotifyingObserver::~DownloadNotifyingObserver() {} | 29 DownloadNotifyingObserver::~DownloadNotifyingObserver() {} |
21 | 30 |
22 // static | 31 // static |
23 DownloadNotifyingObserver* DownloadNotifyingObserver::GetFromRequestCoordinator( | 32 DownloadNotifyingObserver* DownloadNotifyingObserver::GetFromRequestCoordinator( |
(...skipping 11 matching lines...) Expand all Loading... | |
35 DCHECK(notifier.get()); | 44 DCHECK(notifier.get()); |
36 DownloadNotifyingObserver* observer = | 45 DownloadNotifyingObserver* observer = |
37 new DownloadNotifyingObserver(std::move(notifier)); | 46 new DownloadNotifyingObserver(std::move(notifier)); |
38 request_coordinator->AddObserver(observer); | 47 request_coordinator->AddObserver(observer); |
39 // |request_coordinator| takes ownership of observer here. | 48 // |request_coordinator| takes ownership of observer here. |
40 request_coordinator->SetUserData(&kUserDataKey, observer); | 49 request_coordinator->SetUserData(&kUserDataKey, observer); |
41 } | 50 } |
42 | 51 |
43 void DownloadNotifyingObserver::OnAdded(const SavePageRequest& request) { | 52 void DownloadNotifyingObserver::OnAdded(const SavePageRequest& request) { |
44 DCHECK(notifier_.get()); | 53 DCHECK(notifier_.get()); |
54 if (!IsVisibleInUI(request.client_id())) | |
55 return; | |
45 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); | 56 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); |
46 } | 57 } |
47 | 58 |
48 void DownloadNotifyingObserver::OnChanged(const SavePageRequest& request) { | 59 void DownloadNotifyingObserver::OnChanged(const SavePageRequest& request) { |
49 DCHECK(notifier_.get()); | 60 DCHECK(notifier_.get()); |
61 if (!IsVisibleInUI(request.client_id())) | |
62 return; | |
50 if (request.request_state() == SavePageRequest::RequestState::PAUSED) | 63 if (request.request_state() == SavePageRequest::RequestState::PAUSED) |
51 notifier_->NotifyDownloadPaused(DownloadUIItem(request)); | 64 notifier_->NotifyDownloadPaused(DownloadUIItem(request)); |
52 else | 65 else |
53 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); | 66 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); |
54 } | 67 } |
55 | 68 |
56 void DownloadNotifyingObserver::OnCompleted( | 69 void DownloadNotifyingObserver::OnCompleted( |
57 const SavePageRequest& request, | 70 const SavePageRequest& request, |
58 RequestCoordinator::SavePageStatus status) { | 71 RequestCoordinator::SavePageStatus status) { |
59 DCHECK(notifier_.get()); | 72 DCHECK(notifier_.get()); |
73 if (!IsVisibleInUI(request.client_id())) | |
74 return; | |
60 if (status == RequestCoordinator::SavePageStatus::SUCCESS) | 75 if (status == RequestCoordinator::SavePageStatus::SUCCESS) |
61 notifier_->NotifyDownloadSuccessful(DownloadUIItem(request)); | 76 notifier_->NotifyDownloadSuccessful(DownloadUIItem(request)); |
62 else if (status == RequestCoordinator::SavePageStatus::REMOVED) | 77 else if (status == RequestCoordinator::SavePageStatus::REMOVED) |
63 notifier_->NotifyDownloadCanceled(DownloadUIItem(request)); | 78 notifier_->NotifyDownloadCanceled(DownloadUIItem(request)); |
64 else | 79 else |
65 notifier_->NotifyDownloadFailed(DownloadUIItem(request)); | 80 notifier_->NotifyDownloadFailed(DownloadUIItem(request)); |
66 } | 81 } |
67 } // namespace offline_pages | 82 } // namespace offline_pages |
OLD | NEW |