Chromium Code Reviews| 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 7ab5c3bfa10207f4c0d78b7ffa562c8ad99d0f9b..00740fc1902dd440c214fce1aebc0df30ee4ba20 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 |
| @@ -14,9 +14,12 @@ |
| #include "base/metrics/histogram_macros.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/task_runner_util.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" |
| #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| +#include "chrome/browser/ui/app_list/arc/arc_package_syncable_service.h" |
| #include "chrome/common/pref_names.h" |
| +#include "components/arc/arc_bridge_service.h" |
|
Luis Héctor Chávez
2016/07/25 17:31:17
You should be able to remove this import. (If you
lgcheng
2016/07/25 20:45:17
Keep it for browser_test destruction.
|
| #include "components/crx_file/id_util.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| #include "components/prefs/scoped_user_pref_update.h" |
| @@ -193,9 +196,10 @@ void RemovePackageFromPrefs(PrefService* prefs, |
| } // namespace |
| // static |
| -ArcAppListPrefs* ArcAppListPrefs::Create(const base::FilePath& base_path, |
| - PrefService* prefs) { |
| - return new ArcAppListPrefs(base_path, prefs); |
| +ArcAppListPrefs* ArcAppListPrefs::Create( |
| + Profile* profile, |
| + arc::InstanceHolder<arc::mojom::AppInstance>* app_instance_holder) { |
| + return new ArcAppListPrefs(profile, app_instance_holder); |
| } |
| // static |
| @@ -218,9 +222,19 @@ std::string ArcAppListPrefs::GetAppId(const std::string& package_name, |
| return crx_file::id_util::GenerateId(input); |
| } |
| -ArcAppListPrefs::ArcAppListPrefs(const base::FilePath& base_path, |
| - PrefService* prefs) |
| - : prefs_(prefs), binding_(this), weak_ptr_factory_(this) { |
| +ArcAppListPrefs::ArcAppListPrefs( |
| + Profile* profile, |
| + arc::InstanceHolder<arc::mojom::AppInstance>* app_instance_holder) |
| + : prefs_(nullptr), |
| + profile_(profile), |
|
Luis Héctor Chávez
2016/07/25 17:31:17
Can you reorder the declaration of the members so
lgcheng
2016/07/25 20:45:16
Done.
|
| + app_instance_holder_(app_instance_holder), |
| + sync_service_(nullptr), |
| + binding_(this), |
| + weak_ptr_factory_(this) { |
| + DCHECK(profile); |
| + DCHECK(app_instance_holder); |
| + const base::FilePath& base_path = profile->GetPath(); |
| + prefs_ = profile->GetPrefs(); |
| base_path_ = base_path.AppendASCII(prefs::kArcApps); |
| arc::ArcAuthService* auth_service = arc::ArcAuthService::Get(); |
| @@ -231,21 +245,15 @@ ArcAppListPrefs::ArcAppListPrefs(const base::FilePath& base_path, |
| OnOptInEnabled(auth_service->IsArcEnabled()); |
| auth_service->AddObserver(this); |
| - arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| - DCHECK(bridge_service); |
| - |
| - bridge_service->app()->AddObserver(this); |
| - bridge_service->AddObserver(this); |
| - if (!bridge_service->ready()) |
| - OnBridgeStopped(arc::ArcBridgeService::StopReason::SHUTDOWN); |
| + app_instance_holder_->AddObserver(this); |
| + if (!app_instance_holder_->instance()) |
| + OnInstanceClosed(); |
| } |
| ArcAppListPrefs::~ArcAppListPrefs() { |
| arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
|
Luis Héctor Chávez
2016/07/25 17:31:17
Not needed anymore.
lgcheng
2016/07/25 20:45:17
Keep this reference for browser_test destruction.
|
| - if (bridge_service) { |
| - bridge_service->RemoveObserver(this); |
| - bridge_service->app()->RemoveObserver(this); |
| - } |
| + if (bridge_service) |
| + app_instance_holder_->RemoveObserver(this); |
| arc::ArcAuthService* auth_service = arc::ArcAuthService::Get(); |
| if (auth_service) |
| @@ -299,12 +307,7 @@ void ArcAppListPrefs::RequestIcon(const std::string& app_id, |
| return; |
| } |
| - arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| - if (!bridge_service) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - arc::mojom::AppInstance* app_instance = bridge_service->app()->instance(); |
| + arc::mojom::AppInstance* app_instance = app_instance_holder_->instance(); |
| if (!app_instance) { |
| // AppInstance should be ready since we have app_id in ready_apps_. |
| NOTREACHED(); |
| @@ -353,20 +356,14 @@ void ArcAppListPrefs::SetNotificationsEnabled(const std::string& app_id, |
| return; |
| } |
| - arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| - if (!bridge_service) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - |
| - arc::mojom::AppInstance* app_instance = bridge_service->app()->instance(); |
| + arc::mojom::AppInstance* app_instance = app_instance_holder_->instance(); |
| if (!app_instance) { |
| // AppInstance should be ready since we have app_id in ready_apps_. |
| NOTREACHED(); |
| return; |
| } |
| - if (bridge_service->app()->version() < kSetNotificationsEnabledMinVersion) { |
| + if (app_instance_holder_->version() < kSetNotificationsEnabledMinVersion) { |
| VLOG(2) << "app version is too small to set notifications enabled."; |
| return; |
| } |
| @@ -563,18 +560,8 @@ void ArcAppListPrefs::OnOptInEnabled(bool enabled) { |
| RemoveAllApps(); |
| } |
| -void ArcAppListPrefs::OnBridgeStopped( |
| - arc::ArcBridgeService::StopReason reason) { |
| - DisableAllApps(); |
| -} |
| - |
| void ArcAppListPrefs::OnInstanceReady() { |
| - arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| - if (!bridge_service) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - arc::mojom::AppInstance* app_instance = bridge_service->app()->instance(); |
| + arc::mojom::AppInstance* app_instance = app_instance_holder_->instance(); |
| if (!app_instance) { |
| VLOG(2) << "Request to refresh app list when bridge service is not ready."; |
| return; |
| @@ -582,10 +569,19 @@ void ArcAppListPrefs::OnInstanceReady() { |
| app_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| app_instance->RefreshAppList(); |
| + |
| + // Start ArcPackageSyncService. |
| + sync_service_ = arc::ArcPackageSyncableService::Get(profile_); |
| + DCHECK(sync_service_); |
| + sync_service_->SyncStarted(); |
| } |
| void ArcAppListPrefs::OnInstanceClosed() { |
| - ready_apps_.clear(); |
| + DisableAllApps(); |
| + binding_.Close(); |
| + |
| + if (sync_service_) |
| + sync_service_->StopSyncing(syncer::ARC_PACKAGE); |
|
Luis Héctor Chávez
2016/07/25 17:31:17
nit:
if (sync_service_) {
sync_service_...
sy
lgcheng
2016/07/25 20:45:16
Done
|
| } |
| void ArcAppListPrefs::AddAppAndShortcut( |
| @@ -777,6 +773,7 @@ void ArcAppListPrefs::OnPackageRemoved(const mojo::String& package_name) { |
| RemoveApp(app_id); |
| RemovePackageFromPrefs(prefs_, package_name); |
| + FOR_EACH_OBSERVER(Observer, observer_list_, OnPackageRemoved(package_name)); |
| } |
| void ArcAppListPrefs::OnAppIcon(const mojo::String& package_name, |
| @@ -854,12 +851,15 @@ void ArcAppListPrefs::OnPackageAdded( |
| arc::mojom::ArcPackageInfoPtr package_info) { |
| DCHECK(IsArcEnabled()); |
| AddOrUpdatePackagePrefs(prefs_, *package_info); |
| + FOR_EACH_OBSERVER(Observer, observer_list_, |
| + OnPackageInstalled(*package_info)); |
| } |
| void ArcAppListPrefs::OnPackageModified( |
| arc::mojom::ArcPackageInfoPtr package_info) { |
| DCHECK(IsArcEnabled()); |
| AddOrUpdatePackagePrefs(prefs_, *package_info); |
| + FOR_EACH_OBSERVER(Observer, observer_list_, OnPackageModified(*package_info)); |
| } |
| void ArcAppListPrefs::OnPackageListRefreshed( |