Skip to content

Commit

Permalink
Prototype migrating old localStorage and cookies from StorageRecord.
Browse files Browse the repository at this point in the history
b/362296377
  • Loading branch information
aee-google committed Jan 7, 2025
1 parent 6c6f249 commit 3e44f8d
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 5 deletions.
6 changes: 3 additions & 3 deletions base/metrics/histogram_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ HistogramBase::HistogramBase(const char* name)
HistogramBase::~HistogramBase() = default;

void HistogramBase::CheckName(const StringPiece& name) const {
DCHECK_EQ(StringPiece(histogram_name()), name)
<< "Provided histogram name doesn't match instance name. Are you using a "
"dynamic string in a macro?";
// DCHECK_EQ(StringPiece(histogram_name()), name)
// << "Provided histogram name doesn't match instance name. Are you using a "
// "dynamic string in a macro?";
}

void HistogramBase::SetFlags(int32_t flags) {
Expand Down
2 changes: 2 additions & 0 deletions cobalt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ group("gn_all") {

# TODO(b/371589344): Fix android build configs.
deps = [
"//cobalt/migrate_storage_record",
"//starboard($starboard_toolchain)",
"//starboard/nplb",
]
Expand All @@ -45,6 +46,7 @@ if (!is_android) {
defines = []

deps = [
"//cobalt/migrate_storage_record",
"//cobalt/user_agent",
"//content/public/app",
"//content/shell:content_shell_app",
Expand Down
1 change: 1 addition & 0 deletions cobalt/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ shared_library("libcobalt_content_shell_content_view") {
# TODO(b/375655377): remove testonly
testonly = true
deps = [
"//cobalt/migrate_storage_record",
"//cobalt/user_agent",

# TODO: what can be removed in the dependencies?
Expand Down
27 changes: 25 additions & 2 deletions cobalt/cobalt_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,32 @@

#include <string>

#include "base/logging.h"
#include "cobalt/migrate_storage_record/migrate.h"
#include "cobalt/user_agent/user_agent_platform_info.h"
#include "content/public/common/user_agent.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"

#include "base/logging.h"

namespace cobalt {

std::atomic_bool migration_attempted_{false};

void CobaltWebContentsObserver::OnCookiesAccessed(
content::RenderFrameHost* render_frame_host,
const content::CookieAccessDetails& details) {
if (!migration_attempted_.load()) {
migration_attempted_.store(true);
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
"clear-cookies-and-local-storage")) {
LOG(INFO) << "Clearing cookies and localStorage.";
cobalt::migrate_storage_record::ClearAll(render_frame_host);
} else {
LOG(INFO) << "Try to migrate cookies and localStorage if needed.";
cobalt::migrate_storage_record::Migrate(render_frame_host);
}
}
}

#define COBALT_BRAND_NAME "Cobalt"
#define COBALT_MAJOR_VERSION "26"
#define COBALT_VERSION "26.lts.0-qa"
Expand Down Expand Up @@ -91,4 +109,9 @@ void CobaltContentBrowserClient::OverrideWebkitPrefs(
content::ShellContentBrowserClient::OverrideWebkitPrefs(web_contents, prefs);
}

void CobaltContentBrowserClient::OnWebContentsCreated(
content::WebContents* web_contents) {
web_contents_observer_.reset(new CobaltWebContentsObserver(web_contents));
}

} // namespace cobalt
14 changes: 14 additions & 0 deletions cobalt/cobalt_content_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
#ifndef COBALT_COBALT_CONTENT_BROWSER_CLIENT_H_
#define COBALT_COBALT_CONTENT_BROWSER_CLIENT_H_

#include "content/public/browser/web_contents_observer.h"
#include "content/shell/browser/shell_content_browser_client.h"

namespace cobalt {

class CobaltWebContentsObserver : public content::WebContentsObserver {
public:
explicit CobaltWebContentsObserver(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {}

void OnCookiesAccessed(content::RenderFrameHost* render_frame_host,
const content::CookieAccessDetails& details) override;
};

class CobaltContentBrowserClient : public content::ShellContentBrowserClient {
public:
CobaltContentBrowserClient();
Expand All @@ -31,6 +41,10 @@ class CobaltContentBrowserClient : public content::ShellContentBrowserClient {
blink::UserAgentMetadata GetUserAgentMetadata() override;
void OverrideWebkitPrefs(content::WebContents* web_contents,
blink::web_pref::WebPreferences* prefs) override;
void OnWebContentsCreated(content::WebContents* web_contents);

private:
std::unique_ptr<CobaltWebContentsObserver> web_contents_observer_;
};

} // namespace cobalt
Expand Down
26 changes: 26 additions & 0 deletions cobalt/migrate_storage_record/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import("//testing/test.gni")
import("//third_party/protobuf/proto_library.gni")

proto_library("storage_proto") {
sources = [ "storage.proto" ]
generate_python = false
}

source_set("migrate_storage_record") {
# Needed to depend on |//content/shell:content_shell_lib|.
testonly = true

sources = [
"migrate.cc",
"migrate.h",
]
deps = [
":storage_proto",
"//base",
"//content/shell:content_shell_lib",
"//net",
"//services/network/public/mojom:cookies_mojom",
"//url",
]
public_deps = [ "//skia" ]
}
Loading

0 comments on commit 3e44f8d

Please sign in to comment.