| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chrome_browser_policy_connector.h" | 5 #include "chrome/browser/policy/chrome_browser_policy_connector.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/strings/stringprintf.h" | |
| 16 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 17 #include "base/sys_info.h" | |
| 18 #include "chrome/browser/policy/configuration_policy_handler_list_factory.h" | 16 #include "chrome/browser/policy/configuration_policy_handler_list_factory.h" |
| 17 #include "chrome/browser/policy/device_management_service_configuration.h" |
| 19 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/chrome_version_info.h" | |
| 21 #include "components/policy/core/common/async_policy_provider.h" | 19 #include "components/policy/core/common/async_policy_provider.h" |
| 22 #include "components/policy/core/common/cloud/device_management_service.h" | 20 #include "components/policy/core/common/cloud/device_management_service.h" |
| 23 #include "components/policy/core/common/configuration_policy_provider.h" | 21 #include "components/policy/core/common/configuration_policy_provider.h" |
| 24 #include "components/policy/core/common/policy_types.h" | 22 #include "components/policy/core/common/policy_types.h" |
| 25 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 26 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 27 #include "policy/policy_constants.h" | 25 #include "policy/policy_constants.h" |
| 28 | 26 |
| 29 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 30 #include "components/policy/core/common/policy_loader_win.h" | 28 #include "components/policy/core/common/policy_loader_win.h" |
| 31 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
| 32 #include <CoreFoundation/CoreFoundation.h> | 30 #include <CoreFoundation/CoreFoundation.h> |
| 33 #include "components/policy/core/common/policy_loader_mac.h" | 31 #include "components/policy/core/common/policy_loader_mac.h" |
| 34 #include "components/policy/core/common/preferences_mac.h" | 32 #include "components/policy/core/common/preferences_mac.h" |
| 35 #elif defined(OS_POSIX) && !defined(OS_ANDROID) | 33 #elif defined(OS_POSIX) && !defined(OS_ANDROID) |
| 36 #include "components/policy/core/common/config_dir_policy_loader.h" | 34 #include "components/policy/core/common/config_dir_policy_loader.h" |
| 37 #elif defined(OS_ANDROID) | 35 #elif defined(OS_ANDROID) |
| 38 #include "components/policy/core/common/policy_provider_android.h" | 36 #include "components/policy/core/common/policy_provider_android.h" |
| 39 #endif | 37 #endif |
| 40 | 38 |
| 41 #if defined(OS_CHROMEOS) | |
| 42 #include "chromeos/system/statistics_provider.h" | |
| 43 #endif | |
| 44 | |
| 45 using content::BrowserThread; | 39 using content::BrowserThread; |
| 46 | 40 |
| 47 namespace policy { | 41 namespace policy { |
| 48 | 42 |
| 49 namespace { | 43 namespace { |
| 50 | 44 |
| 51 // The following constants define delays applied before the initial policy fetch | |
| 52 // on startup. (So that displaying Chrome's GUI does not get delayed.) | |
| 53 // Delay in milliseconds from startup. | |
| 54 const int64 kServiceInitializationStartupDelay = 5000; | |
| 55 | |
| 56 #if defined(OS_MACOSX) | 45 #if defined(OS_MACOSX) |
| 57 base::FilePath GetManagedPolicyPath() { | 46 base::FilePath GetManagedPolicyPath() { |
| 58 // This constructs the path to the plist file in which Mac OS X stores the | 47 // This constructs the path to the plist file in which Mac OS X stores the |
| 59 // managed preference for the application. This is undocumented and therefore | 48 // managed preference for the application. This is undocumented and therefore |
| 60 // fragile, but if it doesn't work out, AsyncPolicyLoader has a task that | 49 // fragile, but if it doesn't work out, AsyncPolicyLoader has a task that |
| 61 // polls periodically in order to reload managed preferences later even if we | 50 // polls periodically in order to reload managed preferences later even if we |
| 62 // missed the change. | 51 // missed the change. |
| 63 base::FilePath path; | 52 base::FilePath path; |
| 64 if (!PathService::Get(chrome::DIR_MANAGED_PREFS, &path)) | 53 if (!PathService::Get(chrome::DIR_MANAGED_PREFS, &path)) |
| 65 return base::FilePath(); | 54 return base::FilePath(); |
| 66 | 55 |
| 67 CFBundleRef bundle(CFBundleGetMainBundle()); | 56 CFBundleRef bundle(CFBundleGetMainBundle()); |
| 68 if (!bundle) | 57 if (!bundle) |
| 69 return base::FilePath(); | 58 return base::FilePath(); |
| 70 | 59 |
| 71 CFStringRef bundle_id = CFBundleGetIdentifier(bundle); | 60 CFStringRef bundle_id = CFBundleGetIdentifier(bundle); |
| 72 if (!bundle_id) | 61 if (!bundle_id) |
| 73 return base::FilePath(); | 62 return base::FilePath(); |
| 74 | 63 |
| 75 return path.Append(base::SysCFStringRefToUTF8(bundle_id) + ".plist"); | 64 return path.Append(base::SysCFStringRefToUTF8(bundle_id) + ".plist"); |
| 76 } | 65 } |
| 77 #endif // defined(OS_MACOSX) | 66 #endif // defined(OS_MACOSX) |
| 78 | 67 |
| 79 class DeviceManagementServiceConfiguration | |
| 80 : public DeviceManagementService::Configuration { | |
| 81 public: | |
| 82 DeviceManagementServiceConfiguration() {} | |
| 83 virtual ~DeviceManagementServiceConfiguration() {} | |
| 84 | |
| 85 virtual std::string GetServerUrl() OVERRIDE { | |
| 86 return BrowserPolicyConnector::GetDeviceManagementUrl(); | |
| 87 } | |
| 88 | |
| 89 virtual std::string GetAgentParameter() OVERRIDE { | |
| 90 chrome::VersionInfo version_info; | |
| 91 return base::StringPrintf("%s %s(%s)", | |
| 92 version_info.Name().c_str(), | |
| 93 version_info.Version().c_str(), | |
| 94 version_info.LastChange().c_str()); | |
| 95 } | |
| 96 | |
| 97 virtual std::string GetPlatformParameter() OVERRIDE { | |
| 98 std::string os_name = base::SysInfo::OperatingSystemName(); | |
| 99 std::string os_hardware = base::SysInfo::OperatingSystemArchitecture(); | |
| 100 | |
| 101 #if defined(OS_CHROMEOS) | |
| 102 chromeos::system::StatisticsProvider* provider = | |
| 103 chromeos::system::StatisticsProvider::GetInstance(); | |
| 104 | |
| 105 std::string hwclass; | |
| 106 if (!provider->GetMachineStatistic(chromeos::system::kHardwareClassKey, | |
| 107 &hwclass)) { | |
| 108 LOG(ERROR) << "Failed to get machine information"; | |
| 109 } | |
| 110 os_name += ",CrOS," + base::SysInfo::GetLsbReleaseBoard(); | |
| 111 os_hardware += "," + hwclass; | |
| 112 #endif | |
| 113 | |
| 114 std::string os_version("-"); | |
| 115 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | |
| 116 int32 os_major_version = 0; | |
| 117 int32 os_minor_version = 0; | |
| 118 int32 os_bugfix_version = 0; | |
| 119 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | |
| 120 &os_minor_version, | |
| 121 &os_bugfix_version); | |
| 122 os_version = base::StringPrintf("%d.%d.%d", | |
| 123 os_major_version, | |
| 124 os_minor_version, | |
| 125 os_bugfix_version); | |
| 126 #endif | |
| 127 | |
| 128 return base::StringPrintf( | |
| 129 "%s|%s|%s", os_name.c_str(), os_hardware.c_str(), os_version.c_str()); | |
| 130 } | |
| 131 }; | |
| 132 | |
| 133 } // namespace | 68 } // namespace |
| 134 | 69 |
| 135 ChromeBrowserPolicyConnector::ChromeBrowserPolicyConnector() | 70 ChromeBrowserPolicyConnector::ChromeBrowserPolicyConnector() |
| 136 : BrowserPolicyConnector(base::Bind(&BuildHandlerList)) { | 71 : BrowserPolicyConnector(base::Bind(&BuildHandlerList)) { |
| 137 ConfigurationPolicyProvider* platform_provider = CreatePlatformProvider(); | 72 ConfigurationPolicyProvider* platform_provider = CreatePlatformProvider(); |
| 138 if (platform_provider) | 73 if (platform_provider) |
| 139 SetPlatformPolicyProvider(make_scoped_ptr(platform_provider)); | 74 SetPlatformPolicyProvider(make_scoped_ptr(platform_provider)); |
| 140 } | 75 } |
| 141 | 76 |
| 142 ChromeBrowserPolicyConnector::~ChromeBrowserPolicyConnector() {} | 77 ChromeBrowserPolicyConnector::~ChromeBrowserPolicyConnector() {} |
| 143 | 78 |
| 144 void ChromeBrowserPolicyConnector::Init( | 79 void ChromeBrowserPolicyConnector::Init( |
| 145 PrefService* local_state, | 80 PrefService* local_state, |
| 146 scoped_refptr<net::URLRequestContextGetter> request_context) { | 81 scoped_refptr<net::URLRequestContextGetter> request_context) { |
| 147 // Initialization of some of the providers requires the FILE thread; make | 82 // Initialization of some of the providers requires the FILE thread; make |
| 148 // sure that threading is ready at this point. | 83 // sure that threading is ready at this point. |
| 149 DCHECK(BrowserThread::IsThreadInitialized(BrowserThread::FILE)); | 84 DCHECK(BrowserThread::IsThreadInitialized(BrowserThread::FILE)); |
| 150 | 85 |
| 151 scoped_ptr<DeviceManagementService::Configuration> configuration( | 86 scoped_ptr<DeviceManagementService::Configuration> configuration( |
| 152 new DeviceManagementServiceConfiguration); | 87 new DeviceManagementServiceConfiguration( |
| 88 BrowserPolicyConnector::GetDeviceManagementUrl())); |
| 153 scoped_ptr<DeviceManagementService> device_management_service( | 89 scoped_ptr<DeviceManagementService> device_management_service( |
| 154 new DeviceManagementService(configuration.Pass())); | 90 new DeviceManagementService(configuration.Pass())); |
| 155 device_management_service->ScheduleInitialization( | 91 device_management_service->ScheduleInitialization( |
| 156 kServiceInitializationStartupDelay); | 92 kServiceInitializationStartupDelay); |
| 157 | 93 |
| 158 BrowserPolicyConnector::Init( | 94 BrowserPolicyConnector::Init( |
| 159 local_state, request_context, device_management_service.Pass()); | 95 local_state, request_context, device_management_service.Pass()); |
| 160 } | 96 } |
| 161 | 97 |
| 162 ConfigurationPolicyProvider* | 98 ConfigurationPolicyProvider* |
| (...skipping 21 matching lines...) Expand all Loading... |
| 184 return NULL; | 120 return NULL; |
| 185 } | 121 } |
| 186 #elif defined(OS_ANDROID) | 122 #elif defined(OS_ANDROID) |
| 187 return new PolicyProviderAndroid(); | 123 return new PolicyProviderAndroid(); |
| 188 #else | 124 #else |
| 189 return NULL; | 125 return NULL; |
| 190 #endif | 126 #endif |
| 191 } | 127 } |
| 192 | 128 |
| 193 } // namespace policy | 129 } // namespace policy |
| OLD | NEW |