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()) { |
Joao da Silva
2012/08/08 09:35:46
This should be if (MessageLoop::current()) { ... }
pneubeck (no reviews)
2012/08/08 09:47:29
Done.
| |
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 // Don't bother updating the cache if this is a unit test. | |
557 if (!MessageLoop::current()) { | |
Joao da Silva
2012/08/08 09:35:46
This test is not necessary, since it was already c
pneubeck (no reviews)
2012/08/08 09:47:29
Done.
| |
558 // Create the AppPackUpdater to start updating the cache. It requires the | |
559 // system request context, which isn't available in Init(); therefore it is | |
560 // created only once the loops are running. | |
561 GetAppPackUpdater(); | |
562 } | |
563 | |
565 if (device_cloud_policy_subsystem_.get()) { | 564 if (device_cloud_policy_subsystem_.get()) { |
566 // Read serial number and machine model. This must be done before we call | 565 // Read serial number and machine model. This must be done before we call |
567 // CompleteInitialization() below such that the serial number is available | 566 // CompleteInitialization() below such that the serial number is available |
568 // for re-submission in case we're doing serial number recovery. | 567 // for re-submission in case we're doing serial number recovery. |
569 if (device_data_store_->machine_id().empty() || | 568 if (device_data_store_->machine_id().empty() || |
570 device_data_store_->machine_model().empty()) { | 569 device_data_store_->machine_model().empty()) { |
571 chromeos::system::StatisticsProvider* provider = | 570 chromeos::system::StatisticsProvider* provider = |
572 chromeos::system::StatisticsProvider::GetInstance(); | 571 chromeos::system::StatisticsProvider::GetInstance(); |
573 | 572 |
574 std::string machine_model; | 573 std::string machine_model; |
(...skipping 12 matching lines...) Expand all Loading... | |
587 | 586 |
588 device_cloud_policy_subsystem_->CompleteInitialization( | 587 device_cloud_policy_subsystem_->CompleteInitialization( |
589 prefs::kDevicePolicyRefreshRate, | 588 prefs::kDevicePolicyRefreshRate, |
590 kServiceInitializationStartupDelay); | 589 kServiceInitializationStartupDelay); |
591 } | 590 } |
592 device_data_store_->set_device_status_collector( | 591 device_data_store_->set_device_status_collector( |
593 new DeviceStatusCollector( | 592 new DeviceStatusCollector( |
594 g_browser_process->local_state(), | 593 g_browser_process->local_state(), |
595 chromeos::system::StatisticsProvider::GetInstance(), | 594 chromeos::system::StatisticsProvider::GetInstance(), |
596 NULL)); | 595 NULL)); |
596 | |
597 SetTimezoneIfPolicyAvailable(); | |
597 #endif | 598 #endif |
598 } | 599 } |
599 | 600 |
601 void BrowserPolicyConnector::SetTimezoneIfPolicyAvailable() { | |
602 #if defined(OS_CHROMEOS) | |
603 typedef chromeos::CrosSettingsProvider Provider; | |
604 Provider::TrustedStatus result = | |
605 chromeos::CrosSettings::Get()->PrepareTrustedValues( | |
606 base::Bind(&BrowserPolicyConnector::SetTimezoneIfPolicyAvailable, | |
607 weak_ptr_factory_.GetWeakPtr())); | |
608 | |
609 if (result != Provider::TRUSTED) | |
610 return; | |
611 | |
612 std::string timezone; | |
613 if (chromeos::CrosSettings::Get()->GetString( | |
614 chromeos::kSystemTimezonePolicy, &timezone)) { | |
615 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( | |
616 UTF8ToUTF16(timezone)); | |
617 } | |
618 #endif | |
619 } | |
620 | |
600 // static | 621 // static |
601 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { | 622 ConfigurationPolicyProvider* BrowserPolicyConnector::CreatePlatformProvider() { |
602 #if defined(OS_WIN) | 623 #if defined(OS_WIN) |
603 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 624 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
604 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); | 625 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); |
605 return new AsyncPolicyProvider(loader.Pass()); | 626 return new AsyncPolicyProvider(loader.Pass()); |
606 #elif defined(OS_MACOSX) | 627 #elif defined(OS_MACOSX) |
607 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 628 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
608 scoped_ptr<AsyncPolicyLoader> loader( | 629 scoped_ptr<AsyncPolicyLoader> loader( |
609 new PolicyLoaderMac(policy_list, new MacPreferences())); | 630 new PolicyLoaderMac(policy_list, new MacPreferences())); |
610 return new AsyncPolicyProvider(loader.Pass()); | 631 return new AsyncPolicyProvider(loader.Pass()); |
611 #elif defined(OS_POSIX) | 632 #elif defined(OS_POSIX) |
612 FilePath config_dir_path; | 633 FilePath config_dir_path; |
613 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | 634 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
614 scoped_ptr<AsyncPolicyLoader> loader( | 635 scoped_ptr<AsyncPolicyLoader> loader( |
615 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); | 636 new ConfigDirPolicyLoader(config_dir_path, POLICY_SCOPE_MACHINE)); |
616 return new AsyncPolicyProvider(loader.Pass()); | 637 return new AsyncPolicyProvider(loader.Pass()); |
617 } else { | 638 } else { |
618 return NULL; | 639 return NULL; |
619 } | 640 } |
620 #else | 641 #else |
621 return NULL; | 642 return NULL; |
622 #endif | 643 #endif |
623 } | 644 } |
624 | 645 |
625 } // namespace policy | 646 } // namespace policy |
OLD | NEW |