Commit babf9dad authored by Sreeja Kamishetty's avatar Sreeja Kamishetty Committed by Chromium LUCI CQ

Add ClosedTabCache Service and Factory

ClosedTabCache is a desktop feature to instantly restore closed tabs.

To own ClosedTabCache, this CL adds a KeyedService called
ClosedTabCacheService and a BrowserContextKeyedServiceFactory,
ClosedTabCacheServiceFactory, to retrieve the service.

ClosedTabCache design doc:
https://docs.google.com/document/d/1SF230MYWgroe4WikDMn82ETd3-HFRzylKtIk0HZRaOU/edit?usp=sharing

BUG=1100946

Change-Id: I397aa3abbebd9098694b20b9385fe75a7958c484
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2564966Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Sreeja Kamishetty <sreejakshetty@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832708}
parent 350f5ba2
......@@ -3893,6 +3893,10 @@ static_library("browser") {
"serial/serial_chooser_context_factory.cc",
"serial/serial_chooser_context_factory.h",
"serial/serial_chooser_histograms.h",
"sessions/closed_tab_cache_service.cc",
"sessions/closed_tab_cache_service.h",
"sessions/closed_tab_cache_service_factory.cc",
"sessions/closed_tab_cache_service_factory.h",
"sharesheet/sharesheet_controller.h",
"sharesheet/sharesheet_metrics.cc",
"sharesheet/sharesheet_metrics.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/sessions/closed_tab_cache_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/closed_tab_cache.h"
ClosedTabCacheService::ClosedTabCacheService(Profile* profile)
: profile_(profile), cache_(std::make_unique<ClosedTabCache>()) {
// Incognito profiles don't allow tab restores.
DCHECK(!profile_->IsOffTheRecord());
}
ClosedTabCacheService::~ClosedTabCacheService() = default;
void ClosedTabCacheService::Shutdown() {
cache_.reset();
}
ClosedTabCache& ClosedTabCacheService::closed_tab_cache() {
DCHECK(cache_);
return *cache_.get();
}
// 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_SESSIONS_CLOSED_TAB_CACHE_SERVICE_H_
#define CHROME_BROWSER_SESSIONS_CLOSED_TAB_CACHE_SERVICE_H_
#include <memory>
#include "components/keyed_service/core/keyed_service.h"
class ClosedTabCache;
class Profile;
class ClosedTabCacheService : public KeyedService {
public:
explicit ClosedTabCacheService(Profile* profile);
ClosedTabCacheService(const ClosedTabCacheService&) = delete;
ClosedTabCacheService& operator=(const ClosedTabCacheService&) = delete;
~ClosedTabCacheService() override;
ClosedTabCache& closed_tab_cache();
// KeyedService:
void Shutdown() override;
private:
Profile* profile_;
std::unique_ptr<ClosedTabCache> cache_;
};
#endif // CHROME_BROWSER_SESSIONS_CLOSED_TAB_CACHE_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/sessions/closed_tab_cache_service_factory.h"
#include "build/build_config.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
ClosedTabCacheServiceFactory::ClosedTabCacheServiceFactory()
: BrowserContextKeyedServiceFactory(
"ClosedTabCacheService",
BrowserContextDependencyManager::GetInstance()) {}
// static
ClosedTabCacheService* ClosedTabCacheServiceFactory::GetForProfile(
Profile* profile) {
return static_cast<ClosedTabCacheService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
ClosedTabCacheServiceFactory* ClosedTabCacheServiceFactory::GetInstance() {
return base::Singleton<ClosedTabCacheServiceFactory>::get();
}
KeyedService* ClosedTabCacheServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
if (context->IsOffTheRecord())
return nullptr;
return new ClosedTabCacheService(static_cast<Profile*>(context));
}
bool ClosedTabCacheServiceFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}
// 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_SESSIONS_CLOSED_TAB_CACHE_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SESSIONS_CLOSED_TAB_CACHE_SERVICE_FACTORY_H_
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/closed_tab_cache_service.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class ClosedTabCacheServiceFactory : public BrowserContextKeyedServiceFactory {
public:
// Returns the ClosedTabCacheService for |profile|.
static ClosedTabCacheService* GetForProfile(Profile* profile);
static ClosedTabCacheServiceFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<ClosedTabCacheServiceFactory>;
ClosedTabCacheServiceFactory();
~ClosedTabCacheServiceFactory() override = default;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
};
#endif // CHROME_BROWSER_SESSIONS_CLOSED_TAB_CACHE_SERVICE_FACTORY_H_
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