Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(875)

Unified Diff: chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc

Issue 2601323002: arc: Handle default app not availble case. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc
diff --git a/chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc b/chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc
index 765fea0b6a8e5c6980419ab0de52a07cfe85adb7..21e53335590302c42d3e32b53b4ebd31d07c1633 100644
--- a/chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc
+++ b/chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc
@@ -53,6 +53,9 @@ const char kUninstalled[] = "uninstalled";
constexpr uint32_t kSetNotificationsEnabledMinVersion = 6;
constexpr uint32_t kRequestIconMinVersion = 9;
+constexpr base::TimeDelta kValidateDefaultAppaAvailabilityTimeout =
Luis Héctor Chávez 2017/01/03 19:08:00 nit: s/AppaAvailability/AppAvailability/
khmel 2017/01/03 21:40:56 Thanks!
+ base::TimeDelta::FromSeconds(15);
+
// Provider of write access to a dictionary storing ARC prefs.
class ScopedArcPrefUpdate : public DictionaryPrefUpdate {
public:
@@ -400,6 +403,10 @@ std::unique_ptr<ArcAppListPrefs::PackageInfo> ArcAppListPrefs::GetPackage(
!packages->GetDictionaryWithoutPathExpansion(package_name, &package))
return std::unique_ptr<PackageInfo>();
+ bool uninstalled;
Luis Héctor Chávez 2017/01/03 19:08:00 nit: = false.
khmel 2017/01/03 21:40:56 Done.
+ if (package->GetBoolean(kUninstalled, &uninstalled) && uninstalled)
+ return nullptr;
+
int32_t package_version = 0;
int64_t last_backup_android_id = 0;
int64_t last_backup_time = 0;
@@ -660,6 +667,13 @@ void ArcAppListPrefs::SetDefaltAppsReadyCallback(base::Closure callback) {
default_apps_ready_callback_.Run();
}
+void ArcAppListPrefs::SimulateDefaultAppAvailabilityTimeoutForTesting() {
+ if (!validate_default_app_availability_timeout_.IsRunning())
+ return;
+ validate_default_app_availability_timeout_.Stop();
+ ValidateDefaultAppaAvailability();
+}
+
void ArcAppListPrefs::OnInstanceReady() {
// Init() is also available at version 0.
arc::mojom::AppInstance* app_instance =
@@ -681,6 +695,8 @@ void ArcAppListPrefs::OnInstanceReady() {
void ArcAppListPrefs::OnInstanceClosed() {
DisableAllApps();
installing_packages_count_ = 0;
+ default_apps_installations_.clear();
+ validate_default_app_availability_timeout_.Stop();
binding_.Close();
if (sync_service_) {
@@ -908,10 +924,32 @@ void ArcAppListPrefs::OnAppListRefreshed(
if (!is_initialized_) {
is_initialized_ = true;
+ MaybeSetDefaultAppLoadingTimeout();
UMA_HISTOGRAM_COUNTS_1000("Arc.AppsInstalledAtStartup", ready_apps_.size());
}
}
+void ArcAppListPrefs::ValidateDefaultAppaAvailability() {
Luis Héctor Chávez 2017/01/03 19:08:00 This does not perform validation. How about callin
khmel 2017/01/03 21:40:56 Done.
+ for (const auto& package : default_apps_.GetActivePackages()) {
+ // Check if already installed or installation in progress.
+ if (!GetPackage(package) && !default_apps_installations_.count(package)) {
Luis Héctor Chávez 2017/01/03 19:07:59 nit: elide braces
khmel 2017/01/03 21:40:56 Done.
+ HandlePackageRemoved(package);
+ }
+ }
+}
+
+void ArcAppListPrefs::MaybeSetDefaultAppLoadingTimeout() {
+ // Find at least one not installed defualt app package.
Luis Héctor Chávez 2017/01/03 19:08:00 nit: s/defualt/default/
khmel 2017/01/03 21:40:56 Done.
+ for (const auto& package : default_apps_.GetActivePackages()) {
+ if (!GetPackage(package)) {
+ validate_default_app_availability_timeout_.Start(FROM_HERE,
+ kValidateDefaultAppaAvailabilityTimeout, this,
+ &ArcAppListPrefs::ValidateDefaultAppaAvailability);
+ break;
+ }
+ }
+}
+
void ArcAppListPrefs::OnTaskOrientationLockRequested(
int32_t task_id,
const arc::mojom::OrientationLock orientation_lock) {
@@ -1010,13 +1048,18 @@ std::unordered_set<std::string> ArcAppListPrefs::GetAppsForPackage(
return app_set;
}
-void ArcAppListPrefs::OnPackageRemoved(const std::string& package_name) {
+void ArcAppListPrefs::HandlePackageRemoved(const std::string& package_name) {
const std::unordered_set<std::string> apps_to_remove =
GetAppsForPackage(package_name);
for (const auto& app_id : apps_to_remove)
RemoveApp(app_id);
RemovePackageFromPrefs(prefs_, package_name);
+}
+
+void ArcAppListPrefs::OnPackageRemoved(const std::string& package_name) {
+ HandlePackageRemoved(package_name);
+
for (auto& observer : observer_list_)
observer.OnPackageRemoved(package_name);
}
@@ -1255,14 +1298,26 @@ void ArcAppListPrefs::OnIconInstalled(const std::string& app_id,
observer.OnAppIconUpdated(app_id, scale_factor);
}
-void ArcAppListPrefs::OnInstallationStarted() {
+void ArcAppListPrefs::OnInstallationStarted(
+ const base::Optional<std::string>& package_name) {
// Start new batch installation group if this is first installation.
if (!installing_packages_count_)
++current_batch_installation_revision_;
++installing_packages_count_;
+
+ if (package_name.has_value() && default_apps_.HasPackage(*package_name))
+ default_apps_installations_.insert(*package_name);
}
-void ArcAppListPrefs::OnInstallationFinished() {
+void ArcAppListPrefs::OnInstallationFinished(
+ const base::Optional<std::string>& package_name, bool success) {
+ if (package_name.has_value() && default_apps_.HasPackage(*package_name)) {
+ default_apps_installations_.erase(*package_name);
+
+ if (!success && !GetPackage(*package_name))
+ HandlePackageRemoved(*package_name);
Luis Héctor Chávez 2017/01/03 19:07:59 Isn't this a no-op when !GetPackage(*package_name)
khmel 2017/01/03 21:40:56 HandlePackageRemoved explicitly marks package unin
+ }
+
if (!installing_packages_count_) {
VLOG(2) << "Received unexpected installation finished event";
return;

Powered by Google App Engine
This is Rietveld 408576698