| 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 26 matching lines...) Expand all Loading... |
| 37 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
| 38 #include "chrome/browser/policy/policy_loader_win.h" | 38 #include "chrome/browser/policy/policy_loader_win.h" |
| 39 #elif defined(OS_MACOSX) | 39 #elif defined(OS_MACOSX) |
| 40 #include "chrome/browser/policy/policy_loader_mac.h" | 40 #include "chrome/browser/policy/policy_loader_mac.h" |
| 41 #include "chrome/browser/preferences_mac.h" | 41 #include "chrome/browser/preferences_mac.h" |
| 42 #elif defined(OS_POSIX) | 42 #elif defined(OS_POSIX) |
| 43 #include "chrome/browser/policy/config_dir_policy_loader.h" | 43 #include "chrome/browser/policy/config_dir_policy_loader.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 #if defined(OS_CHROMEOS) | 46 #if defined(OS_CHROMEOS) |
| 47 #include "base/utf_string_conversions.h" |
| 47 #include "chrome/browser/chromeos/cros/cros_library.h" | 48 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 49 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 50 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" |
| 48 #include "chrome/browser/chromeos/system/statistics_provider.h" | 51 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 52 #include "chrome/browser/chromeos/system/timezone_settings.h" |
| 49 #include "chrome/browser/policy/app_pack_updater.h" | 53 #include "chrome/browser/policy/app_pack_updater.h" |
| 50 #include "chrome/browser/policy/cros_user_policy_cache.h" | 54 #include "chrome/browser/policy/cros_user_policy_cache.h" |
| 51 #include "chrome/browser/policy/device_policy_cache.h" | 55 #include "chrome/browser/policy/device_policy_cache.h" |
| 52 #include "chromeos/dbus/dbus_thread_manager.h" | 56 #include "chromeos/dbus/dbus_thread_manager.h" |
| 53 #endif | 57 #endif |
| 54 | 58 |
| 55 using content::BrowserThread; | 59 using content::BrowserThread; |
| 56 | 60 |
| 57 namespace policy { | 61 namespace policy { |
| 58 | 62 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 this, | 145 this, |
| 142 POLICY_LEVEL_MANDATORY)); | 146 POLICY_LEVEL_MANDATORY)); |
| 143 recommended_cloud_provider_.reset(new CloudPolicyProvider( | 147 recommended_cloud_provider_.reset(new CloudPolicyProvider( |
| 144 this, | 148 this, |
| 145 POLICY_LEVEL_RECOMMENDED)); | 149 POLICY_LEVEL_RECOMMENDED)); |
| 146 } | 150 } |
| 147 } | 151 } |
| 148 | 152 |
| 149 InitializeDevicePolicy(); | 153 InitializeDevicePolicy(); |
| 150 | 154 |
| 151 // Create the AppPackUpdater to start updating the cache. It requires the | 155 // Complete the initialization once the message loops are spinning. |
| 152 // system request context, which isn't available yet; therefore it is | |
| 153 // created only once the loops are running. | |
| 154 MessageLoop::current()->PostTask( | 156 MessageLoop::current()->PostTask( |
| 155 FROM_HERE, | 157 FROM_HERE, |
| 156 base::Bind(base::IgnoreResult(&BrowserPolicyConnector::GetAppPackUpdater), | 158 base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
| 157 weak_ptr_factory_.GetWeakPtr())); | 159 weak_ptr_factory_.GetWeakPtr())); |
| 158 #endif | 160 #endif |
| 159 } | 161 } |
| 160 | 162 |
| 161 PolicyService* BrowserPolicyConnector::CreatePolicyService( | 163 PolicyService* BrowserPolicyConnector::CreatePolicyService( |
| 162 Profile* profile) { | 164 Profile* profile) { |
| 163 // |providers| in decreasing order of priority. | 165 // |providers| in decreasing order of priority. |
| 164 PolicyServiceImpl::Providers providers; | 166 PolicyServiceImpl::Providers providers; |
| 165 if (g_testing_provider) | 167 if (g_testing_provider) |
| 166 providers.push_back(g_testing_provider); | 168 providers.push_back(g_testing_provider); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 DevicePolicyCache* device_policy_cache = | 517 DevicePolicyCache* device_policy_cache = |
| 516 new DevicePolicyCache(device_data_store_.get(), | 518 new DevicePolicyCache(device_data_store_.get(), |
| 517 install_attributes_.get()); | 519 install_attributes_.get()); |
| 518 | 520 |
| 519 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 521 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| 520 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 522 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| 521 | 523 |
| 522 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 524 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 523 device_data_store_.get(), | 525 device_data_store_.get(), |
| 524 device_policy_cache)); | 526 device_policy_cache)); |
| 525 | |
| 526 // Initialize the subsystem once the message loops are spinning. | |
| 527 MessageLoop::current()->PostTask( | |
| 528 FROM_HERE, | |
| 529 base::Bind(&BrowserPolicyConnector::CompleteInitialization, | |
| 530 weak_ptr_factory_.GetWeakPtr())); | |
| 531 } | 527 } |
| 532 } | 528 } |
| 533 #endif | 529 #endif |
| 534 } | 530 } |
| 535 | 531 |
| 536 void BrowserPolicyConnector::CompleteInitialization() { | 532 void BrowserPolicyConnector::CompleteInitialization() { |
| 537 #if defined(OS_CHROMEOS) | 533 #if defined(OS_CHROMEOS) |
| 534 // Create the AppPackUpdater to start updating the cache. It requires the |
| 535 // system request context, which isn't available in Init(); therefore it is |
| 536 // created only once the loops are running. |
| 537 GetAppPackUpdater(); |
| 538 |
| 538 if (device_cloud_policy_subsystem_.get()) { | 539 if (device_cloud_policy_subsystem_.get()) { |
| 539 // Read serial number and machine model. This must be done before we call | 540 // Read serial number and machine model. This must be done before we call |
| 540 // CompleteInitialization() below such that the serial number is available | 541 // CompleteInitialization() below such that the serial number is available |
| 541 // for re-submission in case we're doing serial number recovery. | 542 // for re-submission in case we're doing serial number recovery. |
| 542 if (device_data_store_->machine_id().empty() || | 543 if (device_data_store_->machine_id().empty() || |
| 543 device_data_store_->machine_model().empty()) { | 544 device_data_store_->machine_model().empty()) { |
| 544 chromeos::system::StatisticsProvider* provider = | 545 chromeos::system::StatisticsProvider* provider = |
| 545 chromeos::system::StatisticsProvider::GetInstance(); | 546 chromeos::system::StatisticsProvider::GetInstance(); |
| 546 | 547 |
| 547 std::string machine_model; | 548 std::string machine_model; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 560 | 561 |
| 561 device_cloud_policy_subsystem_->CompleteInitialization( | 562 device_cloud_policy_subsystem_->CompleteInitialization( |
| 562 prefs::kDevicePolicyRefreshRate, | 563 prefs::kDevicePolicyRefreshRate, |
| 563 kServiceInitializationStartupDelay); | 564 kServiceInitializationStartupDelay); |
| 564 } | 565 } |
| 565 device_data_store_->set_device_status_collector( | 566 device_data_store_->set_device_status_collector( |
| 566 new DeviceStatusCollector( | 567 new DeviceStatusCollector( |
| 567 g_browser_process->local_state(), | 568 g_browser_process->local_state(), |
| 568 chromeos::system::StatisticsProvider::GetInstance(), | 569 chromeos::system::StatisticsProvider::GetInstance(), |
| 569 NULL)); | 570 NULL)); |
| 571 |
| 572 SetTimezoneIfPolicyAvailable(); |
| 570 #endif | 573 #endif |
| 571 } | 574 } |
| 572 | 575 |
| 576 void BrowserPolicyConnector::SetTimezoneIfPolicyAvailable() { |
| 577 #if defined(OS_CHROMEOS) |
| 578 typedef chromeos::CrosSettingsProvider Provider; |
| 579 Provider::TrustedStatus result = |
| 580 chromeos::CrosSettings::Get()->PrepareTrustedValues( |
| 581 base::Bind(&BrowserPolicyConnector::SetTimezoneIfPolicyAvailable, |
| 582 weak_ptr_factory_.GetWeakPtr())); |
| 583 |
| 584 if (result != Provider::TRUSTED) |
| 585 return; |
| 586 |
| 587 std::string timezone; |
| 588 if (chromeos::CrosSettings::Get()->GetString( |
| 589 chromeos::kSystemTimezonePolicy, &timezone)) { |
| 590 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
| 591 UTF8ToUTF16(timezone)); |
| 592 } |
| 593 #endif |
| 594 } |
| 595 |
| 573 // static | 596 // static |
| 574 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { | 597 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { |
| 575 #if defined(OS_WIN) | 598 #if defined(OS_WIN) |
| 576 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 599 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
| 577 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); | 600 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); |
| 578 return new AsyncPolicyProvider(loader.Pass()); | 601 return new AsyncPolicyProvider(loader.Pass()); |
| 579 #elif defined(OS_MACOSX) | 602 #elif defined(OS_MACOSX) |
| 580 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 603 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
| 581 scoped_ptr<AsyncPolicyLoader> loader( | 604 scoped_ptr<AsyncPolicyLoader> loader( |
| 582 new PolicyLoaderMac(policy_list, new MacPreferences())); | 605 new PolicyLoaderMac(policy_list, new MacPreferences())); |
| 583 return new AsyncPolicyProvider(loader.Pass()); | 606 return new AsyncPolicyProvider(loader.Pass()); |
| 584 #elif defined(OS_POSIX) | 607 #elif defined(OS_POSIX) |
| 585 FilePath config_dir_path; | 608 FilePath config_dir_path; |
| 586 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | 609 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
| 587 scoped_ptr<AsyncPolicyLoader> loader( | 610 scoped_ptr<AsyncPolicyLoader> loader( |
| 588 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); | 611 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); |
| 589 return new AsyncPolicyProvider(loader.Pass()); | 612 return new AsyncPolicyProvider(loader.Pass()); |
| 590 } else { | 613 } else { |
| 591 return NULL; | 614 return NULL; |
| 592 } | 615 } |
| 593 #else | 616 #else |
| 594 return NULL; | 617 return NULL; |
| 595 #endif | 618 #endif |
| 596 } | 619 } |
| 597 | 620 |
| 598 } // namespace policy | 621 } // namespace policy |
| OLD | NEW |