Commit 69dc7cf5 authored by Polina Bondarenko's avatar Polina Bondarenko Committed by Commit Bot

arc: add clear snapshot flow.

Add parsing/syncing to local state arc.snapshot pref of snapshot related info.
Add blocked UI mode Chrome start up along with clearing outdated
snapshots flow.
Currently, ArcDataSnapshotdManager functionality is disabled for testing.

BUG=b:161221001
TEST=components_unittests

Change-Id: I6ccfe44c3b85a6dc864914609fa41c071e81e4a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2385396
Commit-Queue: Polina Bondarenko <pbond@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Auto-Submit: Polina Bondarenko <pbond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809390}
parent 39eded94
...@@ -655,7 +655,8 @@ void ChromeBrowserMainPartsChromeos::PreProfileInit() { ...@@ -655,7 +655,8 @@ void ChromeBrowserMainPartsChromeos::PreProfileInit() {
g_browser_process->platform_part()->InitializeChromeUserManager(); g_browser_process->platform_part()->InitializeChromeUserManager();
arc_data_snapshotd_manager_ = arc_data_snapshotd_manager_ =
std::make_unique<arc::data_snapshotd::ArcDataSnapshotdManager>(); std::make_unique<arc::data_snapshotd::ArcDataSnapshotdManager>(
g_browser_process->local_state());
if (base::FeatureList::IsEnabled(::features::kWilcoDtc)) if (base::FeatureList::IsEnabled(::features::kWilcoDtc))
wilco_dtc_supportd_manager_ = std::make_unique<WilcoDtcSupportdManager>(); wilco_dtc_supportd_manager_ = std::make_unique<WilcoDtcSupportdManager>();
......
...@@ -148,6 +148,7 @@ static_library("arc") { ...@@ -148,6 +148,7 @@ static_library("arc") {
"//ui/events", "//ui/events",
"//ui/events:dom_keycode_converter", "//ui/events:dom_keycode_converter",
"//ui/events/ozone", "//ui/events/ozone",
"//ui/ozone",
"//ui/wm/public", "//ui/wm/public",
"//url:url", "//url:url",
] ]
...@@ -448,6 +449,7 @@ source_set("unit_tests") { ...@@ -448,6 +449,7 @@ source_set("unit_tests") {
"//ui/base/ime", "//ui/base/ime",
"//ui/events", "//ui/events",
"//ui/events:dom_keycode_converter", "//ui/events:dom_keycode_converter",
"//ui/ozone",
"//url:url", "//url:url",
] ]
} }
......
...@@ -129,9 +129,13 @@ const char kStabilityMetrics[] = "arc.metrics.stability"; ...@@ -129,9 +129,13 @@ const char kStabilityMetrics[] = "arc.metrics.stability";
// Android properties. Used only in ARCVM. // Android properties. Used only in ARCVM.
const char kArcSerialNumberSalt[] = "arc.serialno_salt"; const char kArcSerialNumberSalt[] = "arc.serialno_salt";
// A preferece to keep ARC snapshot related info in dictionary.
const char kArcSnapshotInfo[] = "arc.snapshot";
void RegisterLocalStatePrefs(PrefRegistrySimple* registry) { void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
// Sorted in lexicographical order. // Sorted in lexicographical order.
registry->RegisterStringPref(kArcSerialNumberSalt, std::string()); registry->RegisterStringPref(kArcSerialNumberSalt, std::string());
registry->RegisterDictionaryPref(kArcSnapshotInfo);
registry->RegisterBooleanPref(kNativeBridge64BitSupportExperimentEnabled, registry->RegisterBooleanPref(kNativeBridge64BitSupportExperimentEnabled,
false); false);
registry->RegisterDictionaryPref(kStabilityMetrics); registry->RegisterDictionaryPref(kStabilityMetrics);
......
...@@ -45,6 +45,7 @@ ARC_EXPORT extern const char kEngagementPrefsPrefix[]; ...@@ -45,6 +45,7 @@ ARC_EXPORT extern const char kEngagementPrefsPrefix[];
// Local state prefs in lexicographical order. // Local state prefs in lexicographical order.
ARC_EXPORT extern const char kArcSerialNumberSalt[]; ARC_EXPORT extern const char kArcSerialNumberSalt[];
ARC_EXPORT extern const char kArcSnapshotInfo[];
ARC_EXPORT extern const char kNativeBridge64BitSupportExperimentEnabled[]; ARC_EXPORT extern const char kNativeBridge64BitSupportExperimentEnabled[];
ARC_EXPORT extern const char kStabilityMetrics[]; ARC_EXPORT extern const char kStabilityMetrics[];
......
include_rules = [
"+ui/ozone/public/ozone_switches.h",
]
...@@ -26,7 +26,9 @@ constexpr int kMaxConnectionAttemptCount = 5; ...@@ -26,7 +26,9 @@ constexpr int kMaxConnectionAttemptCount = 5;
} // namespace } // namespace
ArcDataSnapshotdBridge::ArcDataSnapshotdBridge() { ArcDataSnapshotdBridge::ArcDataSnapshotdBridge(
base::OnceClosure on_bridge_available_callback)
: on_bridge_available_callback_(std::move(on_bridge_available_callback)) {
WaitForDBusService(); WaitForDBusService();
} }
...@@ -48,6 +50,7 @@ void ArcDataSnapshotdBridge::WaitForDBusService() { ...@@ -48,6 +50,7 @@ void ArcDataSnapshotdBridge::WaitForDBusService() {
LOG(WARNING) LOG(WARNING)
<< "Stopping attempts to connect to arc-data-snapshotd - too many " << "Stopping attempts to connect to arc-data-snapshotd - too many "
"unsuccessful attempts in a row"; "unsuccessful attempts in a row";
std::move(on_bridge_available_callback_).Run();
return; return;
} }
++connection_attempt_; ++connection_attempt_;
...@@ -80,6 +83,7 @@ void ArcDataSnapshotdBridge::OnWaitedForDBusService(bool service_is_available) { ...@@ -80,6 +83,7 @@ void ArcDataSnapshotdBridge::OnWaitedForDBusService(bool service_is_available) {
// ScheduleWaitingForDBusService(). // ScheduleWaitingForDBusService().
dbus_waiting_weak_ptr_factory_.InvalidateWeakPtrs(); dbus_waiting_weak_ptr_factory_.InvalidateWeakPtrs();
is_available_ = true; is_available_ = true;
std::move(on_bridge_available_callback_).Run();
} }
void ArcDataSnapshotdBridge::GenerateKeyPair( void ArcDataSnapshotdBridge::GenerateKeyPair(
...@@ -96,5 +100,18 @@ void ArcDataSnapshotdBridge::GenerateKeyPair( ...@@ -96,5 +100,18 @@ void ArcDataSnapshotdBridge::GenerateKeyPair(
->GenerateKeyPair(std::move(callback)); ->GenerateKeyPair(std::move(callback));
} }
void ArcDataSnapshotdBridge::ClearSnapshot(
bool last,
base::OnceCallback<void(bool)> callback) {
if (!is_available_) {
LOG(ERROR) << "ClearSnapshot call when D-Bus service is not available.";
std::move(callback).Run(false /* success */);
return;
}
VLOG(1) << "ClearSnapshot via D-Bus";
// TODO(pbond): implement
std::move(callback).Run(true /* success */);
}
} // namespace data_snapshotd } // namespace data_snapshotd
} // namespace arc } // namespace arc
...@@ -17,7 +17,8 @@ namespace data_snapshotd { ...@@ -17,7 +17,8 @@ namespace data_snapshotd {
// operations to it. // operations to it.
class ArcDataSnapshotdBridge { class ArcDataSnapshotdBridge {
public: public:
ArcDataSnapshotdBridge(); explicit ArcDataSnapshotdBridge(
base::OnceClosure on_bridge_available_callback);
ArcDataSnapshotdBridge(const ArcDataSnapshotdBridge&) = delete; ArcDataSnapshotdBridge(const ArcDataSnapshotdBridge&) = delete;
ArcDataSnapshotdBridge& operator=(const ArcDataSnapshotdBridge&) = delete; ArcDataSnapshotdBridge& operator=(const ArcDataSnapshotdBridge&) = delete;
~ArcDataSnapshotdBridge(); ~ArcDataSnapshotdBridge();
...@@ -27,6 +28,7 @@ class ArcDataSnapshotdBridge { ...@@ -27,6 +28,7 @@ class ArcDataSnapshotdBridge {
// Delegates the key pair generation to arc-data-snapshotd daemon. // Delegates the key pair generation to arc-data-snapshotd daemon.
void GenerateKeyPair(base::OnceCallback<void(bool)> callback); void GenerateKeyPair(base::OnceCallback<void(bool)> callback);
void ClearSnapshot(bool last, base::OnceCallback<void(bool)> callback);
bool is_available_for_testing() { return is_available_; } bool is_available_for_testing() { return is_available_; }
...@@ -40,6 +42,10 @@ class ArcDataSnapshotdBridge { ...@@ -40,6 +42,10 @@ class ArcDataSnapshotdBridge {
// finishes. // finishes.
void OnWaitedForDBusService(bool service_is_available); void OnWaitedForDBusService(bool service_is_available);
// Callback passed in constructor and called once the D-Bus bridge is set up
// or the number of max attempts exceeded.
base::OnceClosure on_bridge_available_callback_;
// Current consecutive connection attempt number. // Current consecutive connection attempt number.
int connection_attempt_ = 0; int connection_attempt_ = 0;
// True if D-Bus service is available. // True if D-Bus service is available.
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include "base/bind_helpers.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
...@@ -62,7 +63,7 @@ class ArcDataSnapshotdBridgeTest : public testing::Test { ...@@ -62,7 +63,7 @@ class ArcDataSnapshotdBridgeTest : public testing::Test {
// Test basic scenario: D-Bus service is available immediately. // Test basic scenario: D-Bus service is available immediately.
TEST_F(ArcDataSnapshotdBridgeTest, ServiceAvailable) { TEST_F(ArcDataSnapshotdBridgeTest, ServiceAvailable) {
dbus_client()->set_available(true /* is_available */); dbus_client()->set_available(true /* is_available */);
ArcDataSnapshotdBridge bridge; ArcDataSnapshotdBridge bridge{base::DoNothing()};
EXPECT_FALSE(bridge.is_available_for_testing()); EXPECT_FALSE(bridge.is_available_for_testing());
RunGenerateKeyPair(&bridge, false /* expected_result */); RunGenerateKeyPair(&bridge, false /* expected_result */);
...@@ -75,7 +76,7 @@ TEST_F(ArcDataSnapshotdBridgeTest, ServiceAvailable) { ...@@ -75,7 +76,7 @@ TEST_F(ArcDataSnapshotdBridgeTest, ServiceAvailable) {
// Test basic scenario: D-Bus service is not available. // Test basic scenario: D-Bus service is not available.
TEST_F(ArcDataSnapshotdBridgeTest, ServiceUnavailable) { TEST_F(ArcDataSnapshotdBridgeTest, ServiceUnavailable) {
dbus_client()->set_available(false /* is_available */); dbus_client()->set_available(false /* is_available */);
ArcDataSnapshotdBridge bridge; ArcDataSnapshotdBridge bridge{base::DoNothing()};
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
...@@ -86,7 +87,7 @@ TEST_F(ArcDataSnapshotdBridgeTest, ServiceUnavailable) { ...@@ -86,7 +87,7 @@ TEST_F(ArcDataSnapshotdBridgeTest, ServiceUnavailable) {
// Test that service is available from the max attempt. // Test that service is available from the max attempt.
TEST_F(ArcDataSnapshotdBridgeTest, ServiceAvailableMaxAttempt) { TEST_F(ArcDataSnapshotdBridgeTest, ServiceAvailableMaxAttempt) {
dbus_client()->set_available(false /* is_available */); dbus_client()->set_available(false /* is_available */);
ArcDataSnapshotdBridge bridge; ArcDataSnapshotdBridge bridge{base::DoNothing()};
// Not available from the first attempt. // Not available from the first attempt.
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
...@@ -109,7 +110,7 @@ TEST_F(ArcDataSnapshotdBridgeTest, ServiceAvailableMaxAttempt) { ...@@ -109,7 +110,7 @@ TEST_F(ArcDataSnapshotdBridgeTest, ServiceAvailableMaxAttempt) {
// Test that service is available from the max + 1 attempt and is not picked up. // Test that service is available from the max + 1 attempt and is not picked up.
TEST_F(ArcDataSnapshotdBridgeTest, ServiceUnavailableMaxAttempts) { TEST_F(ArcDataSnapshotdBridgeTest, ServiceUnavailableMaxAttempts) {
dbus_client()->set_available(false /* is_available */); dbus_client()->set_available(false /* is_available */);
ArcDataSnapshotdBridge bridge; ArcDataSnapshotdBridge bridge{base::DoNothing()};
// Not available from the first attempt. // Not available from the first attempt.
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
......
...@@ -6,9 +6,19 @@ ...@@ -6,9 +6,19 @@
#define COMPONENTS_ARC_ENTERPRISE_ARC_DATA_SNAPSHOTD_MANAGER_H_ #define COMPONENTS_ARC_ENTERPRISE_ARC_DATA_SNAPSHOTD_MANAGER_H_
#include <memory> #include <memory>
#include <string>
#include "base/callback.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
class PrefService;
namespace base {
class Value;
} // namespace base
namespace arc { namespace arc {
namespace data_snapshotd { namespace data_snapshotd {
...@@ -18,27 +28,182 @@ class ArcDataSnapshotdBridge; ...@@ -18,27 +28,182 @@ class ArcDataSnapshotdBridge;
// the arc-data-snapshotd daemon. // the arc-data-snapshotd daemon.
class ArcDataSnapshotdManager final { class ArcDataSnapshotdManager final {
public: public:
ArcDataSnapshotdManager(); // State of the flow.
enum class State {
kNone,
// Blocked UI mode is ON.
kBlockedUi,
// In blocked UI mode, MGS can be launched.
kMgsToLaunch,
// MGS is launched to create a snapshot.
kMgsLaunched,
// User session was restored.
kRestored,
};
// This class operates with a snapshot related info either last or
// backed-up (previous): stores and keeps in sync with an appropriate
// preference in local state.
class SnapshotInfo {
public:
SnapshotInfo(const base::Value* value, bool last);
SnapshotInfo(const SnapshotInfo&) = delete;
SnapshotInfo& operator=(const SnapshotInfo&) = delete;
~SnapshotInfo();
// Creates from the passed arguments instead of constructing it from
// dictionary.
static std::unique_ptr<SnapshotInfo> CreateForTesting(
const std::string& os_version,
const std::string& creation_date,
bool verified,
bool updated,
bool last);
// Syncs stored snapshot info to dictionaty |value|.
void Sync(base::Value* value);
// Returns true if snapshot is expired.
bool IsExpired() const;
// Returns true if OS version is updated, since the snapshot has been taken.
bool IsOsVersionUpdated() const;
bool is_last() const { return is_last_; }
private:
SnapshotInfo(const std::string& os_version,
const std::string& creation_date,
bool verified,
bool updated,
bool last);
// Returns dictionary path in arc.snapshot local state preference.
std::string GetDictPath() const;
bool is_last_;
// Values should be kept in sync with values stored in arc.snapshot.last or
// arc.snapshot.previous preferences.
std::string os_version_;
std::string creation_date_;
bool verified_ = false;
bool updated_ = false;
};
// This class operates with a snapshot related info including mode and
// creation flow time: stores and keeps in sync with arc.snapshot preference
// in local state.
class Snapshot {
public:
// Snapshot does not own |local_state|, it must be non nullptr and must
// outlive the instance.
explicit Snapshot(PrefService* local_state);
Snapshot(const Snapshot&) = delete;
Snapshot& operator=(const Snapshot&) = delete;
~Snapshot();
// Creates an instance from the passed arguments instead of reading it from
// |local_state|.
static std::unique_ptr<Snapshot> CreateForTesting(
PrefService* local_state,
bool blocked_ui_mode,
const std::string& started_date,
std::unique_ptr<SnapshotInfo> last,
std::unique_ptr<SnapshotInfo> previous);
// Parses the snapshot info from arc.snapshot preference.
void Parse();
// Syncs stored snapshot info to local state.
void Sync();
// Clears snapshot related info in arc.snapshot preference either last
// if |last| is true or previous otherwise.
void ClearSnapshot(bool last);
bool is_blocked_ui_mode() const { return blocked_ui_mode_; }
SnapshotInfo* last() { return last_.get(); }
SnapshotInfo* previous() { return previous_.get(); }
private:
Snapshot(PrefService* local_state,
bool blocked_ui_mode,
const std::string& started_date,
std::unique_ptr<SnapshotInfo> last,
std::unique_ptr<SnapshotInfo> previous);
// Unowned pointer - outlives this instance.
PrefService* const local_state_;
// Values should be kept in sync with values stored in arc.snapshot
// preference.
bool blocked_ui_mode_ = false;
std::string started_date_;
std::unique_ptr<SnapshotInfo> last_;
std::unique_ptr<SnapshotInfo> previous_;
};
explicit ArcDataSnapshotdManager(PrefService* local_state);
ArcDataSnapshotdManager(const ArcDataSnapshotdManager&) = delete; ArcDataSnapshotdManager(const ArcDataSnapshotdManager&) = delete;
ArcDataSnapshotdManager& operator=(const ArcDataSnapshotdManager&) = delete; ArcDataSnapshotdManager& operator=(const ArcDataSnapshotdManager&) = delete;
~ArcDataSnapshotdManager(); ~ArcDataSnapshotdManager();
// Starts arc-data-snapshotd. // Starts arc-data-snapshotd.
void StartDaemon(); void EnsureDaemonStarted(base::OnceClosure callback);
// Stops arc-data-snapshotd. // Stops arc-data-snapshotd.
void StopDaemon(); void EnsureDaemonStopped(base::OnceClosure callback);
// Get |bridge_| for testing. // Get |bridge_| for testing.
ArcDataSnapshotdBridge* bridge() { return bridge_.get(); } ArcDataSnapshotdBridge* bridge() { return bridge_.get(); }
State state() const { return state_; }
static void set_snapshot_enabled_for_testing(bool enabled) {
is_snapshot_enabled_for_testing_ = enabled;
}
static bool is_snapshot_enabled_for_testing() {
return is_snapshot_enabled_for_testing_;
}
private: private:
void OnDaemonStarted(bool success); // Attempts to arc-data-snapshotd daemon regardless of state of the class.
void OnDaemonStopped(bool success); // Runs |callback| once finished.
void StopDaemon(base::OnceClosure callback);
// Attempts to clear snapshots.
void DoClearSnapshots();
// Attempts to clear the passed snapshot, calls |callback| once finished.
// |success| indicates a successfully or not the previous operation has been
// finished.
void DoClearSnapshot(SnapshotInfo* snapshot,
base::OnceCallback<void(bool)> callback,
bool success);
// Delegates operations to |bridge_|
void GenerateKeyPair();
void ClearSnapshot(bool last, base::OnceCallback<void(bool)> callback);
// Called once the outdated snapshots were removed or ensured that there are
// no outdated snapshots.
void OnSnapshotsCleared(bool success);
// Called once GenerateKeyPair is finished with a result |success|.
void OnKeyPairGenerated(bool success);
// Called once arc-data-snapshotd starting process is finished with result
// |success|, runs |callback| afterwards.
void OnDaemonStarted(base::OnceClosure callback, bool success);
// Called once arc-data-snapshotd stopping process is finished with result
// |success", runs |callback| afterwards.
void OnDaemonStopped(base::OnceClosure callback, bool success);
static bool is_snapshot_enabled_for_testing_;
State state_ = State::kNone;
Snapshot snapshot_;
std::unique_ptr<ArcDataSnapshotdBridge> bridge_; std::unique_ptr<ArcDataSnapshotdBridge> bridge_;
// Note: This should remain the last member so it'll be destroyed and // Used for cancelling previously posted tasks to daemon.
// invalidate its weak pointers before any other members are destroyed. base::WeakPtrFactory<ArcDataSnapshotdManager> daemon_weak_ptr_factory_{this};
// WeakPtrFactory to use for callbacks.
base::WeakPtrFactory<ArcDataSnapshotdManager> weak_ptr_factory_{this}; base::WeakPtrFactory<ArcDataSnapshotdManager> weak_ptr_factory_{this};
}; };
......
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