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 @@
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/public/identity_manager/identity_manager.h"
class AuthenticationService;
class ChromeBrowserState;
class DiscoverFeedProvider;
// A browser-context keyed service that is used to keep the Discover Feed data
......@@ -17,9 +17,7 @@ class DiscoverFeedService : public KeyedService,
public signin::IdentityManager::Observer {
public:
// Initializes the service.
DiscoverFeedService(signin::IdentityManager* identity_manager,
AuthenticationService* authentication_service,
DiscoverFeedProvider* feed_provider);
DiscoverFeedService(ChromeBrowserState* browser_state);
~DiscoverFeedService() override;
// KeyedService:
......@@ -35,9 +33,6 @@ class DiscoverFeedService : public KeyedService,
// Identity manager to observe.
signin::IdentityManager* identity_manager_;
// The AuthenticationService sent to DiscoverFeedProvider;
AuthenticationService* authentication_service_ = nullptr;
// Discover Feed provider to notify of changes.
DiscoverFeedProvider* discover_feed_provider_;
......
......@@ -4,23 +4,31 @@
#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"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
DiscoverFeedService::DiscoverFeedService(
signin::IdentityManager* identity_manager,
AuthenticationService* authentication_service,
DiscoverFeedProvider* feed_provider)
: identity_manager_(identity_manager),
authentication_service_(authentication_service),
discover_feed_provider_(feed_provider) {
DiscoverFeedService::DiscoverFeedService(ChromeBrowserState* browser_state) {
discover_feed_provider_ =
ios::GetChromeBrowserProvider()->GetDiscoverFeedProvider();
identity_manager_ = IdentityManagerFactory::GetForBrowserState(browser_state);
if (identity_manager_) {
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() {}
......
......@@ -9,8 +9,6 @@
#include "ios/chrome/browser/discover_feed/discover_feed_service.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_provider.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -44,12 +42,5 @@ DiscoverFeedServiceFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
ChromeBrowserState* browser_state =
ChromeBrowserState::FromBrowserState(context);
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForBrowserState(browser_state);
AuthenticationService* authentication_service =
AuthenticationServiceFactory::GetForBrowserState(browser_state);
return std::make_unique<DiscoverFeedService>(
identity_manager, authentication_service,
ios::GetChromeBrowserProvider()->GetDiscoverFeedProvider());
return std::make_unique<DiscoverFeedService>(browser_state);
}
......@@ -5,6 +5,8 @@
source_set("discover_feed") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"discover_feed_configuration.h",
"discover_feed_configuration.mm",
"discover_feed_observer_bridge.h",
"discover_feed_observer_bridge.mm",
"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 @@
@protocol ApplicationCommands;
class AuthenticationService;
class Browser;
@class DiscoverFeedConfiguration;
// DiscoverFeedProvider allows embedders to provide functionality for a Discover
// Feed.
......@@ -34,7 +35,10 @@ class DiscoverFeedProvider {
DiscoverFeedProvider(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);
// Returns true if the Discover Feed is enabled.
virtual bool IsDiscoverFeedEnabled();
......
......@@ -8,6 +8,8 @@
#error "This file requires ARC support."
#endif
void DiscoverFeedProvider::StartFeed(
DiscoverFeedConfiguration* discover_config) {}
void DiscoverFeedProvider::StartFeed(AuthenticationService* auth_service) {}
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