Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: components/offline_pages/downloads/download_notifying_observer.cc

Issue 2521353005: [OfflinePages] Call NotifyInterrupted for pending requests (Closed)
Patch Set: Fix indeterminate progress bar for Downloading... Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
40 std::move(notifier), request_coordinator->GetPolicyController()); 40 std::move(notifier), request_coordinator->GetPolicyController());
41 request_coordinator->AddObserver(observer); 41 request_coordinator->AddObserver(observer);
42 // |request_coordinator| takes ownership of observer here. 42 // |request_coordinator| takes ownership of observer here.
43 request_coordinator->SetUserData(&kUserDataKey, observer); 43 request_coordinator->SetUserData(&kUserDataKey, observer);
44 } 44 }
45 45
46 void DownloadNotifyingObserver::OnAdded(const SavePageRequest& request) { 46 void DownloadNotifyingObserver::OnAdded(const SavePageRequest& request) {
47 DCHECK(notifier_.get()); 47 DCHECK(notifier_.get());
48 if (!IsVisibleInUI(request.client_id())) 48 if (!IsVisibleInUI(request.client_id()))
49 return; 49 return;
50
51 // There is no Added call for the notifier so we perform a Progress call
fgorski 2016/11/29 17:50:59 nit: how about: Calling Progress ensures notificat
dougarnett 2016/11/29 20:43:30 Done.
52 // to cause the notification to be created.
50 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); 53 notifier_->NotifyDownloadProgress(DownloadUIItem(request));
54
55 // Now we need to update the notification if it is not active/offlining.
56 // TODO(dougarnett): Handle request state in notifier impl so this call
fgorski 2016/11/29 17:50:59 Why? If we do so, it will require double call for
dougarnett 2016/11/29 20:43:30 Removed TODO. The concern here was if we experienc
57 // is not needed.
58 if (request.request_state() != SavePageRequest::RequestState::OFFLINING)
59 NotifyRequestStateChange(request);
51 } 60 }
52 61
53 void DownloadNotifyingObserver::OnChanged(const SavePageRequest& request) { 62 void DownloadNotifyingObserver::OnChanged(const SavePageRequest& request) {
54 DCHECK(notifier_.get()); 63 DCHECK(notifier_.get());
55 if (!IsVisibleInUI(request.client_id())) 64 if (!IsVisibleInUI(request.client_id()))
56 return; 65 return;
57 if (request.request_state() == SavePageRequest::RequestState::PAUSED) 66 NotifyRequestStateChange(request);
58 notifier_->NotifyDownloadPaused(DownloadUIItem(request));
59 else
60 notifier_->NotifyDownloadProgress(DownloadUIItem(request));
61 } 67 }
62 68
63 void DownloadNotifyingObserver::OnCompleted( 69 void DownloadNotifyingObserver::OnCompleted(
64 const SavePageRequest& request, 70 const SavePageRequest& request,
65 RequestCoordinator::BackgroundSavePageResult status) { 71 RequestCoordinator::BackgroundSavePageResult status) {
66 DCHECK(notifier_.get()); 72 DCHECK(notifier_.get());
67 if (!IsVisibleInUI(request.client_id())) 73 if (!IsVisibleInUI(request.client_id()))
68 return; 74 return;
69 if (status == RequestCoordinator::BackgroundSavePageResult::SUCCESS) 75 if (status == RequestCoordinator::BackgroundSavePageResult::SUCCESS)
70 notifier_->NotifyDownloadSuccessful(DownloadUIItem(request)); 76 notifier_->NotifyDownloadSuccessful(DownloadUIItem(request));
71 else if (status == RequestCoordinator::BackgroundSavePageResult::REMOVED) 77 else if (status == RequestCoordinator::BackgroundSavePageResult::REMOVED)
72 notifier_->NotifyDownloadCanceled(DownloadUIItem(request)); 78 notifier_->NotifyDownloadCanceled(DownloadUIItem(request));
73 else 79 else
74 notifier_->NotifyDownloadFailed(DownloadUIItem(request)); 80 notifier_->NotifyDownloadFailed(DownloadUIItem(request));
75 } 81 }
76 82
77 bool DownloadNotifyingObserver::IsVisibleInUI(const ClientId& page) { 83 bool DownloadNotifyingObserver::IsVisibleInUI(const ClientId& page) {
78 return policy_controller_->IsSupportedByDownload(page.name_space) && 84 return policy_controller_->IsSupportedByDownload(page.name_space) &&
79 base::IsValidGUID(page.id); 85 base::IsValidGUID(page.id);
80 } 86 }
81 87
88 void DownloadNotifyingObserver::NotifyRequestStateChange(
fgorski 2016/11/29 17:50:59 Thanks for extracting this one. I think the overal
dougarnett 2016/11/29 20:43:30 Acknowledged.
89 const SavePageRequest& request) {
90 if (request.request_state() == SavePageRequest::RequestState::PAUSED)
91 notifier_->NotifyDownloadPaused(DownloadUIItem(request));
92 else if (request.request_state() == SavePageRequest::RequestState::AVAILABLE)
93 notifier_->NotifyDownloadInterrupted(DownloadUIItem(request));
94 else
95 notifier_->NotifyDownloadProgress(DownloadUIItem(request));
96 }
97
82 } // namespace offline_pages 98 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698