OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/policy/browser_policy_connector.h" | 5 #include "chrome/browser/policy/browser_policy_connector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
40 #include "chrome/browser/policy/policy_loader_win.h" | 40 #include "chrome/browser/policy/policy_loader_win.h" |
41 #elif defined(OS_MACOSX) | 41 #elif defined(OS_MACOSX) |
42 #include "chrome/browser/policy/policy_loader_mac.h" | 42 #include "chrome/browser/policy/policy_loader_mac.h" |
43 #include "chrome/browser/preferences_mac.h" | 43 #include "chrome/browser/preferences_mac.h" |
44 #elif defined(OS_POSIX) | 44 #elif defined(OS_POSIX) |
45 #include "chrome/browser/policy/config_dir_policy_loader.h" | 45 #include "chrome/browser/policy/config_dir_policy_loader.h" |
46 #endif | 46 #endif |
47 | 47 |
48 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 49 #include "base/utf_string_conversions.h" |
49 #include "chrome/browser/chromeos/cros/cros_library.h" | 50 #include "chrome/browser/chromeos/cros/cros_library.h" |
50 #include "chrome/browser/chromeos/login/authenticator.h" | |
51 #include "chrome/browser/chromeos/login/user_manager.h" | 51 #include "chrome/browser/chromeos/login/user_manager.h" |
| 52 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 53 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" |
52 #include "chrome/browser/chromeos/system/statistics_provider.h" | 54 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 55 #include "chrome/browser/chromeos/system/timezone_settings.h" |
53 #include "chrome/browser/policy/app_pack_updater.h" | 56 #include "chrome/browser/policy/app_pack_updater.h" |
54 #include "chrome/browser/policy/cros_user_policy_cache.h" | 57 #include "chrome/browser/policy/cros_user_policy_cache.h" |
55 #include "chrome/browser/policy/device_policy_cache.h" | 58 #include "chrome/browser/policy/device_policy_cache.h" |
56 #include "chromeos/dbus/dbus_thread_manager.h" | 59 #include "chromeos/dbus/dbus_thread_manager.h" |
57 #endif | 60 #endif |
58 | 61 |
59 using content::BrowserThread; | 62 using content::BrowserThread; |
60 | 63 |
61 namespace policy { | 64 namespace policy { |
62 | 65 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 managed_cloud_provider_.reset(new CloudPolicyProvider( | 153 managed_cloud_provider_.reset(new CloudPolicyProvider( |
151 this, | 154 this, |
152 POLICY_LEVEL_MANDATORY)); | 155 POLICY_LEVEL_MANDATORY)); |
153 recommended_cloud_provider_.reset(new CloudPolicyProvider( | 156 recommended_cloud_provider_.reset(new CloudPolicyProvider( |
154 this, | 157 this, |
155 POLICY_LEVEL_RECOMMENDED)); | 158 POLICY_LEVEL_RECOMMENDED)); |
156 } | 159 } |
157 | 160 |
158 InitializeDevicePolicy(); | 161 InitializeDevicePolicy(); |
159 | 162 |
160 // Create the AppPackUpdater to start updating the cache. It requires the | 163 // Complete the initialization once the message loops are spinning. |
161 // system request context, which isn't available yet; therefore it is | |
162 // created only once the loops are running. | |
163 MessageLoop::current()->PostTask( | 164 MessageLoop::current()->PostTask( |
164 FROM_HERE, | 165 FROM_HERE, |
165 base::Bind(base::IgnoreResult(&BrowserPolicyConnector::GetAppPackUpdater), | 166 base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
166 weak_ptr_factory_.GetWeakPtr())); | 167 weak_ptr_factory_.GetWeakPtr())); |
167 #endif | 168 #endif |
168 } | 169 } |
169 | 170 |
170 scoped_ptr<UserCloudPolicyManager> | 171 scoped_ptr<UserCloudPolicyManager> |
171 BrowserPolicyConnector::CreateCloudPolicyManager(Profile* profile) { | 172 BrowserPolicyConnector::CreateCloudPolicyManager(Profile* profile) { |
172 scoped_ptr<UserCloudPolicyManager> manager; | 173 scoped_ptr<UserCloudPolicyManager> manager; |
173 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 174 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
174 if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { | 175 if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
175 bool wait_for_policy_fetch = false; | 176 bool wait_for_policy_fetch = false; |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 new DevicePolicyCache(device_data_store_.get(), | 543 new DevicePolicyCache(device_data_store_.get(), |
543 install_attributes_.get()); | 544 install_attributes_.get()); |
544 | 545 |
545 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 546 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
546 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 547 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
547 | 548 |
548 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 549 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
549 device_data_store_.get(), | 550 device_data_store_.get(), |
550 device_policy_cache, | 551 device_policy_cache, |
551 GetDeviceManagementUrl())); | 552 GetDeviceManagementUrl())); |
552 | |
553 // Initialize the subsystem once the message loops are spinning. | |
554 MessageLoop::current()->PostTask( | |
555 FROM_HERE, | |
556 base::Bind(&BrowserPolicyConnector::CompleteInitialization, | |
557 weak_ptr_factory_.GetWeakPtr())); | |
558 } | 553 } |
559 } | 554 } |
560 #endif | 555 #endif |
561 } | 556 } |
562 | 557 |
563 void BrowserPolicyConnector::CompleteInitialization() { | 558 void BrowserPolicyConnector::CompleteInitialization() { |
564 #if defined(OS_CHROMEOS) | 559 #if defined(OS_CHROMEOS) |
| 560 |
| 561 // Create the AppPackUpdater to start updating the cache. It requires the |
| 562 // system request context, which isn't available in Init(); therefore it is |
| 563 // created only once the loops are running. |
| 564 GetAppPackUpdater(); |
| 565 |
565 if (device_cloud_policy_subsystem_.get()) { | 566 if (device_cloud_policy_subsystem_.get()) { |
566 // Read serial number and machine model. This must be done before we call | 567 // Read serial number and machine model. This must be done before we call |
567 // CompleteInitialization() below such that the serial number is available | 568 // CompleteInitialization() below such that the serial number is available |
568 // for re-submission in case we're doing serial number recovery. | 569 // for re-submission in case we're doing serial number recovery. |
569 if (device_data_store_->machine_id().empty() || | 570 if (device_data_store_->machine_id().empty() || |
570 device_data_store_->machine_model().empty()) { | 571 device_data_store_->machine_model().empty()) { |
571 chromeos::system::StatisticsProvider* provider = | 572 chromeos::system::StatisticsProvider* provider = |
572 chromeos::system::StatisticsProvider::GetInstance(); | 573 chromeos::system::StatisticsProvider::GetInstance(); |
573 | 574 |
574 std::string machine_model; | 575 std::string machine_model; |
575 if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, | 576 if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, |
576 &machine_model)) { | 577 &machine_model)) { |
577 LOG(ERROR) << "Failed to get machine model."; | 578 LOG(ERROR) << "Failed to get machine model."; |
578 } | 579 } |
579 | 580 |
580 std::string machine_id = GetSerialNumber(); | 581 std::string machine_id = GetSerialNumber(); |
581 if (machine_id.empty()) | 582 if (machine_id.empty()) |
582 LOG(ERROR) << "Failed to get machine serial number."; | 583 LOG(ERROR) << "Failed to get machine serial number."; |
583 | 584 |
584 device_data_store_->set_machine_id(machine_id); | 585 device_data_store_->set_machine_id(machine_id); |
585 device_data_store_->set_machine_model(machine_model); | 586 device_data_store_->set_machine_model(machine_model); |
586 } | 587 } |
587 | 588 |
588 device_cloud_policy_subsystem_->CompleteInitialization( | 589 device_cloud_policy_subsystem_->CompleteInitialization( |
589 prefs::kDevicePolicyRefreshRate, | 590 prefs::kDevicePolicyRefreshRate, |
590 kServiceInitializationStartupDelay); | 591 kServiceInitializationStartupDelay); |
591 } | 592 } |
592 device_data_store_->set_device_status_collector( | 593 |
593 new DeviceStatusCollector( | 594 if (device_data_store_.get()) { |
594 g_browser_process->local_state(), | 595 device_data_store_->set_device_status_collector( |
595 chromeos::system::StatisticsProvider::GetInstance(), | 596 new DeviceStatusCollector( |
596 NULL)); | 597 g_browser_process->local_state(), |
| 598 chromeos::system::StatisticsProvider::GetInstance(), |
| 599 NULL)); |
| 600 } |
| 601 |
| 602 SetTimezoneIfPolicyAvailable(); |
597 #endif | 603 #endif |
598 } | 604 } |
599 | 605 |
| 606 void BrowserPolicyConnector::SetTimezoneIfPolicyAvailable() { |
| 607 #if defined(OS_CHROMEOS) |
| 608 typedef chromeos::CrosSettingsProvider Provider; |
| 609 Provider::TrustedStatus result = |
| 610 chromeos::CrosSettings::Get()->PrepareTrustedValues( |
| 611 base::Bind(&BrowserPolicyConnector::SetTimezoneIfPolicyAvailable, |
| 612 weak_ptr_factory_.GetWeakPtr())); |
| 613 |
| 614 if (result != Provider::TRUSTED) |
| 615 return; |
| 616 |
| 617 std::string timezone; |
| 618 if (chromeos::CrosSettings::Get()->GetString( |
| 619 chromeos::kSystemTimezonePolicy, &timezone)) { |
| 620 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
| 621 UTF8ToUTF16(timezone)); |
| 622 } |
| 623 #endif |
| 624 } |
| 625 |
600 // static | 626 // static |
601 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { | 627 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { |
602 #if defined(OS_WIN) | 628 #if defined(OS_WIN) |
603 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 629 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
604 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); | 630 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); |
605 return new AsyncPolicyProvider(loader.Pass()); | 631 return new AsyncPolicyProvider(loader.Pass()); |
606 #elif defined(OS_MACOSX) | 632 #elif defined(OS_MACOSX) |
607 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 633 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
608 scoped_ptr<AsyncPolicyLoader> loader( | 634 scoped_ptr<AsyncPolicyLoader> loader( |
609 new PolicyLoaderMac(policy_list, new MacPreferences())); | 635 new PolicyLoaderMac(policy_list, new MacPreferences())); |
610 return new AsyncPolicyProvider(loader.Pass()); | 636 return new AsyncPolicyProvider(loader.Pass()); |
611 #elif defined(OS_POSIX) | 637 #elif defined(OS_POSIX) |
612 FilePath config_dir_path; | 638 FilePath config_dir_path; |
613 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | 639 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
614 scoped_ptr<AsyncPolicyLoader> loader( | 640 scoped_ptr<AsyncPolicyLoader> loader( |
615 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); | 641 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); |
616 return new AsyncPolicyProvider(loader.Pass()); | 642 return new AsyncPolicyProvider(loader.Pass()); |
617 } else { | 643 } else { |
618 return NULL; | 644 return NULL; |
619 } | 645 } |
620 #else | 646 #else |
621 return NULL; | 647 return NULL; |
622 #endif | 648 #endif |
623 } | 649 } |
624 | 650 |
625 } // namespace policy | 651 } // namespace policy |
OLD | NEW |