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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 managed_cloud_provider_.reset(new CloudPolicyProvider( | 145 managed_cloud_provider_.reset(new CloudPolicyProvider( |
143 this, | 146 this, |
144 POLICY_LEVEL_MANDATORY)); | 147 POLICY_LEVEL_MANDATORY)); |
145 recommended_cloud_provider_.reset(new CloudPolicyProvider( | 148 recommended_cloud_provider_.reset(new CloudPolicyProvider( |
146 this, | 149 this, |
147 POLICY_LEVEL_RECOMMENDED)); | 150 POLICY_LEVEL_RECOMMENDED)); |
148 } | 151 } |
149 | 152 |
150 InitializeDevicePolicy(); | 153 InitializeDevicePolicy(); |
151 | 154 |
152 // Don't bother updating the cache if this is a unit test. | 155 // Skip the final initialization if this is a unit test. |
153 if (!MessageLoop::current()) | 156 if (MessageLoop::current()) { |
154 return; | 157 // Complete the initialization once the message loops are spinning. |
155 | 158 MessageLoop::current()->PostTask( |
156 // Create the AppPackUpdater to start updating the cache. It requires the | 159 FROM_HERE, |
157 // system request context, which isn't available yet; therefore it is | 160 base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
158 // created only once the loops are running. | 161 weak_ptr_factory_.GetWeakPtr())); |
159 MessageLoop::current()->PostTask( | 162 } |
160 FROM_HERE, | |
161 base::Bind(base::IgnoreResult(&BrowserPolicyConnector::GetAppPackUpdater), | |
162 weak_ptr_factory_.GetWeakPtr())); | |
163 #endif | 163 #endif |
164 } | 164 } |
165 | 165 |
166 scoped_ptr<UserCloudPolicyManager> | 166 scoped_ptr<UserCloudPolicyManager> |
167 BrowserPolicyConnector::CreateCloudPolicyManager(Profile* profile) { | 167 BrowserPolicyConnector::CreateCloudPolicyManager(Profile* profile) { |
168 scoped_ptr<UserCloudPolicyManager> manager; | 168 scoped_ptr<UserCloudPolicyManager> manager; |
169 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 169 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
170 if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { | 170 if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
171 bool wait_for_policy_fetch = false; | 171 bool wait_for_policy_fetch = false; |
172 #if defined(OS_CHROMEOS) | 172 #if defined(OS_CHROMEOS) |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 new DevicePolicyCache(device_data_store_.get(), | 538 new DevicePolicyCache(device_data_store_.get(), |
539 install_attributes_.get()); | 539 install_attributes_.get()); |
540 | 540 |
541 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 541 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
542 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 542 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
543 | 543 |
544 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 544 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
545 device_data_store_.get(), | 545 device_data_store_.get(), |
546 device_policy_cache, | 546 device_policy_cache, |
547 GetDeviceManagementUrl())); | 547 GetDeviceManagementUrl())); |
548 | |
549 // Skip the final initialization if this is a unit test. | |
550 if (!MessageLoop::current()) | |
551 return; | |
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 } | 548 } |
559 } | 549 } |
560 #endif | 550 #endif |
561 } | 551 } |
562 | 552 |
563 void BrowserPolicyConnector::CompleteInitialization() { | 553 void BrowserPolicyConnector::CompleteInitialization() { |
564 #if defined(OS_CHROMEOS) | 554 #if defined(OS_CHROMEOS) |
| 555 |
| 556 // Create the AppPackUpdater to start updating the cache. It requires the |
| 557 // system request context, which isn't available in Init(); therefore it is |
| 558 // created only once the loops are running. |
| 559 GetAppPackUpdater(); |
| 560 |
565 if (device_cloud_policy_subsystem_.get()) { | 561 if (device_cloud_policy_subsystem_.get()) { |
566 // Read serial number and machine model. This must be done before we call | 562 // Read serial number and machine model. This must be done before we call |
567 // CompleteInitialization() below such that the serial number is available | 563 // CompleteInitialization() below such that the serial number is available |
568 // for re-submission in case we're doing serial number recovery. | 564 // for re-submission in case we're doing serial number recovery. |
569 if (device_data_store_->machine_id().empty() || | 565 if (device_data_store_->machine_id().empty() || |
570 device_data_store_->machine_model().empty()) { | 566 device_data_store_->machine_model().empty()) { |
571 chromeos::system::StatisticsProvider* provider = | 567 chromeos::system::StatisticsProvider* provider = |
572 chromeos::system::StatisticsProvider::GetInstance(); | 568 chromeos::system::StatisticsProvider::GetInstance(); |
573 | 569 |
574 std::string machine_model; | 570 std::string machine_model; |
(...skipping 12 matching lines...) Expand all Loading... |
587 | 583 |
588 device_cloud_policy_subsystem_->CompleteInitialization( | 584 device_cloud_policy_subsystem_->CompleteInitialization( |
589 prefs::kDevicePolicyRefreshRate, | 585 prefs::kDevicePolicyRefreshRate, |
590 kServiceInitializationStartupDelay); | 586 kServiceInitializationStartupDelay); |
591 } | 587 } |
592 device_data_store_->set_device_status_collector( | 588 device_data_store_->set_device_status_collector( |
593 new DeviceStatusCollector( | 589 new DeviceStatusCollector( |
594 g_browser_process->local_state(), | 590 g_browser_process->local_state(), |
595 chromeos::system::StatisticsProvider::GetInstance(), | 591 chromeos::system::StatisticsProvider::GetInstance(), |
596 NULL)); | 592 NULL)); |
| 593 |
| 594 SetTimezoneIfPolicyAvailable(); |
597 #endif | 595 #endif |
598 } | 596 } |
599 | 597 |
| 598 void BrowserPolicyConnector::SetTimezoneIfPolicyAvailable() { |
| 599 #if defined(OS_CHROMEOS) |
| 600 typedef chromeos::CrosSettingsProvider Provider; |
| 601 Provider::TrustedStatus result = |
| 602 chromeos::CrosSettings::Get()->PrepareTrustedValues( |
| 603 base::Bind(&BrowserPolicyConnector::SetTimezoneIfPolicyAvailable, |
| 604 weak_ptr_factory_.GetWeakPtr())); |
| 605 |
| 606 if (result != Provider::TRUSTED) |
| 607 return; |
| 608 |
| 609 std::string timezone; |
| 610 if (chromeos::CrosSettings::Get()->GetString( |
| 611 chromeos::kSystemTimezonePolicy, &timezone)) { |
| 612 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
| 613 UTF8ToUTF16(timezone)); |
| 614 } |
| 615 #endif |
| 616 } |
| 617 |
600 // static | 618 // static |
601 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { | 619 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { |
602 #if defined(OS_WIN) | 620 #if defined(OS_WIN) |
603 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 621 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
604 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); | 622 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); |
605 return new AsyncPolicyProvider(loader.Pass()); | 623 return new AsyncPolicyProvider(loader.Pass()); |
606 #elif defined(OS_MACOSX) | 624 #elif defined(OS_MACOSX) |
607 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 625 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
608 scoped_ptr<AsyncPolicyLoader> loader( | 626 scoped_ptr<AsyncPolicyLoader> loader( |
609 new PolicyLoaderMac(policy_list, new MacPreferences())); | 627 new PolicyLoaderMac(policy_list, new MacPreferences())); |
610 return new AsyncPolicyProvider(loader.Pass()); | 628 return new AsyncPolicyProvider(loader.Pass()); |
611 #elif defined(OS_POSIX) | 629 #elif defined(OS_POSIX) |
612 FilePath config_dir_path; | 630 FilePath config_dir_path; |
613 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | 631 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
614 scoped_ptr<AsyncPolicyLoader> loader( | 632 scoped_ptr<AsyncPolicyLoader> loader( |
615 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); | 633 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); |
616 return new AsyncPolicyProvider(loader.Pass()); | 634 return new AsyncPolicyProvider(loader.Pass()); |
617 } else { | 635 } else { |
618 return NULL; | 636 return NULL; |
619 } | 637 } |
620 #else | 638 #else |
621 return NULL; | 639 return NULL; |
622 #endif | 640 #endif |
623 } | 641 } |
624 | 642 |
625 } // namespace policy | 643 } // namespace policy |
OLD | NEW |