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

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

Issue 2848703004: Switch SupportsUserData uses to use unique_ptr. (Closed)
Patch Set: rev Created 3 years, 7 months 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/core/downloads/download_notifying_observer.h" 5 #include "components/offline_pages/core/downloads/download_notifying_observer.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "components/offline_pages/core/background/request_coordinator.h" 8 #include "components/offline_pages/core/background/request_coordinator.h"
8 #include "components/offline_pages/core/background/save_page_request.h" 9 #include "components/offline_pages/core/background/save_page_request.h"
9 #include "components/offline_pages/core/client_policy_controller.h" 10 #include "components/offline_pages/core/client_policy_controller.h"
10 #include "components/offline_pages/core/downloads/download_ui_adapter.h" 11 #include "components/offline_pages/core/downloads/download_ui_adapter.h"
11 #include "components/offline_pages/core/downloads/offline_page_download_notifier .h" 12 #include "components/offline_pages/core/downloads/offline_page_download_notifier .h"
12 13
13 namespace offline_pages { 14 namespace offline_pages {
14 namespace { 15 namespace {
15 int kUserDataKey; // Only address is used. 16 int kUserDataKey; // Only address is used.
16 } // namespace 17 } // namespace
(...skipping 12 matching lines...) Expand all
29 return static_cast<DownloadNotifyingObserver*>( 30 return static_cast<DownloadNotifyingObserver*>(
30 request_coordinator->GetUserData(&kUserDataKey)); 31 request_coordinator->GetUserData(&kUserDataKey));
31 } 32 }
32 33
33 // static 34 // static
34 void DownloadNotifyingObserver::CreateAndStartObserving( 35 void DownloadNotifyingObserver::CreateAndStartObserving(
35 RequestCoordinator* request_coordinator, 36 RequestCoordinator* request_coordinator,
36 std::unique_ptr<OfflinePageDownloadNotifier> notifier) { 37 std::unique_ptr<OfflinePageDownloadNotifier> notifier) {
37 DCHECK(request_coordinator); 38 DCHECK(request_coordinator);
38 DCHECK(notifier.get()); 39 DCHECK(notifier.get());
39 DownloadNotifyingObserver* observer = new DownloadNotifyingObserver( 40 std::unique_ptr<DownloadNotifyingObserver> observer =
40 std::move(notifier), request_coordinator->GetPolicyController()); 41 base::WrapUnique(new DownloadNotifyingObserver(
dewittj 2017/04/28 19:02:19 nit: rewrite this as: auto observer = base::MakeUn
Avi (use Gerrit) 2017/04/28 21:12:51 Sorry, but the constructor isn't public and theref
41 request_coordinator->AddObserver(observer); 42 std::move(notifier), request_coordinator->GetPolicyController()));
42 // |request_coordinator| takes ownership of observer here. 43 request_coordinator->AddObserver(observer.get());
43 request_coordinator->SetUserData(&kUserDataKey, observer); 44 request_coordinator->SetUserData(&kUserDataKey, std::move(observer));
44 } 45 }
45 46
46 void DownloadNotifyingObserver::OnAdded(const SavePageRequest& request) { 47 void DownloadNotifyingObserver::OnAdded(const SavePageRequest& request) {
47 DCHECK(notifier_.get()); 48 DCHECK(notifier_.get());
48 if (!IsVisibleInUI(request.client_id())) 49 if (!IsVisibleInUI(request.client_id()))
49 return; 50 return;
50 51
51 // Calling Progress ensures notification is created in lieu of specific 52 // Calling Progress ensures notification is created in lieu of specific
52 // Add/Create call. 53 // Add/Create call.
53 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); 54 notifier_->NotifyDownloadProgress(DownloadUIItem(request));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 const SavePageRequest& request) { 99 const SavePageRequest& request) {
99 if (request.request_state() == SavePageRequest::RequestState::PAUSED) 100 if (request.request_state() == SavePageRequest::RequestState::PAUSED)
100 notifier_->NotifyDownloadPaused(DownloadUIItem(request)); 101 notifier_->NotifyDownloadPaused(DownloadUIItem(request));
101 else if (request.request_state() == SavePageRequest::RequestState::AVAILABLE) 102 else if (request.request_state() == SavePageRequest::RequestState::AVAILABLE)
102 notifier_->NotifyDownloadInterrupted(DownloadUIItem(request)); 103 notifier_->NotifyDownloadInterrupted(DownloadUIItem(request));
103 else 104 else
104 notifier_->NotifyDownloadProgress(DownloadUIItem(request)); 105 notifier_->NotifyDownloadProgress(DownloadUIItem(request));
105 } 106 }
106 107
107 } // namespace offline_pages 108 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698