Commit 5ccb3f5d authored by Yue Zhang's avatar Yue Zhang Committed by Chromium LUCI CQ

[ChromeCart] Add empty chrome cart service

This CL adds the skeleton of chrome cart service which will later be
used to read, write and maintain data of chrome cart module. This CL
also adds a singleton CartServiceFactory to acquire CartService.

Bug: 1157892
Change-Id: Ia4bde1bc514cf83fe445f8c8be24b093b05fb0b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2597813
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839158}
parent d2d71ce6
......@@ -267,8 +267,6 @@ static_library("browser") {
"browsing_data/site_data_size_collector.h",
"cache_stats_recorder.cc",
"cache_stats_recorder.h",
"cart/cart_handler.cc",
"cart/cart_handler.h",
"chooser_controller/chooser_controller.cc",
"chooser_controller/chooser_controller.h",
"chrome_browser_field_trials.cc",
......@@ -3474,6 +3472,12 @@ static_library("browser") {
"browsing_data/chrome_browsing_data_lifetime_manager.h",
"browsing_data/chrome_browsing_data_lifetime_manager_factory.cc",
"browsing_data/chrome_browsing_data_lifetime_manager_factory.h",
"cart/cart_handler.cc",
"cart/cart_handler.h",
"cart/cart_service.cc",
"cart/cart_service.h",
"cart/cart_service_factory.cc",
"cart/cart_service_factory.h",
"certificate_viewer.h",
"chrome_browser_field_trials_desktop.cc",
"chrome_browser_field_trials_desktop.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.
#include "chrome/browser/cart/cart_service.h"
CartService::CartService(Profile* profile) {}
CartService::~CartService() = default;
// 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 CHROME_BROWSER_CART_CART_SERVICE_H_
#define CHROME_BROWSER_CART_CART_SERVICE_H_
#include "base/memory/weak_ptr.h"
#include "chrome/browser/cart/cart_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/core/keyed_service.h"
// Service to maintain and read/write data for chrome cart module.
class CartService : public KeyedService {
public:
CartService(const CartService&) = delete;
CartService& operator=(const CartService&) = delete;
~CartService() override;
private:
friend class CartServiceFactory;
// Use |CartServiceFactory::GetForProfile(...)| to get an instance of this
// service.
explicit CartService(Profile* profile);
base::WeakPtrFactory<CartService> weak_ptr_factory_{this};
};
#endif // CHROME_BROWSER_CART_CART_SERVICE_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.
#include "chrome/browser/cart/cart_service_factory.h"
#include "chrome/browser/cart/cart_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/storage_partition.h"
// static
CartServiceFactory* CartServiceFactory::GetInstance() {
return base::Singleton<CartServiceFactory>::get();
}
// static
CartService* CartServiceFactory::GetForProfile(Profile* profile) {
// CartService is not supported on incognito.
if (profile->IsOffTheRecord())
return nullptr;
return static_cast<CartService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
CartServiceFactory::CartServiceFactory()
: BrowserContextKeyedServiceFactory(
"ChromeCartService",
BrowserContextDependencyManager::GetInstance()) {}
CartServiceFactory::~CartServiceFactory() = default;
KeyedService* CartServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
DCHECK(!context->IsOffTheRecord());
return new CartService(Profile::FromBrowserContext(context));
}
// 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 CHROME_BROWSER_CART_CART_SERVICE_FACTORY_H_
#define CHROME_BROWSER_CART_CART_SERVICE_FACTORY_H_
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
class CartService;
// Factory to create CartService per profile. CartService is not supported on
// incognito, and the factory will return nullptr for an incognito profile.
class CartServiceFactory : public BrowserContextKeyedServiceFactory {
public:
// Acquire instance of CartServiceFactory.
static CartServiceFactory* GetInstance();
// Acquire CartService - there is one per profile.
static CartService* GetForProfile(Profile* profile);
private:
friend struct base::DefaultSingletonTraits<CartServiceFactory>;
CartServiceFactory();
~CartServiceFactory() override;
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
};
#endif // CHROME_BROWSER_CART_CART_SERVICE_FACTORY_H_
......@@ -122,6 +122,7 @@
#else
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_lifetime_manager_factory.h"
#include "chrome/browser/cart/cart_service_factory.h"
#include "chrome/browser/feedback/feedback_uploader_factory_chrome.h"
#include "chrome/browser/media/feeds/media_feeds_service_factory.h"
#include "chrome/browser/metrics/desktop_session_duration/desktop_profile_session_durations_service_factory.h"
......@@ -446,6 +447,9 @@ void ChromeBrowserMainExtraPartsProfiles::
#if BUILDFLAG(IS_CHROMEOS_LACROS)
CertDbInitializerFactory::GetInstance();
#endif
#if !defined(OS_ANDROID)
CartServiceFactory::GetInstance();
#endif
}
void ChromeBrowserMainExtraPartsProfiles::PreProfileInit() {
......
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