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" | |
50 #include "chrome/browser/chromeos/cros/cros_library.h" | 49 #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" | |
54 #include "chrome/browser/chromeos/system/statistics_provider.h" | 52 #include "chrome/browser/chromeos/system/statistics_provider.h" |
55 #include "chrome/browser/chromeos/system/timezone_settings.h" | |
56 #include "chrome/browser/policy/app_pack_updater.h" | 53 #include "chrome/browser/policy/app_pack_updater.h" |
57 #include "chrome/browser/policy/cros_user_policy_cache.h" | 54 #include "chrome/browser/policy/cros_user_policy_cache.h" |
58 #include "chrome/browser/policy/device_policy_cache.h" | 55 #include "chrome/browser/policy/device_policy_cache.h" |
59 #include "chromeos/dbus/dbus_thread_manager.h" | 56 #include "chromeos/dbus/dbus_thread_manager.h" |
60 #endif | 57 #endif |
61 | 58 |
62 using content::BrowserThread; | 59 using content::BrowserThread; |
63 | 60 |
64 namespace policy { | 61 namespace policy { |
65 | 62 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 managed_cloud_provider_.reset(new CloudPolicyProvider( | 142 managed_cloud_provider_.reset(new CloudPolicyProvider( |
146 this, | 143 this, |
147 POLICY_LEVEL_MANDATORY)); | 144 POLICY_LEVEL_MANDATORY)); |
148 recommended_cloud_provider_.reset(new CloudPolicyProvider( | 145 recommended_cloud_provider_.reset(new CloudPolicyProvider( |
149 this, | 146 this, |
150 POLICY_LEVEL_RECOMMENDED)); | 147 POLICY_LEVEL_RECOMMENDED)); |
151 } | 148 } |
152 | 149 |
153 InitializeDevicePolicy(); | 150 InitializeDevicePolicy(); |
154 | 151 |
155 // Skip the final initialization if this is a unit test. | 152 // Don't bother updating the cache if this is a unit test. |
156 if (MessageLoop::current()) { | 153 if (!MessageLoop::current()) |
157 // Complete the initialization once the message loops are spinning. | 154 return; |
158 MessageLoop::current()->PostTask( | 155 |
159 FROM_HERE, | 156 // Create the AppPackUpdater to start updating the cache. It requires the |
160 base::Bind(&BrowserPolicyConnector::CompleteInitialization, | 157 // system request context, which isn't available yet; therefore it is |
161 weak_ptr_factory_.GetWeakPtr())); | 158 // created only once the loops are running. |
162 } | 159 MessageLoop::current()->PostTask( |
| 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())); |
548 } | 558 } |
549 } | 559 } |
550 #endif | 560 #endif |
551 } | 561 } |
552 | 562 |
553 void BrowserPolicyConnector::CompleteInitialization() { | 563 void BrowserPolicyConnector::CompleteInitialization() { |
554 #if defined(OS_CHROMEOS) | 564 #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 | |
561 if (device_cloud_policy_subsystem_.get()) { | 565 if (device_cloud_policy_subsystem_.get()) { |
562 // Read serial number and machine model. This must be done before we call | 566 // Read serial number and machine model. This must be done before we call |
563 // CompleteInitialization() below such that the serial number is available | 567 // CompleteInitialization() below such that the serial number is available |
564 // for re-submission in case we're doing serial number recovery. | 568 // for re-submission in case we're doing serial number recovery. |
565 if (device_data_store_->machine_id().empty() || | 569 if (device_data_store_->machine_id().empty() || |
566 device_data_store_->machine_model().empty()) { | 570 device_data_store_->machine_model().empty()) { |
567 chromeos::system::StatisticsProvider* provider = | 571 chromeos::system::StatisticsProvider* provider = |
568 chromeos::system::StatisticsProvider::GetInstance(); | 572 chromeos::system::StatisticsProvider::GetInstance(); |
569 | 573 |
570 std::string machine_model; | 574 std::string machine_model; |
(...skipping 12 matching lines...) Expand all Loading... |
583 | 587 |
584 device_cloud_policy_subsystem_->CompleteInitialization( | 588 device_cloud_policy_subsystem_->CompleteInitialization( |
585 prefs::kDevicePolicyRefreshRate, | 589 prefs::kDevicePolicyRefreshRate, |
586 kServiceInitializationStartupDelay); | 590 kServiceInitializationStartupDelay); |
587 } | 591 } |
588 device_data_store_->set_device_status_collector( | 592 device_data_store_->set_device_status_collector( |
589 new DeviceStatusCollector( | 593 new DeviceStatusCollector( |
590 g_browser_process->local_state(), | 594 g_browser_process->local_state(), |
591 chromeos::system::StatisticsProvider::GetInstance(), | 595 chromeos::system::StatisticsProvider::GetInstance(), |
592 NULL)); | 596 NULL)); |
593 | |
594 SetTimezoneIfPolicyAvailable(); | |
595 #endif | 597 #endif |
596 } | 598 } |
597 | 599 |
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 | |
618 // static | 600 // static |
619 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { | 601 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { |
620 #if defined(OS_WIN) | 602 #if defined(OS_WIN) |
621 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 603 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
622 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); | 604 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); |
623 return new AsyncPolicyProvider(loader.Pass()); | 605 return new AsyncPolicyProvider(loader.Pass()); |
624 #elif defined(OS_MACOSX) | 606 #elif defined(OS_MACOSX) |
625 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 607 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
626 scoped_ptr<AsyncPolicyLoader> loader( | 608 scoped_ptr<AsyncPolicyLoader> loader( |
627 new PolicyLoaderMac(policy_list, new MacPreferences())); | 609 new PolicyLoaderMac(policy_list, new MacPreferences())); |
628 return new AsyncPolicyProvider(loader.Pass()); | 610 return new AsyncPolicyProvider(loader.Pass()); |
629 #elif defined(OS_POSIX) | 611 #elif defined(OS_POSIX) |
630 FilePath config_dir_path; | 612 FilePath config_dir_path; |
631 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | 613 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
632 scoped_ptr<AsyncPolicyLoader> loader( | 614 scoped_ptr<AsyncPolicyLoader> loader( |
633 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); | 615 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); |
634 return new AsyncPolicyProvider(loader.Pass()); | 616 return new AsyncPolicyProvider(loader.Pass()); |
635 } else { | 617 } else { |
636 return NULL; | 618 return NULL; |
637 } | 619 } |
638 #else | 620 #else |
639 return NULL; | 621 return NULL; |
640 #endif | 622 #endif |
641 } | 623 } |
642 | 624 |
643 } // namespace policy | 625 } // namespace policy |
OLD | NEW |