Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/content_suggestions/content_suggestions_mediator.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "components/ntp_snippets/category.h" | |
| 9 #include "components/ntp_snippets/content_suggestion.h" | |
| 10 #import "ios/chrome/browser/content_suggestions/content_suggestions_service_brid ge_observer.h" | |
| 11 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" | |
| 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h" | |
| 13 | |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 15 #error "This file requires ARC support." | |
| 16 #endif | |
| 17 | |
| 18 @interface ContentSuggestionsMediator ()<ContentSuggestionsServiceObserver> { | |
| 19 // Bridge for this class to become an observer of a ContentSuggestionsService. | |
| 20 std::unique_ptr<ContentSuggestionsServiceBridge> _suggestionBridge; | |
| 21 } | |
| 22 | |
| 23 @property(nonatomic, assign) | |
| 24 ntp_snippets::ContentSuggestionsService* contentService; | |
| 25 | |
| 26 // Converts the data in |category| to ContentSuggestion and adds them to the | |
| 27 // |contentArray|. | |
| 28 - (void)addContentInCategory:(ntp_snippets::Category&)category | |
| 29 toArray:(NSMutableArray<ContentSuggestion*>*)contentArray; | |
| 30 | |
| 31 // Converts the |contentsuggestion| to a ContentSuggestion. | |
| 32 - (ContentSuggestion*)convertContentSuggestion: | |
| 33 (const ntp_snippets::ContentSuggestion&)contentsuggestion; | |
| 34 | |
| 35 @end | |
| 36 | |
| 37 @implementation ContentSuggestionsMediator | |
| 38 | |
| 39 @synthesize contentService = _contentService; | |
| 40 @synthesize dataSink = _dataSink; | |
| 41 | |
| 42 - (instancetype)initWithContentService: | |
| 43 (ntp_snippets::ContentSuggestionsService*)contentService { | |
| 44 self = [super init]; | |
| 45 if (self) { | |
| 46 _suggestionBridge = | |
| 47 base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService); | |
| 48 _contentService = contentService; | |
| 49 } | |
| 50 return self; | |
| 51 } | |
| 52 | |
| 53 #pragma mark - ContentSuggestionsDataSource | |
| 54 | |
| 55 - (NSArray<ContentSuggestion*>*)allSuggestions { | |
| 56 std::vector<ntp_snippets::Category> categories = | |
| 57 self.contentService->GetCategories(); | |
| 58 NSMutableArray<ContentSuggestion*>* dataHolders = [NSMutableArray array]; | |
| 59 for (auto& category : categories) { | |
| 60 [self addContentInCategory:category toArray:dataHolders]; | |
| 61 } | |
| 62 return dataHolders; | |
| 63 } | |
| 64 | |
| 65 #pragma mark - ContentSuggestionsServiceObserver | |
| 66 | |
| 67 - (void)contentSuggestionsService: | |
| 68 (ntp_snippets::ContentSuggestionsService*)suggestionsService | |
| 69 newSuggestionsInCategory:(ntp_snippets::Category)category { | |
| 70 [self.dataSink dataAvailable]; | |
| 71 } | |
| 72 | |
| 73 - (void)contentSuggestionsService: | |
|
marq (ping after 24h)
2017/02/01 09:55:40
Some sort of formatting chaos has happened.
gambard
2017/02/01 13:38:07
No idea what happened. git cl format gave me the s
| |
| 74 (ntp_snippets::ContentSuggestionsService*)suggestionsService | |
| 75 category: | |
| 76 (ntp_snippets::Category)category | |
| 77 statusChangedTo: | |
| 78 (ntp_snippets::CategoryStatus)status{ | |
| 79 // Update dataSink. | |
| 80 } | |
| 81 | |
| 82 - (void) | |
| 83 contentSuggestionsService: | |
| 84 (ntp_snippets::ContentSuggestionsService*) | |
| 85 suggestionsService | |
| 86 SuggestionInvalidated: | |
| 87 (const ntp_snippets::ContentSuggestion::ID&) | |
| 88 suggestion_id{ | |
| 89 // Update dataSink. | |
| 90 } | |
| 91 | |
| 92 - (void) | |
| 93 contentSuggestionsServiceFullRefreshRequired: | |
| 94 (ntp_snippets::ContentSuggestionsService*)suggestionsService{ | |
| 95 // Update dataSink. | |
| 96 } | |
| 97 | |
| 98 - (void) | |
| 99 contentSuggestionsServiceShutdown: | |
| 100 (ntp_snippets::ContentSuggestionsService*) | |
| 101 suggestionsService { | |
| 102 // Update dataSink. | |
| 103 } | |
| 104 | |
| 105 #pragma mark - Private | |
| 106 | |
| 107 - (void)addContentInCategory:(ntp_snippets::Category&)category | |
| 108 toArray:(NSMutableArray<ContentSuggestion*>*)contentArray { | |
| 109 const std::vector<ntp_snippets::ContentSuggestion>& suggestions = | |
| 110 self.contentService->GetSuggestionsForCategory(category); | |
| 111 for (auto& contentSuggestion : suggestions) { | |
| 112 [contentArray addObject:[self convertContentSuggestion:contentSuggestion]]; | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 - (ContentSuggestion*)convertContentSuggestion: | |
| 117 (const ntp_snippets::ContentSuggestion&)contentsuggestion { | |
| 118 return [[ContentSuggestion alloc] init]; | |
| 119 } | |
| 120 | |
| 121 @end | |
| OLD | NEW |