Commit 47d59d25 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Creates DiscoverFeedConfiguration

DiscoverFeedConfiguration will make any future changes much easier
(even for potential cherrypicks), and its needed so the provider
can read a PrefValue indicating the last time browsing data was
cleared.

Bug: 1085419
Change-Id: I8324eadac2f4c0113cc707ac9b84cd84e0336ffe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359399
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798888}
parent 3861f5c6
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
class AuthenticationService; class ChromeBrowserState;
class DiscoverFeedProvider; class DiscoverFeedProvider;
// A browser-context keyed service that is used to keep the Discover Feed data // A browser-context keyed service that is used to keep the Discover Feed data
...@@ -17,9 +17,7 @@ class DiscoverFeedService : public KeyedService, ...@@ -17,9 +17,7 @@ class DiscoverFeedService : public KeyedService,
public signin::IdentityManager::Observer { public signin::IdentityManager::Observer {
public: public:
// Initializes the service. // Initializes the service.
DiscoverFeedService(signin::IdentityManager* identity_manager, DiscoverFeedService(ChromeBrowserState* browser_state);
AuthenticationService* authentication_service,
DiscoverFeedProvider* feed_provider);
~DiscoverFeedService() override; ~DiscoverFeedService() override;
// KeyedService: // KeyedService:
...@@ -35,9 +33,6 @@ class DiscoverFeedService : public KeyedService, ...@@ -35,9 +33,6 @@ class DiscoverFeedService : public KeyedService,
// Identity manager to observe. // Identity manager to observe.
signin::IdentityManager* identity_manager_; signin::IdentityManager* identity_manager_;
// The AuthenticationService sent to DiscoverFeedProvider;
AuthenticationService* authentication_service_ = nullptr;
// Discover Feed provider to notify of changes. // Discover Feed provider to notify of changes.
DiscoverFeedProvider* discover_feed_provider_; DiscoverFeedProvider* discover_feed_provider_;
......
...@@ -4,23 +4,31 @@ ...@@ -4,23 +4,31 @@
#include "ios/chrome/browser/discover_feed/discover_feed_service.h" #include "ios/chrome/browser/discover_feed/discover_feed_service.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/discover_feed/discover_feed_configuration.h"
#import "ios/public/provider/chrome/browser/discover_feed/discover_feed_provider.h" #import "ios/public/provider/chrome/browser/discover_feed/discover_feed_provider.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
DiscoverFeedService::DiscoverFeedService( DiscoverFeedService::DiscoverFeedService(ChromeBrowserState* browser_state) {
signin::IdentityManager* identity_manager, discover_feed_provider_ =
AuthenticationService* authentication_service, ios::GetChromeBrowserProvider()->GetDiscoverFeedProvider();
DiscoverFeedProvider* feed_provider) identity_manager_ = IdentityManagerFactory::GetForBrowserState(browser_state);
: identity_manager_(identity_manager),
authentication_service_(authentication_service),
discover_feed_provider_(feed_provider) {
if (identity_manager_) { if (identity_manager_) {
identity_manager_->AddObserver(this); identity_manager_->AddObserver(this);
} }
discover_feed_provider_->StartFeed(authentication_service_);
DiscoverFeedConfiguration* discover_config =
[[DiscoverFeedConfiguration alloc] init];
discover_config.browserState = browser_state;
// TODO(crbug.com/1085419): Send discover_config once downstream CL lands.
discover_feed_provider_->StartFeed(
AuthenticationServiceFactory::GetForBrowserState(browser_state));
} }
DiscoverFeedService::~DiscoverFeedService() {} DiscoverFeedService::~DiscoverFeedService() {}
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#include "ios/chrome/browser/discover_feed/discover_feed_service.h" #include "ios/chrome/browser/discover_feed/discover_feed_service.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h" #import "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h" #include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/discover_feed/discover_feed_provider.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -44,12 +42,5 @@ DiscoverFeedServiceFactory::BuildServiceInstanceFor( ...@@ -44,12 +42,5 @@ DiscoverFeedServiceFactory::BuildServiceInstanceFor(
web::BrowserState* context) const { web::BrowserState* context) const {
ChromeBrowserState* browser_state = ChromeBrowserState* browser_state =
ChromeBrowserState::FromBrowserState(context); ChromeBrowserState::FromBrowserState(context);
signin::IdentityManager* identity_manager = return std::make_unique<DiscoverFeedService>(browser_state);
IdentityManagerFactory::GetForBrowserState(browser_state);
AuthenticationService* authentication_service =
AuthenticationServiceFactory::GetForBrowserState(browser_state);
return std::make_unique<DiscoverFeedService>(
identity_manager, authentication_service,
ios::GetChromeBrowserProvider()->GetDiscoverFeedProvider());
} }
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
source_set("discover_feed") { source_set("discover_feed") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"discover_feed_configuration.h",
"discover_feed_configuration.mm",
"discover_feed_observer_bridge.h", "discover_feed_observer_bridge.h",
"discover_feed_observer_bridge.mm", "discover_feed_observer_bridge.mm",
"discover_feed_provider.h", "discover_feed_provider.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_PUBLIC_PROVIDER_CHROME_BROWSER_DISCOVER_FEED_DISCOVER_FEED_CONFIGURATION_H_
#define IOS_PUBLIC_PROVIDER_CHROME_BROWSER_DISCOVER_FEED_DISCOVER_FEED_CONFIGURATION_H_
#import <Foundation/Foundation.h>
class ChromeBrowserState;
// Configuration object used by the DiscoverFeedProvider.
@interface DiscoverFeedConfiguration : NSObject
// BrowserState used by DiscoverFeedProvider;
@property(nonatomic, assign) ChromeBrowserState* browserState;
@end
#endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_DISCOVER_FEED_DISCOVER_FEED_CONFIGURATION_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/public/provider/chrome/browser/discover_feed/discover_feed_configuration.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation DiscoverFeedConfiguration
@end
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
@protocol ApplicationCommands; @protocol ApplicationCommands;
class AuthenticationService; class AuthenticationService;
class Browser; class Browser;
@class DiscoverFeedConfiguration;
// DiscoverFeedProvider allows embedders to provide functionality for a Discover // DiscoverFeedProvider allows embedders to provide functionality for a Discover
// Feed. // Feed.
...@@ -34,7 +35,10 @@ class DiscoverFeedProvider { ...@@ -34,7 +35,10 @@ class DiscoverFeedProvider {
DiscoverFeedProvider(const DiscoverFeedProvider&) = delete; DiscoverFeedProvider(const DiscoverFeedProvider&) = delete;
DiscoverFeedProvider& operator=(const DiscoverFeedProvider&) = delete; DiscoverFeedProvider& operator=(const DiscoverFeedProvider&) = delete;
// Starts the Feed using |auth_service| to check if user is Signed In/Out. // Starts the Feed using |discover_config| which contains various configs for
// the Feed.
virtual void StartFeed(DiscoverFeedConfiguration* discover_config);
// DEPRECATED. Delete once this method has been deleted downstream.
virtual void StartFeed(AuthenticationService* auth_service); virtual void StartFeed(AuthenticationService* auth_service);
// Returns true if the Discover Feed is enabled. // Returns true if the Discover Feed is enabled.
virtual bool IsDiscoverFeedEnabled(); virtual bool IsDiscoverFeedEnabled();
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
void DiscoverFeedProvider::StartFeed(
DiscoverFeedConfiguration* discover_config) {}
void DiscoverFeedProvider::StartFeed(AuthenticationService* auth_service) {} void DiscoverFeedProvider::StartFeed(AuthenticationService* auth_service) {}
bool DiscoverFeedProvider::IsDiscoverFeedEnabled() { bool DiscoverFeedProvider::IsDiscoverFeedEnabled() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment