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

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_manager.cc

Issue 1019283004: Switch to direct use of OwnerSettingsServiceChromeOS::Set() in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 8 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/kiosk_app_manager.h" 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/barrier_closure.h" 10 #include "base/barrier_closure.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/prefs/pref_registry_simple.h" 16 #include "base/prefs/pref_registry_simple.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/scoped_user_pref_update.h" 18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/sys_info.h" 20 #include "base/sys_info.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h"
23 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h"
24 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h"
25 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" 25 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h"
26 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
26 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 27 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
27 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
28 #include "chrome/browser/chromeos/policy/device_local_account.h" 29 #include "chrome/browser/chromeos/policy/device_local_account.h"
29 #include "chrome/browser/chromeos/settings/cros_settings.h" 30 #include "chrome/browser/chromeos/settings/cros_settings.h"
30 #include "chrome/browser/extensions/external_loader.h" 31 #include "chrome/browser/extensions/external_loader.h"
31 #include "chrome/browser/extensions/external_provider_impl.h" 32 #include "chrome/browser/extensions/external_provider_impl.h"
32 #include "chrome/browser/lifetime/application_lifetime.h" 33 #include "chrome/browser/lifetime/application_lifetime.h"
33 #include "chrome/common/chrome_paths.h" 34 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/extensions/extension_constants.h" 35 #include "chrome/common/extensions/extension_constants.h"
35 #include "chromeos/chromeos_paths.h" 36 #include "chromeos/chromeos_paths.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 177
177 KioskAppManager::App::App() : is_loading(false), 178 KioskAppManager::App::App() : is_loading(false),
178 was_auto_launched_with_zero_delay(false) {} 179 was_auto_launched_with_zero_delay(false) {}
179 180
180 KioskAppManager::App::~App() {} 181 KioskAppManager::App::~App() {}
181 182
182 std::string KioskAppManager::GetAutoLaunchApp() const { 183 std::string KioskAppManager::GetAutoLaunchApp() const {
183 return auto_launch_app_id_; 184 return auto_launch_app_id_;
184 } 185 }
185 186
186 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) { 187 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id,
188 OwnerSettingsServiceChromeOS* service) {
187 SetAutoLoginState(AUTOLOGIN_REQUESTED); 189 SetAutoLoginState(AUTOLOGIN_REQUESTED);
188 // Clean first, so the proper change callbacks are triggered even 190 // Clean first, so the proper change callbacks are triggered even
189 // if we are only changing AutoLoginState here. 191 // if we are only changing AutoLoginState here.
190 if (!auto_launch_app_id_.empty()) { 192 if (!auto_launch_app_id_.empty()) {
191 CrosSettings::Get()->SetString(kAccountsPrefDeviceLocalAccountAutoLoginId, 193 service->SetString(kAccountsPrefDeviceLocalAccountAutoLoginId,
192 std::string()); 194 std::string());
193 } 195 }
194 196
195 CrosSettings::Get()->SetString( 197 service->SetString(
196 kAccountsPrefDeviceLocalAccountAutoLoginId, 198 kAccountsPrefDeviceLocalAccountAutoLoginId,
197 app_id.empty() ? std::string() : GenerateKioskAppAccountId(app_id)); 199 app_id.empty() ? std::string() : GenerateKioskAppAccountId(app_id));
198 CrosSettings::Get()->SetInteger( 200 service->SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0);
199 kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0);
200 } 201 }
201 202
202 void KioskAppManager::SetAppWasAutoLaunchedWithZeroDelay( 203 void KioskAppManager::SetAppWasAutoLaunchedWithZeroDelay(
203 const std::string& app_id) { 204 const std::string& app_id) {
204 DCHECK_EQ(auto_launch_app_id_, app_id); 205 DCHECK_EQ(auto_launch_app_id_, app_id);
205 currently_auto_launched_with_zero_delay_app_ = app_id; 206 currently_auto_launched_with_zero_delay_app_ = app_id;
206 } 207 }
207 208
208 void KioskAppManager::EnableConsumerKioskAutoLaunch( 209 void KioskAppManager::EnableConsumerKioskAutoLaunch(
209 const KioskAppManager::EnableKioskAutoLaunchCallback& callback) { 210 const KioskAppManager::EnableKioskAutoLaunchCallback& callback) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // Apps that were installed by the policy don't require machine owner 326 // Apps that were installed by the policy don't require machine owner
326 // consent through UI. 327 // consent through UI.
327 policy::BrowserPolicyConnectorChromeOS* connector = 328 policy::BrowserPolicyConnectorChromeOS* connector =
328 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 329 g_browser_process->platform_part()->browser_policy_connector_chromeos();
329 if (connector->IsEnterpriseManaged()) 330 if (connector->IsEnterpriseManaged())
330 return true; 331 return true;
331 332
332 return GetAutoLoginState() == AUTOLOGIN_APPROVED; 333 return GetAutoLoginState() == AUTOLOGIN_APPROVED;
333 } 334 }
334 335
335 void KioskAppManager::AddApp(const std::string& app_id) { 336 void KioskAppManager::AddApp(const std::string& app_id,
337 OwnerSettingsServiceChromeOS* service) {
336 std::vector<policy::DeviceLocalAccount> device_local_accounts = 338 std::vector<policy::DeviceLocalAccount> device_local_accounts =
337 policy::GetDeviceLocalAccounts(CrosSettings::Get()); 339 policy::GetDeviceLocalAccounts(CrosSettings::Get());
338 340
339 // Don't insert the app if it's already in the list. 341 // Don't insert the app if it's already in the list.
340 for (std::vector<policy::DeviceLocalAccount>::const_iterator 342 for (std::vector<policy::DeviceLocalAccount>::const_iterator
341 it = device_local_accounts.begin(); 343 it = device_local_accounts.begin();
342 it != device_local_accounts.end(); ++it) { 344 it != device_local_accounts.end(); ++it) {
343 if (it->type == policy::DeviceLocalAccount::TYPE_KIOSK_APP && 345 if (it->type == policy::DeviceLocalAccount::TYPE_KIOSK_APP &&
344 it->kiosk_app_id == app_id) { 346 it->kiosk_app_id == app_id) {
345 return; 347 return;
346 } 348 }
347 } 349 }
348 350
349 // Add the new account. 351 // Add the new account.
350 device_local_accounts.push_back(policy::DeviceLocalAccount( 352 device_local_accounts.push_back(policy::DeviceLocalAccount(
351 policy::DeviceLocalAccount::TYPE_KIOSK_APP, 353 policy::DeviceLocalAccount::TYPE_KIOSK_APP,
352 GenerateKioskAppAccountId(app_id), 354 GenerateKioskAppAccountId(app_id),
353 app_id, 355 app_id,
354 std::string())); 356 std::string()));
355 357
356 policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts); 358 policy::SetDeviceLocalAccounts(service, device_local_accounts);
357 } 359 }
358 360
359 void KioskAppManager::RemoveApp(const std::string& app_id) { 361 void KioskAppManager::RemoveApp(const std::string& app_id,
362 OwnerSettingsServiceChromeOS* service) {
360 // Resets auto launch app if it is the removed app. 363 // Resets auto launch app if it is the removed app.
361 if (auto_launch_app_id_ == app_id) 364 if (auto_launch_app_id_ == app_id)
362 SetAutoLaunchApp(std::string()); 365 SetAutoLaunchApp(std::string(), service);
363 366
364 std::vector<policy::DeviceLocalAccount> device_local_accounts = 367 std::vector<policy::DeviceLocalAccount> device_local_accounts =
365 policy::GetDeviceLocalAccounts(CrosSettings::Get()); 368 policy::GetDeviceLocalAccounts(CrosSettings::Get());
366 if (device_local_accounts.empty()) 369 if (device_local_accounts.empty())
367 return; 370 return;
368 371
369 // Remove entries that match |app_id|. 372 // Remove entries that match |app_id|.
370 for (std::vector<policy::DeviceLocalAccount>::iterator 373 for (std::vector<policy::DeviceLocalAccount>::iterator
371 it = device_local_accounts.begin(); 374 it = device_local_accounts.begin();
372 it != device_local_accounts.end(); ++it) { 375 it != device_local_accounts.end(); ++it) {
373 if (it->type == policy::DeviceLocalAccount::TYPE_KIOSK_APP && 376 if (it->type == policy::DeviceLocalAccount::TYPE_KIOSK_APP &&
374 it->kiosk_app_id == app_id) { 377 it->kiosk_app_id == app_id) {
375 device_local_accounts.erase(it); 378 device_local_accounts.erase(it);
376 break; 379 break;
377 } 380 }
378 } 381 }
379 382
380 policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts); 383 policy::SetDeviceLocalAccounts(service, device_local_accounts);
381 } 384 }
382 385
383 void KioskAppManager::GetApps(Apps* apps) const { 386 void KioskAppManager::GetApps(Apps* apps) const {
384 apps->clear(); 387 apps->clear();
385 apps->reserve(apps_.size()); 388 apps->reserve(apps_.size());
386 for (size_t i = 0; i < apps_.size(); ++i) { 389 for (size_t i = 0; i < apps_.size(); ++i) {
387 const KioskAppData& app_data = *apps_[i]; 390 const KioskAppData& app_data = *apps_[i];
388 if (app_data.status() != KioskAppData::STATUS_ERROR) { 391 if (app_data.status() != KioskAppData::STATUS_ERROR) {
389 apps->push_back(App( 392 apps->push_back(App(
390 app_data, external_cache_->IsExtensionPending(app_data.app_id()), 393 app_data, external_cache_->IsExtensionPending(app_data.app_id()),
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); 734 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir);
732 } 735 }
733 736
734 void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) { 737 void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) {
735 base::FilePath temp_dir; 738 base::FilePath temp_dir;
736 base::GetTempDir(&temp_dir); 739 base::GetTempDir(&temp_dir);
737 *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir); 740 *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir);
738 } 741 }
739 742
740 } // namespace chromeos 743 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698