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