Commit 9e6d0cfa authored by Tanya Gupta's avatar Tanya Gupta Committed by Commit Bot

[LongScreenshots] Created a keyed service to generate long screenshots.

Created a skeleton for the Long Screenshots service. This will eventually
be used to call Freeze-Dried Tabs and generate the bitmaps needed for the
screenshot.

Bug: 1142520
Change-Id: Ia9e9ff5cc79d316ea6048e127c83f70a55c54996
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518090Reviewed-by: default avatarKyle Milka <kmilka@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarCalder Kitagawa <ckitagawa@chromium.org>
Commit-Queue: Tanya Gupta <tgupta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825429}
parent e9025066
...@@ -3138,6 +3138,7 @@ static_library("browser") { ...@@ -3138,6 +3138,7 @@ static_library("browser") {
"//chrome/browser/endpoint_fetcher:jni_headers", "//chrome/browser/endpoint_fetcher:jni_headers",
"//chrome/browser/feedback/android", "//chrome/browser/feedback/android",
"//chrome/browser/flags:flags_android", "//chrome/browser/flags:flags_android",
"//chrome/browser/long_screenshots:services",
"//chrome/browser/notifications/chime/android", "//chrome/browser/notifications/chime/android",
"//chrome/browser/notifications/scheduler/public", "//chrome/browser/notifications/scheduler/public",
"//chrome/browser/offline_pages/prefetch/notifications", "//chrome/browser/offline_pages/prefetch/notifications",
......
# 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.
source_set("services") {
sources = [
"long_screenshots_tab_service.cc",
"long_screenshots_tab_service.h",
"long_screenshots_tab_service_factory.cc",
"long_screenshots_tab_service_factory.h",
]
deps = [
"//components/keyed_service/core",
"//components/paint_preview/browser",
]
}
file://components/send_tab_to_self/OWNERS
# COMPONENT: UI>Browser>Sharing
\ No newline at end of file
// 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/long_screenshots/long_screenshots_tab_service.h"
#include "base/callback.h"
namespace long_screenshots {
LongScreenshotsTabService::LongScreenshotsTabService(
const base::FilePath& profile_dir,
base::StringPiece ascii_feature_name,
std::unique_ptr<paint_preview::PaintPreviewPolicy> policy,
bool is_off_the_record)
: PaintPreviewBaseService(profile_dir,
ascii_feature_name,
std::move(policy),
is_off_the_record) {
// TODO(tgupta): Populate this.
}
LongScreenshotsTabService::~LongScreenshotsTabService() {
// TODO(tgupta): Populate this.
}
void LongScreenshotsTabService::CaptureTab(int tab_id,
content::WebContents* contents,
FinishedCallback callback) {
// TODO(tgupta): Populate this.
}
void LongScreenshotsTabService::CaptureTabInternal(
int tab_id,
const paint_preview::DirectoryKey& key,
int frame_tree_node_id,
content::GlobalFrameRoutingId frame_routing_id,
FinishedCallback callback,
const base::Optional<base::FilePath>& file_path) {
// TODO(tgupta): Complete this function
}
void LongScreenshotsTabService::OnCaptured(
int tab_id,
const paint_preview::DirectoryKey& key,
int frame_tree_node_id,
FinishedCallback callback,
paint_preview::PaintPreviewBaseService::CaptureStatus status,
std::unique_ptr<paint_preview::CaptureResult> result) {
// TODO(tgupta): Populate this.
}
void LongScreenshotsTabService::OnFinished(int tab_id,
FinishedCallback callback,
bool success) {
// TODO(tgupta): Complete this function
}
} // namespace long_screenshots
// 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_LONG_SCREENSHOTS_LONG_SCREENSHOTS_TAB_SERVICE_H_
#define CHROME_BROWSER_LONG_SCREENSHOTS_LONG_SCREENSHOTS_TAB_SERVICE_H_
#include <memory>
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_piece.h"
#include "build/build_config.h"
#include "components/paint_preview/browser/paint_preview_base_service.h"
#include "components/paint_preview/browser/paint_preview_policy.h"
namespace content {
class WebContents;
} // namespace content
namespace long_screenshots {
// A service for capturing Long Screenshots using PaintPreview.
class LongScreenshotsTabService
: public paint_preview::PaintPreviewBaseService {
public:
LongScreenshotsTabService(
const base::FilePath& profile_dir,
base::StringPiece ascii_feature_name,
std::unique_ptr<paint_preview::PaintPreviewPolicy> policy,
bool is_off_the_record);
~LongScreenshotsTabService() override;
enum Status {
kOk = 0,
kDirectoryCreationFailed = 1,
kCaptureFailed = 2,
kProtoSerializationFailed = 3,
kWebContentsGone = 4,
};
using FinishedCallback = base::OnceCallback<void(Status)>;
// Captures a Paint Preview of |contents| which should be associated with
// |tab_id| for storage. |callback| is invoked on completion to indicate
// status.
void CaptureTab(int tab_id,
content::WebContents* contents,
FinishedCallback callback);
private:
// The FTN ID is to look-up the content::WebContents.
void CaptureTabInternal(int tab_id,
const paint_preview::DirectoryKey& key,
int frame_tree_node_id,
content::GlobalFrameRoutingId frame_routing_id,
FinishedCallback callback,
const base::Optional<base::FilePath>& file_path);
void OnCaptured(int tab_id,
const paint_preview::DirectoryKey& key,
int frame_tree_node_id,
FinishedCallback callback,
paint_preview::PaintPreviewBaseService::CaptureStatus status,
std::unique_ptr<paint_preview::CaptureResult> result);
void OnFinished(int tab_id, FinishedCallback callback, bool success);
base::WeakPtrFactory<LongScreenshotsTabService> weak_ptr_factory_{this};
};
} // namespace long_screenshots
#endif // CHROME_BROWSER_LONG_SCREENSHOTS_LONG_SCREENSHOTS_TAB_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/long_screenshots/long_screenshots_tab_service_factory.h"
#include "build/build_config.h"
#include "chrome/browser/long_screenshots/long_screenshots_tab_service.h"
#include "components/keyed_service/core/simple_dependency_manager.h"
#include "components/keyed_service/core/simple_factory_key.h"
namespace long_screenshots {
namespace {
constexpr char kFeatureDirname[] = "long_screenshots_tab_service";
} // namespace
// static
LongScreenshotsTabServiceFactory*
LongScreenshotsTabServiceFactory::GetInstance() {
return base::Singleton<LongScreenshotsTabServiceFactory>::get();
}
// static
long_screenshots::LongScreenshotsTabService*
LongScreenshotsTabServiceFactory::GetServiceInstance(SimpleFactoryKey* key) {
return static_cast<long_screenshots::LongScreenshotsTabService*>(
GetInstance()->GetServiceForKey(key, true));
}
LongScreenshotsTabServiceFactory::LongScreenshotsTabServiceFactory()
: SimpleKeyedServiceFactory("LongScreenshotsTabService",
SimpleDependencyManager::GetInstance()) {}
LongScreenshotsTabServiceFactory::~LongScreenshotsTabServiceFactory() = default;
std::unique_ptr<KeyedService>
LongScreenshotsTabServiceFactory::BuildServiceInstanceFor(
SimpleFactoryKey* key) const {
// Prevent this working off the record.
if (key->IsOffTheRecord())
return nullptr;
return std::make_unique<LongScreenshotsTabService>(
key->GetPath(), kFeatureDirname, nullptr, key->IsOffTheRecord());
}
SimpleFactoryKey* LongScreenshotsTabServiceFactory::GetKeyToUse(
SimpleFactoryKey* key) const {
return key;
}
} // namespace long_screenshots
// 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_LONG_SCREENSHOTS_LONG_SCREENSHOTS_TAB_SERVICE_FACTORY_H_
#define CHROME_BROWSER_LONG_SCREENSHOTS_LONG_SCREENSHOTS_TAB_SERVICE_FACTORY_H_
#include <memory>
#include "base/memory/singleton.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/keyed_service/core/simple_keyed_service_factory.h"
class SimpleFactoryKey;
namespace long_screenshots {
class LongScreenshotsTabService;
// Factory to create one LongScreenshotsTabService per profile key.
class LongScreenshotsTabServiceFactory : public SimpleKeyedServiceFactory {
public:
static LongScreenshotsTabServiceFactory* GetInstance();
static long_screenshots::LongScreenshotsTabService* GetServiceInstance(
SimpleFactoryKey* key);
LongScreenshotsTabServiceFactory(const LongScreenshotsTabServiceFactory&) =
delete;
LongScreenshotsTabServiceFactory& operator=(
const LongScreenshotsTabServiceFactory&) = delete;
private:
friend struct base::DefaultSingletonTraits<LongScreenshotsTabServiceFactory>;
LongScreenshotsTabServiceFactory();
~LongScreenshotsTabServiceFactory() override;
// SimpleKeyedServiceFactory:
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
SimpleFactoryKey* key) const override;
SimpleFactoryKey* GetKeyToUse(SimpleFactoryKey* key) const override;
};
} // namespace long_screenshots
#endif // CHROME_BROWSER_LONG_SCREENSHOTS_LONG_SCREENSHOTS_TAB_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