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

Side by Side Diff: chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.cc

Issue 2584813002: arc: Launch Kiosk app immediately after installation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Populate app_id always when preconditions change. 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.h> 5 #include <chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.h>
6 6
7 #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service_factory.h" 7 #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service_factory.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 10 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 22
23 // static 23 // static
24 ArcKioskAppService* ArcKioskAppService::Get(content::BrowserContext* context) { 24 ArcKioskAppService* ArcKioskAppService::Get(content::BrowserContext* context) {
25 return ArcKioskAppServiceFactory::GetForBrowserContext(context); 25 return ArcKioskAppServiceFactory::GetForBrowserContext(context);
26 } 26 }
27 27
28 void ArcKioskAppService::OnAppRegistered( 28 void ArcKioskAppService::OnAppRegistered(
29 const std::string& app_id, 29 const std::string& app_id,
30 const ArcAppListPrefs::AppInfo& app_info) { 30 const ArcAppListPrefs::AppInfo& app_info) {
31 if (app_id == app_id_) 31 PreconditionsChanged();
32 PreconditionsChanged();
33 } 32 }
34 33
35 void ArcKioskAppService::OnAppReadyChanged(const std::string& id, bool ready) { 34 void ArcKioskAppService::OnAppReadyChanged(const std::string& id, bool ready) {
36 if (id == app_id_) 35 PreconditionsChanged();
37 PreconditionsChanged();
38 } 36 }
39 37
40 void ArcKioskAppService::OnPackageListInitialRefreshed() { 38 void ArcKioskAppService::OnPackageListInitialRefreshed() {
41 // The app could already be registered. 39 // The app could already be registered.
42 app_id_ = GetAppId();
43 PreconditionsChanged(); 40 PreconditionsChanged();
44 } 41 }
45 42
46 void ArcKioskAppService::OnArcKioskAppsChanged() { 43 void ArcKioskAppService::OnArcKioskAppsChanged() {
47 app_id_ = GetAppId();
48 PreconditionsChanged(); 44 PreconditionsChanged();
49 } 45 }
50 46
51 void ArcKioskAppService::OnTaskCreated(int32_t task_id, 47 void ArcKioskAppService::OnTaskCreated(int32_t task_id,
52 const std::string& package_name, 48 const std::string& package_name,
53 const std::string& activity, 49 const std::string& activity,
54 const std::string& intent) { 50 const std::string& intent) {
55 // Store task id of the app to stop it later when needed. 51 // Store task id of the app to stop it later when needed.
56 if (app_info_ && package_name == app_info_->package_name && 52 if (app_info_ && package_name == app_info_->package_name &&
57 activity == app_info_->activity) { 53 activity == app_info_->activity) {
58 task_id_ = task_id; 54 task_id_ = task_id;
59 } 55 }
60 } 56 }
61 57
62 void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) { 58 void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) {
63 if (task_id == task_id_) { 59 if (task_id == task_id_) {
64 app_launcher_.reset(); 60 app_launcher_.reset();
65 task_id_ = -1; 61 task_id_ = -1;
66 } 62 }
67 } 63 }
68 64
69 ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs) 65 ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs)
70 : profile_(profile), prefs_(prefs) { 66 : profile_(profile), prefs_(prefs) {
71 if (prefs_) 67 if (prefs_)
72 prefs_->AddObserver(this); 68 prefs_->AddObserver(this);
73 app_manager_ = ArcKioskAppManager::Get(); 69 app_manager_ = ArcKioskAppManager::Get();
74 if (app_manager_) { 70 if (app_manager_) {
75 app_manager_->AddObserver(this); 71 app_manager_->AddObserver(this);
76 app_id_ = GetAppId();
77 } 72 }
78 pref_change_registrar_.reset(new PrefChangeRegistrar()); 73 pref_change_registrar_.reset(new PrefChangeRegistrar());
79 pref_change_registrar_->Init(profile_->GetPrefs()); 74 pref_change_registrar_->Init(profile_->GetPrefs());
80 // Try to start/stop kiosk app on policy compliance state change. 75 // Try to start/stop kiosk app on policy compliance state change.
81 pref_change_registrar_->Add( 76 pref_change_registrar_->Add(
82 prefs::kArcPolicyCompliant, 77 prefs::kArcPolicyCompliant,
83 base::Bind(&ArcKioskAppService::PreconditionsChanged, 78 base::Bind(&ArcKioskAppService::PreconditionsChanged,
84 base::Unretained(this))); 79 base::Unretained(this)));
85 PreconditionsChanged(); 80 PreconditionsChanged();
86 } 81 }
87 82
88 ArcKioskAppService::~ArcKioskAppService() { 83 ArcKioskAppService::~ArcKioskAppService() {
89 if (prefs_) 84 if (prefs_)
90 prefs_->RemoveObserver(this); 85 prefs_->RemoveObserver(this);
91 if (app_manager_) 86 if (app_manager_)
92 app_manager_->RemoveObserver(this); 87 app_manager_->RemoveObserver(this);
93 } 88 }
94 89
95 void ArcKioskAppService::PreconditionsChanged() { 90 void ArcKioskAppService::PreconditionsChanged() {
91 app_id_ = GetAppId();
Nikita (slow) 2016/12/19 16:48:18 nit: doesn't look you still need app_id_.
92 if (app_id_.empty())
93 return;
96 app_info_ = prefs_->GetApp(app_id_); 94 app_info_ = prefs_->GetApp(app_id_);
97 if (app_info_ && app_info_->ready && 95 if (app_info_ && app_info_->ready &&
98 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) { 96 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) {
99 if (!app_launcher_) 97 if (!app_launcher_)
100 app_launcher_.reset(new ArcKioskAppLauncher(profile_, prefs_, app_id_)); 98 app_launcher_.reset(new ArcKioskAppLauncher(profile_, prefs_, app_id_));
101 } else if (task_id_ != -1) { 99 } else if (task_id_ != -1) {
102 arc::CloseTask(task_id_); 100 arc::CloseTask(task_id_);
103 } 101 }
104 } 102 }
105 103
106 std::string ArcKioskAppService::GetAppId() { 104 std::string ArcKioskAppService::GetAppId() {
107 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); 105 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_);
108 const ArcKioskAppManager::ArcKioskApp* app = 106 const ArcKioskAppManager::ArcKioskApp* app =
109 app_manager_->GetAppByAccountId(account_id); 107 app_manager_->GetAppByAccountId(account_id);
110 if (!app) 108 if (!app)
111 return std::string(); 109 return std::string();
112 std::unordered_set<std::string> app_ids = 110 std::unordered_set<std::string> app_ids =
113 prefs_->GetAppsForPackage(app->app_info().package_name()); 111 prefs_->GetAppsForPackage(app->app_info().package_name());
114 if (app_ids.empty()) 112 if (app_ids.empty())
115 return std::string(); 113 return std::string();
116 // TODO(poromov@): Choose appropriate app id to launch. See 114 // TODO(poromov@): Choose appropriate app id to launch. See
117 // http://crbug.com/665904 115 // http://crbug.com/665904
118 return std::string(*app_ids.begin()); 116 return std::string(*app_ids.begin());
119 } 117 }
120 118
121 } // namespace chromeos 119 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698