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 <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/message_loop/message_loop_proxy.h" | 16 #include "base/message_loop/message_loop_proxy.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/prefs/pref_registry_simple.h" | 18 #include "base/prefs/pref_registry_simple.h" |
19 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/strings/sys_string_conversions.h" | 22 #include "base/strings/sys_string_conversions.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/sys_info.h" | |
25 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
26 #include "chrome/browser/policy/async_policy_provider.h" | 25 #include "chrome/browser/policy/async_policy_provider.h" |
27 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 26 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
28 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" | 27 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" |
29 #include "chrome/browser/policy/cloud/cloud_policy_service.h" | 28 #include "chrome/browser/policy/cloud/cloud_policy_service.h" |
30 #include "chrome/browser/policy/cloud/device_management_service.h" | 29 #include "chrome/browser/policy/cloud/device_management_service.h" |
31 #include "chrome/browser/policy/configuration_policy_provider.h" | 30 #include "chrome/browser/policy/configuration_policy_provider.h" |
32 #include "chrome/browser/policy/policy_domain_descriptor.h" | 31 #include "chrome/browser/policy/policy_domain_descriptor.h" |
33 #include "chrome/browser/policy/policy_service_impl.h" | 32 #include "chrome/browser/policy/policy_service_impl.h" |
34 #include "chrome/browser/policy/policy_statistics_collector.h" | 33 #include "chrome/browser/policy/policy_statistics_collector.h" |
(...skipping 27 matching lines...) Expand all Loading... |
62 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 61 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
63 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 62 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
64 #include "chrome/browser/chromeos/policy/device_local_account.h" | 63 #include "chrome/browser/chromeos/policy/device_local_account.h" |
65 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 64 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
66 #include "chrome/browser/chromeos/policy/device_status_collector.h" | 65 #include "chrome/browser/chromeos/policy/device_status_collector.h" |
67 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 66 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
68 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" | 67 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" |
69 #include "chrome/browser/chromeos/settings/cros_settings.h" | 68 #include "chrome/browser/chromeos/settings/cros_settings.h" |
70 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" | 69 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" |
71 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 70 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
72 #include "chrome/browser/chromeos/system/statistics_provider.h" | |
73 #include "chrome/browser/chromeos/system/timezone_settings.h" | 71 #include "chrome/browser/chromeos/system/timezone_settings.h" |
74 #include "chromeos/chromeos_paths.h" | 72 #include "chromeos/chromeos_paths.h" |
75 #include "chromeos/chromeos_switches.h" | 73 #include "chromeos/chromeos_switches.h" |
76 #include "chromeos/cryptohome/cryptohome_library.h" | 74 #include "chromeos/cryptohome/cryptohome_library.h" |
77 #include "chromeos/dbus/cryptohome_client.h" | 75 #include "chromeos/dbus/cryptohome_client.h" |
78 #include "chromeos/dbus/dbus_thread_manager.h" | 76 #include "chromeos/dbus/dbus_thread_manager.h" |
79 #include "chromeos/network/network_handler.h" | 77 #include "chromeos/network/network_handler.h" |
80 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | 78 #include "chromeos/network/onc/onc_certificate_importer_impl.h" |
| 79 #include "chromeos/system/statistics_provider.h" |
81 #endif | 80 #endif |
82 | 81 |
83 using content::BrowserThread; | 82 using content::BrowserThread; |
84 | 83 |
85 namespace policy { | 84 namespace policy { |
86 | 85 |
87 namespace { | 86 namespace { |
88 | 87 |
89 // The following constants define delays applied before the initial policy fetch | 88 // The following constants define delays applied before the initial policy fetch |
90 // on startup. (So that displaying Chrome's GUI does not get delayed.) | 89 // on startup. (So that displaying Chrome's GUI does not get delayed.) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 130 } |
132 | 131 |
133 std::string GetUserAgentParameter() { | 132 std::string GetUserAgentParameter() { |
134 chrome::VersionInfo version_info; | 133 chrome::VersionInfo version_info; |
135 return base::StringPrintf("%s %s(%s)", | 134 return base::StringPrintf("%s %s(%s)", |
136 version_info.Name().c_str(), | 135 version_info.Name().c_str(), |
137 version_info.Version().c_str(), | 136 version_info.Version().c_str(), |
138 version_info.LastChange().c_str()); | 137 version_info.LastChange().c_str()); |
139 } | 138 } |
140 | 139 |
141 std::string GetPlatformParameter() { | |
142 std::string os_name = base::SysInfo::OperatingSystemName(); | |
143 std::string os_hardware = base::SysInfo::OperatingSystemArchitecture(); | |
144 | |
145 #if defined(OS_CHROMEOS) | |
146 chromeos::system::StatisticsProvider* provider = | |
147 chromeos::system::StatisticsProvider::GetInstance(); | |
148 | |
149 std::string hwclass; | |
150 if (!provider->GetMachineStatistic(chromeos::system::kHardwareClass, | |
151 &hwclass)) { | |
152 LOG(ERROR) << "Failed to get machine information"; | |
153 } | |
154 os_name += ",CrOS," + base::SysInfo::GetLsbReleaseBoard(); | |
155 os_hardware += "," + hwclass; | |
156 #endif | |
157 | |
158 std::string os_version("-"); | |
159 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | |
160 int32 os_major_version = 0; | |
161 int32 os_minor_version = 0; | |
162 int32 os_bugfix_version = 0; | |
163 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | |
164 &os_minor_version, | |
165 &os_bugfix_version); | |
166 os_version = base::StringPrintf("%d.%d.%d", | |
167 os_major_version, | |
168 os_minor_version, | |
169 os_bugfix_version); | |
170 #endif | |
171 | |
172 return base::StringPrintf( | |
173 "%s|%s|%s", os_name.c_str(), os_hardware.c_str(), os_version.c_str()); | |
174 } | |
175 | |
176 } // namespace | 140 } // namespace |
177 | 141 |
178 BrowserPolicyConnector::BrowserPolicyConnector() | 142 BrowserPolicyConnector::BrowserPolicyConnector() |
179 : is_initialized_(false), | 143 : is_initialized_(false), |
180 local_state_(NULL), | 144 local_state_(NULL), |
181 weak_ptr_factory_(this) { | 145 weak_ptr_factory_(this) { |
182 // GetPolicyService() must be ready after the constructor is done. | 146 // GetPolicyService() must be ready after the constructor is done. |
183 // The connector is created very early during startup, when the browser | 147 // The connector is created very early during startup, when the browser |
184 // threads aren't running yet; initialize components that need local_state, | 148 // threads aren't running yet; initialize components that need local_state, |
185 // the system request context or other threads (e.g. FILE) at Init(). | 149 // the system request context or other threads (e.g. FILE) at Init(). |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 DCHECK(!is_initialized()) << "BrowserPolicyConnector::Init() called twice."; | 197 DCHECK(!is_initialized()) << "BrowserPolicyConnector::Init() called twice."; |
234 | 198 |
235 local_state_ = local_state; | 199 local_state_ = local_state; |
236 request_context_ = request_context; | 200 request_context_ = request_context; |
237 | 201 |
238 std::string server_url = GetDeviceManagementUrl(); | 202 std::string server_url = GetDeviceManagementUrl(); |
239 device_management_service_.reset( | 203 device_management_service_.reset( |
240 new DeviceManagementService(request_context, | 204 new DeviceManagementService(request_context, |
241 server_url, | 205 server_url, |
242 content::GetUserAgent(GURL(server_url)), | 206 content::GetUserAgent(GURL(server_url)), |
243 GetUserAgentParameter(), | 207 GetUserAgentParameter())); |
244 GetPlatformParameter())); | |
245 device_management_service_->ScheduleInitialization( | 208 device_management_service_->ScheduleInitialization( |
246 kServiceInitializationStartupDelay); | 209 kServiceInitializationStartupDelay); |
247 | 210 |
248 if (g_testing_provider) | 211 if (g_testing_provider) |
249 g_testing_provider->Init(); | 212 g_testing_provider->Init(); |
250 if (platform_provider_) | 213 if (platform_provider_) |
251 platform_provider_->Init(); | 214 platform_provider_->Init(); |
252 | 215 |
253 #if defined(OS_CHROMEOS) | 216 #if defined(OS_CHROMEOS) |
254 global_user_cloud_policy_provider_.Init(); | 217 global_user_cloud_policy_provider_.Init(); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 return new AsyncPolicyProvider(loader.Pass()); | 512 return new AsyncPolicyProvider(loader.Pass()); |
550 } else { | 513 } else { |
551 return NULL; | 514 return NULL; |
552 } | 515 } |
553 #else | 516 #else |
554 return NULL; | 517 return NULL; |
555 #endif | 518 #endif |
556 } | 519 } |
557 | 520 |
558 } // namespace policy | 521 } // namespace policy |
OLD | NEW |