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

Side by Side Diff: components/offline_pages/content/suggested_articles_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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/content/suggested_articles_observer.h" 5 #include "components/offline_pages/content/suggested_articles_observer.h"
6 6
7 #include <unordered_set> 7 #include <unordered_set>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/ntp_snippets/category.h" 10 #include "components/ntp_snippets/category.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // static 69 // static
70 void SuggestedArticlesObserver::ObserveContentSuggestionsService( 70 void SuggestedArticlesObserver::ObserveContentSuggestionsService(
71 content::BrowserContext* browser_context, 71 content::BrowserContext* browser_context,
72 ntp_snippets::ContentSuggestionsService* service) { 72 ntp_snippets::ContentSuggestionsService* service) {
73 if (!offline_pages::IsPrefetchingOfflinePagesEnabled()) 73 if (!offline_pages::IsPrefetchingOfflinePagesEnabled())
74 return; 74 return;
75 75
76 auto suggestions_observer = base::MakeUnique<SuggestedArticlesObserver>( 76 auto suggestions_observer = base::MakeUnique<SuggestedArticlesObserver>(
77 browser_context, base::MakeUnique<DefaultDelegate>(service)); 77 browser_context, base::MakeUnique<DefaultDelegate>(service));
78 service->AddObserver(suggestions_observer.get()); 78 service->AddObserver(suggestions_observer.get());
79 service->SetUserData( 79 service->SetUserData(&kOfflinePageSuggestedArticlesObserverUserDataKey,
80 &kOfflinePageSuggestedArticlesObserverUserDataKey, 80 std::move(suggestions_observer));
81 // Note that |service| will take ownership of suggestions_observer
82 // despite accepting a raw pointer.
83 suggestions_observer.release());
84 } 81 }
85 82
86 SuggestedArticlesObserver::SuggestedArticlesObserver( 83 SuggestedArticlesObserver::SuggestedArticlesObserver(
87 content::BrowserContext* browser_context, 84 content::BrowserContext* browser_context,
88 std::unique_ptr<Delegate> delegate) 85 std::unique_ptr<Delegate> delegate)
89 : browser_context_(browser_context), delegate_(std::move(delegate)) {} 86 : browser_context_(browser_context), delegate_(std::move(delegate)) {}
90 87
91 SuggestedArticlesObserver::~SuggestedArticlesObserver() = default; 88 SuggestedArticlesObserver::~SuggestedArticlesObserver() = default;
92 89
93 void SuggestedArticlesObserver::OnNewSuggestions(Category category) { 90 void SuggestedArticlesObserver::OnNewSuggestions(Category category) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 158 }
162 service->RemoveAllUnprocessedPrefetchURLs(kSuggestedArticlesNamespace); 159 service->RemoveAllUnprocessedPrefetchURLs(kSuggestedArticlesNamespace);
163 OnNewSuggestions(ArticlesCategory()); 160 OnNewSuggestions(ArticlesCategory());
164 } 161 }
165 162
166 void SuggestedArticlesObserver::ContentSuggestionsServiceShutdown() { 163 void SuggestedArticlesObserver::ContentSuggestionsServiceShutdown() {
167 // No need to do anything here, we will just stop getting events. 164 // No need to do anything here, we will just stop getting events.
168 } 165 }
169 166
170 } // namespace offline_pages 167 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698