[SessionService] Adding debug information & fixing app reparenting.
This fixes the app reparenting issue introduced by this CL: https://chromium-review.googlesource.com/c/chromium/src/+/5899682 That CL deleted some session restore stuff that seemed unnecessary. Unfortunately there are no tests in this area. So this CL adds that logic back due to the below bug being found. This CL also adds a lot more helpful information to chrome://internals/session-service. Bug: 373461941 Change-Id: I701e0588c02a2ef5beb59516ad5ffc79dc93f585 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5938537 Auto-Submit: Daniel Murphy <dmurph@chromium.org> Commit-Queue: Daniel Murphy <dmurph@chromium.org> Commit-Queue: Scott Violet <sky@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Cr-Commit-Position: refs/heads/main@{#1369633}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
7f770539c8
commit
c0a5c38911
chrome/browser
sessions
ui
components/sessions/core
@ -4,6 +4,7 @@
|
||||
|
||||
#include "components/sessions/core/command_storage_manager.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "base/functional/bind.h"
|
||||
@ -14,8 +15,10 @@
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#include "base/task/thread_pool.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "base/values.h"
|
||||
#include "components/sessions/core/command_storage_backend.h"
|
||||
#include "components/sessions/core/command_storage_manager_delegate.h"
|
||||
#include "components/sessions/core/session_command.h"
|
||||
#include "crypto/random.h"
|
||||
|
||||
namespace sessions {
|
||||
@ -31,6 +34,14 @@ void AdaptGetLastSessionCommands(
|
||||
std::move(callback).Run(std::move(result.commands), result.error_reading);
|
||||
}
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
base::Value CommandToDebugValue(const SessionCommand& command) {
|
||||
// There is no convenience function to transform the pickled contents into the
|
||||
// payload struct itself, so just output the id for now.
|
||||
return base::Value(command.id());
|
||||
}
|
||||
#endif // DCHECK_IS_ON()
|
||||
|
||||
} // namespace
|
||||
|
||||
CommandStorageManager::CommandStorageManager(
|
||||
@ -133,6 +144,16 @@ void CommandStorageManager::Save() {
|
||||
if (pending_commands_.empty())
|
||||
return;
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
for (const std::unique_ptr<SessionCommand>& command : pending_commands_) {
|
||||
written_commands_reverse_debug_log_.push_front(
|
||||
CommandToDebugValue(*command));
|
||||
}
|
||||
if (written_commands_reverse_debug_log_.size() > kMaxLogSize) {
|
||||
written_commands_reverse_debug_log_.resize(kMaxLogSize);
|
||||
}
|
||||
#endif // DCHECK_IS_ON()
|
||||
|
||||
std::vector<uint8_t> crypto_key;
|
||||
if (use_crypto_ && pending_reset_) {
|
||||
crypto_key = CreateCryptoKey();
|
||||
@ -178,6 +199,24 @@ void CommandStorageManager::GetLastSessionCommands(
|
||||
base::BindOnce(&AdaptGetLastSessionCommands, std::move(callback)));
|
||||
}
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
base::Value CommandStorageManager::ToDebugValue() const {
|
||||
base::Value::Dict debug_value;
|
||||
debug_value.Set("use_crypto", use_crypto_);
|
||||
for (const std::unique_ptr<SessionCommand>& command : pending_commands_) {
|
||||
debug_value.EnsureList("pending_commands")
|
||||
->Append(CommandToDebugValue(*command));
|
||||
}
|
||||
debug_value.Set("pending_reset", pending_reset_);
|
||||
debug_value.Set("commands_since_reset", commands_since_reset_);
|
||||
for (const base::Value& log_item : written_commands_reverse_debug_log_) {
|
||||
debug_value.EnsureList("written_commands_reverse_debug_log")
|
||||
->Append(log_item.Clone());
|
||||
}
|
||||
return base::Value(std::move(debug_value));
|
||||
}
|
||||
#endif // DCHECK_IS_ON()
|
||||
|
||||
void CommandStorageManager::OnErrorWritingToFile() {
|
||||
delegate_->OnErrorWritingSessionCommands();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@ -18,6 +19,10 @@
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
#include "components/sessions/core/sessions_export.h"
|
||||
|
||||
namespace base {
|
||||
class Value;
|
||||
}
|
||||
|
||||
namespace sessions {
|
||||
class CommandStorageManagerDelegate;
|
||||
class SessionCommand;
|
||||
@ -130,6 +135,14 @@ class SESSIONS_EXPORT CommandStorageManager {
|
||||
// deleted.
|
||||
void GetLastSessionCommands(GetCommandsCallback callback);
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
// Returns the state of this class and logs for the
|
||||
// chrome://internals/session-service debug page. The logs are in reverse
|
||||
// order for truncation ease. This value is NOT STABLE - do not rely on it's
|
||||
// contents for anything.
|
||||
base::Value ToDebugValue() const;
|
||||
#endif // DCHECK_IS_ON()
|
||||
|
||||
private:
|
||||
friend class CommandStorageManagerTestHelper;
|
||||
|
||||
@ -160,6 +173,12 @@ class SESSIONS_EXPORT CommandStorageManager {
|
||||
// all tasks *must* be processed in the order they are scheduled.
|
||||
scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
// Used to store debug log entries for this command manager.
|
||||
constexpr static int kMaxLogSize = 100;
|
||||
std::list<base::Value> written_commands_reverse_debug_log_;
|
||||
#endif // DCHECK_IS_ON()
|
||||
|
||||
base::WeakPtrFactory<CommandStorageManager> weak_factory_{this};
|
||||
|
||||
// Used solely for saving after a delay, and not to be used for any other
|
||||
|
Reference in New Issue
Block a user