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 16, 2025
1 parent 165ac0e commit 6b3ae8d
Show file tree
Hide file tree
Showing 9 changed files with 474 additions and 2 deletions.
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 Down Expand Up @@ -48,6 +49,7 @@ if (!is_android) {

deps = [
"//cobalt/renderer:renderer",
"//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 @@ -242,6 +242,7 @@ shared_library("libcobalt_content_shell_content_view") {
deps = [
":content_shell_jni_headers",
"//cobalt/renderer:renderer",
"//cobalt/migrate_storage_record",
"//cobalt/user_agent",

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

#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 {

#define COBALT_BRAND_NAME "Cobalt"
Expand Down
24 changes: 24 additions & 0 deletions cobalt/cobalt_web_contents_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,32 @@

#include "cobalt/cobalt_web_contents_observer.h"

#include "cobalt/migrate_storage_record/migrate.h"

namespace cobalt {

namespace {

std::atomic_bool migration_attempted{false};

} // namespace

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);
}
}
}

// Placeholder for a WebContentsObserver override
void CobaltWebContentsObserver::PrimaryMainDocumentElementAvailable() {
LOG(INFO) << "Cobalt::PrimaryMainDocumentElementAvailable";
Expand Down
2 changes: 2 additions & 0 deletions cobalt/cobalt_web_contents_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CobaltWebContentsObserver : public content::WebContentsObserver {
explicit CobaltWebContentsObserver(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {}

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

Expand Down
27 changes: 27 additions & 0 deletions cobalt/migrate_storage_record/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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",
"//starboard/common",
"//url",
]
public_deps = [ "//skia" ]
}
Loading

0 comments on commit 6b3ae8d

Please sign in to comment.