Commit 0e77a7fd authored by Sky Malice's avatar Sky Malice Committed by Commit Bot

[Feed] FeedHostService holds FeedNetworkingHost.

Bug: 838609
Change-Id: Idd7f0043064894b414565d2d4e4955658b9cfccb
Reviewed-on: https://chromium-review.googlesource.com/1041069Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Commit-Queue: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555772}
parent 355781b8
......@@ -4,9 +4,19 @@
#include "chrome/browser/android/feed/feed_host_service_factory.h"
#include <memory>
#include <string>
#include <utility>
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/channel_info.h"
#include "components/feed/core/feed_host_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
#include "google_apis/google_api_keys.h"
namespace feed {
......@@ -31,7 +41,24 @@ FeedHostServiceFactory::~FeedHostServiceFactory() = default;
KeyedService* FeedHostServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new FeedHostService();
Profile* profile = Profile::FromBrowserContext(context);
content::StoragePartition* storage_partition =
content::BrowserContext::GetDefaultStoragePartition(context);
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
std::string api_key;
if (google_apis::IsGoogleChromeAPIKeyUsed()) {
bool is_stable_channel =
chrome::GetChannel() == version_info::Channel::STABLE;
api_key = is_stable_channel ? google_apis::GetAPIKey()
: google_apis::GetNonStableAPIKey();
}
auto networking_host = std::make_unique<FeedNetworkingHost>(
identity_manager, api_key,
storage_partition->GetURLLoaderFactoryForBrowserProcess());
return new FeedHostService(std::move(networking_host));
}
content::BrowserContext* FeedHostServiceFactory::GetBrowserContextToUse(
......
......@@ -4,10 +4,18 @@
#include "components/feed/core/feed_host_service.h"
#include <utility>
namespace feed {
FeedHostService::FeedHostService() {}
FeedHostService::FeedHostService(
std::unique_ptr<FeedNetworkingHost> networking_host)
: networking_host_(std::move(networking_host)) {}
FeedHostService::~FeedHostService() = default;
FeedNetworkingHost* FeedHostService::GetFeedNetworkingHost() {
return networking_host_.get();
}
} // namespace feed
......@@ -5,7 +5,10 @@
#ifndef COMPONENTS_FEED_CORE_FEED_HOST_SERVICE_H_
#define COMPONENTS_FEED_CORE_FEED_HOST_SERVICE_H_
#include <memory>
#include "base/macros.h"
#include "components/feed/core/feed_networking_host.h"
#include "components/keyed_service/core/keyed_service.h"
namespace feed {
......@@ -17,10 +20,13 @@ namespace feed {
// yet.
class FeedHostService : public KeyedService {
public:
FeedHostService();
explicit FeedHostService(std::unique_ptr<FeedNetworkingHost> networking_host);
~FeedHostService() override;
FeedNetworkingHost* GetFeedNetworkingHost();
private:
std::unique_ptr<FeedNetworkingHost> networking_host_;
DISALLOW_COPY_AND_ASSIGN(FeedHostService);
};
......
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