Commit 95bfb719 authored by khmel@google.com's avatar khmel@google.com Committed by Commit Bot

arc: Add ability clean up data folder on each start.

Test: unit_test + manually
Bug: 834439
Change-Id: Id3bee682062eeacf7f88ea079ea37bdd4cafe09e
Reviewed-on: https://chromium-review.googlesource.com/1023068Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Yury Khmel <khmel@google.com>
Cr-Commit-Position: refs/heads/master@{#553463}
parent 5432155f
...@@ -50,6 +50,12 @@ void ArcPlayStoreEnabledPreferenceHandler::Start() { ...@@ -50,6 +50,12 @@ void ArcPlayStoreEnabledPreferenceHandler::Start() {
VLOG(1) << "Start observing Google Play Store enabled preference. " VLOG(1) << "Start observing Google Play Store enabled preference. "
<< "Initial value: " << is_play_store_enabled; << "Initial value: " << is_play_store_enabled;
// Force data clean if needed.
if (IsArcDataCleanupOnStartRequested()) {
VLOG(1) << "Request to cleanup data on start.";
arc_session_manager_->RequestArcDataRemoval();
}
// If the OOBE or Assistant Wizard screen is shown, don't kill the // If the OOBE or Assistant Wizard screen is shown, don't kill the
// mini-container. We'll do it if and when the user declines the TOS. We need // mini-container. We'll do it if and when the user declines the TOS. We need
// to check |is_play_store_enabled| to handle the case where |kArcEnabled| is // to check |is_play_store_enabled| to handle the case where |kArcEnabled| is
......
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_command_line.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/arc/arc_optin_uma.h" #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
#include "chrome/browser/chromeos/arc/arc_play_store_enabled_preference_handler.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h" #include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "chrome/browser/chromeos/arc/arc_util.h" #include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.h" #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.h"
...@@ -664,6 +666,67 @@ TEST_F(ArcSessionManagerTest, IsDirectlyStartedOnInternalRestart) { ...@@ -664,6 +666,67 @@ TEST_F(ArcSessionManagerTest, IsDirectlyStartedOnInternalRestart) {
arc_session_manager()->Shutdown(); arc_session_manager()->Shutdown();
} }
// In case of the next start ArcSessionManager should go through remove data
// folder phase before negotiating terms of service.
TEST_F(ArcSessionManagerTest, DataCleanUpOnFirstStart) {
base::test::ScopedCommandLine command_line;
command_line.GetProcessCommandLine()->AppendSwitch(
chromeos::switches::kArcDataCleanupOnStart);
arc_session_manager()->SetProfile(profile());
arc_session_manager()->Initialize();
ArcPlayStoreEnabledPreferenceHandler handler(profile(),
arc_session_manager());
handler.Start();
EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
arc_session_manager()->state());
base::RunLoop().RunUntilIdle();
EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state());
profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE,
arc_session_manager()->state());
arc_session_manager()->OnTermsOfServiceNegotiatedForTesting(true);
EXPECT_EQ(ArcSessionManager::State::CHECKING_ANDROID_MANAGEMENT,
arc_session_manager()->state());
arc_session_manager()->StartArcForTesting();
EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
arc_session_manager()->Shutdown();
}
// In case of the next start ArcSessionManager should go through remove data
// folder phase before activating.
TEST_F(ArcSessionManagerTest, DataCleanUpOnNextStart) {
base::test::ScopedCommandLine command_line;
command_line.GetProcessCommandLine()->AppendSwitch(
chromeos::switches::kArcDataCleanupOnStart);
PrefService* const prefs = profile()->GetPrefs();
prefs->SetBoolean(prefs::kArcTermsAccepted, true);
prefs->SetBoolean(prefs::kArcSignedIn, true);
prefs->SetBoolean(prefs::kArcEnabled, true);
arc_session_manager()->SetProfile(profile());
arc_session_manager()->Initialize();
ArcPlayStoreEnabledPreferenceHandler handler(profile(),
arc_session_manager());
handler.Start();
EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
arc_session_manager()->state());
base::RunLoop().RunUntilIdle();
EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
arc_session_manager()->Shutdown();
}
class ArcSessionManagerArcAlwaysStartTest : public ArcSessionManagerTest { class ArcSessionManagerArcAlwaysStartTest : public ArcSessionManagerTest {
public: public:
ArcSessionManagerArcAlwaysStartTest() = default; ArcSessionManagerArcAlwaysStartTest() = default;
......
...@@ -90,6 +90,9 @@ const char kArcAvailability[] = "arc-availability"; ...@@ -90,6 +90,9 @@ const char kArcAvailability[] = "arc-availability";
// Signals the availability of the ARC instance on this device. // Signals the availability of the ARC instance on this device.
const char kArcAvailable[] = "arc-available"; const char kArcAvailable[] = "arc-available";
// Flag that forces ARC data be cleaned on each start.
const char kArcDataCleanupOnStart[] = "arc-data-cleanup-on-start";
// Used in autotest to specifies how to handle packages cache. Can be // Used in autotest to specifies how to handle packages cache. Can be
// copy - copy resulting packages.xml to the temporary directory. // copy - copy resulting packages.xml to the temporary directory.
// skip-copy - skip initial packages cache setup and copy resulting packages.xml // skip-copy - skip initial packages cache setup and copy resulting packages.xml
......
...@@ -30,6 +30,7 @@ CHROMEOS_EXPORT extern const char kAppAutoLaunched[]; ...@@ -30,6 +30,7 @@ CHROMEOS_EXPORT extern const char kAppAutoLaunched[];
CHROMEOS_EXPORT extern const char kAppOemManifestFile[]; CHROMEOS_EXPORT extern const char kAppOemManifestFile[];
CHROMEOS_EXPORT extern const char kArcAvailability[]; CHROMEOS_EXPORT extern const char kArcAvailability[];
CHROMEOS_EXPORT extern const char kArcAvailable[]; CHROMEOS_EXPORT extern const char kArcAvailable[];
CHROMEOS_EXPORT extern const char kArcDataCleanupOnStart[];
CHROMEOS_EXPORT extern const char kArcPackagesCacheMode[]; CHROMEOS_EXPORT extern const char kArcPackagesCacheMode[];
CHROMEOS_EXPORT extern const char kArcStartMode[]; CHROMEOS_EXPORT extern const char kArcStartMode[];
CHROMEOS_EXPORT extern const char kArcTransitionMigrationRequired[]; CHROMEOS_EXPORT extern const char kArcTransitionMigrationRequired[];
......
...@@ -176,8 +176,7 @@ bool IsArcAllowedForUser(const user_manager::User* user) { ...@@ -176,8 +176,7 @@ bool IsArcAllowedForUser(const user_manager::User* user) {
} }
bool IsArcOptInVerificationDisabled() { bool IsArcOptInVerificationDisabled() {
const auto* command_line = base::CommandLine::ForCurrentProcess(); return base::CommandLine::ForCurrentProcess()->HasSwitch(
return command_line->HasSwitch(
chromeos::switches::kDisableArcOptInVerification); chromeos::switches::kDisableArcOptInVerification);
} }
...@@ -202,4 +201,9 @@ void SetArcCpuRestriction(bool do_restrict) { ...@@ -202,4 +201,9 @@ void SetArcCpuRestriction(bool do_restrict) {
state, base::BindOnce(SetArcCpuRestrictionCallback, state)); state, base::BindOnce(SetArcCpuRestrictionCallback, state));
} }
bool IsArcDataCleanupOnStartRequested() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kArcDataCleanupOnStart);
}
} // namespace arc } // namespace arc
...@@ -97,6 +97,9 @@ bool IsArcOptInVerificationDisabled(); ...@@ -97,6 +97,9 @@ bool IsArcOptInVerificationDisabled();
// |window| is nullptr, returns false. // |window| is nullptr, returns false.
bool IsArcAppWindow(aura::Window* window); bool IsArcAppWindow(aura::Window* window);
// Returns true if data clean up is requested for each ARC start.
bool IsArcDataCleanupOnStartRequested();
// Adjusts the amount of CPU the ARC instance is allowed to use. When // Adjusts the amount of CPU the ARC instance is allowed to use. When
// |do_restrict| is true, the limit is adjusted so ARC can only use tightly // |do_restrict| is true, the limit is adjusted so ARC can only use tightly
// restricted CPU resources. // restricted CPU resources.
......
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