Commit 22a97ba1 authored by davidyu@chromium.org's avatar davidyu@chromium.org

Add consumer_device_management_service() in BrowserPolicyConnectorChromeOS.

    
    Expose kServiceInitializationStartupDelay in ChromeBrowserPolicyConnector.
    
    Extract DeviceManagementServiceConfiguration to its own files.
    
    Add a command line flag to override the consumer DM server address for
    testing.
    
    Fix a comment in policy_switches as it no longer applies.
    
    BUG=353050
    TEST=manual

Review URL: https://codereview.chromium.org/240903002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266449 0039d316-1c4b-4281-b951-d872f2087c98
parent c8d3a7c3
......@@ -197,6 +197,7 @@ std::string DeriveCommandLine(const GURL& start_url,
cc::switches::kShowSurfaceDamageRects,
cc::switches::kSlowDownRasterScaleFactor,
cc::switches::kUIDisablePartialSwap,
chromeos::switches::kConsumerDeviceManagementUrl,
chromeos::switches::kDbusStub,
chromeos::switches::kDisableLoginAnimations,
chromeos::switches::kEnableConsumerManagement,
......@@ -205,9 +206,9 @@ std::string DeriveCommandLine(const GURL& start_url,
chromeos::switches::kLoginProfile,
chromeos::switches::kNaturalScrollDefault,
chromeos::switches::kSystemInDevMode,
policy::switches::kDeviceManagementUrl,
::switches::kEnableBrowserTextSubpixelPositioning,
::switches::kEnableWebkitTextSubpixelPositioning,
policy::switches::kDeviceManagementUrl,
wm::switches::kWindowAnimationsDisabled,
};
command_line->CopySwitchesFrom(base_command_line,
......
......@@ -4,6 +4,8 @@
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include <string>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
......@@ -22,6 +24,7 @@
#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/policy/device_management_service_configuration.h"
#include "chrome/common/pref_names.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/chromeos_switches.h"
......@@ -46,6 +49,13 @@ namespace policy {
namespace {
// TODO(davidyu): Update the URL to the real one once it is ready.
// http://crbug.com/366491.
//
// The URL for the consumer device management server.
const char kDefaultConsumerDeviceManagementServerUrl[] =
"https://m.google.com/devicemanagement/data/api";
// Install attributes for tests.
EnterpriseInstallAttributes* g_testing_install_attributes = NULL;
......@@ -58,6 +68,16 @@ scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() {
pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
}
std::string GetConsumerDeviceManagementServerUrl() {
const CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(
chromeos::switches::kConsumerDeviceManagementUrl)) {
return command_line->GetSwitchValueASCII(
chromeos::switches::kConsumerDeviceManagementUrl);
}
return kDefaultConsumerDeviceManagementServerUrl;
};
} // namespace
BrowserPolicyConnectorChromeOS::BrowserPolicyConnectorChromeOS()
......@@ -110,6 +130,14 @@ void BrowserPolicyConnectorChromeOS::Init(
scoped_refptr<net::URLRequestContextGetter> request_context) {
ChromeBrowserPolicyConnector::Init(local_state, request_context);
scoped_ptr<DeviceManagementService::Configuration> configuration(
new DeviceManagementServiceConfiguration(
GetConsumerDeviceManagementServerUrl()));
consumer_device_management_service_.reset(
new DeviceManagementService(configuration.Pass()));
consumer_device_management_service_->ScheduleInitialization(
kServiceInitializationStartupDelay);
if (device_cloud_policy_manager_) {
// Note: for now the |device_cloud_policy_manager_| is using the global
// schema registry. Eventually it will have its own registry, once device
......
......@@ -26,6 +26,7 @@ namespace policy {
class AppPackUpdater;
class DeviceCloudPolicyManagerChromeOS;
class DeviceLocalAccountPolicyService;
class DeviceManagementService;
class EnterpriseInstallAttributes;
class NetworkConfigurationUpdater;
class ProxyPolicyProvider;
......@@ -85,6 +86,11 @@ class BrowserPolicyConnectorChromeOS : public ChromeBrowserPolicyConnector {
// delegate, if there is one.
void SetUserPolicyDelegate(ConfigurationPolicyProvider* user_policy_provider);
// Returns the device management service for consumer management.
DeviceManagementService* consumer_device_management_service() const {
return consumer_device_management_service_.get();
}
// Sets the install attributes for testing. Must be called before the browser
// is created. Takes ownership of |attributes|.
static void SetInstallAttributesForTesting(
......@@ -114,6 +120,8 @@ class BrowserPolicyConnectorChromeOS : public ChromeBrowserPolicyConnector {
scoped_ptr<AppPackUpdater> app_pack_updater_;
scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_;
scoped_ptr<DeviceManagementService> consumer_device_management_service_;
base::WeakPtrFactory<BrowserPolicyConnectorChromeOS> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorChromeOS);
......
......@@ -12,12 +12,10 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#include "base/sys_info.h"
#include "chrome/browser/policy/configuration_policy_handler_list_factory.h"
#include "chrome/browser/policy/device_management_service_configuration.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_version_info.h"
#include "components/policy/core/common/async_policy_provider.h"
#include "components/policy/core/common/cloud/device_management_service.h"
#include "components/policy/core/common/configuration_policy_provider.h"
......@@ -38,21 +36,12 @@
#include "components/policy/core/common/policy_provider_android.h"
#endif
#if defined(OS_CHROMEOS)
#include "chromeos/system/statistics_provider.h"
#endif
using content::BrowserThread;
namespace policy {
namespace {
// The following constants define delays applied before the initial policy fetch
// on startup. (So that displaying Chrome's GUI does not get delayed.)
// Delay in milliseconds from startup.
const int64 kServiceInitializationStartupDelay = 5000;
#if defined(OS_MACOSX)
base::FilePath GetManagedPolicyPath() {
// This constructs the path to the plist file in which Mac OS X stores the
......@@ -76,60 +65,6 @@ base::FilePath GetManagedPolicyPath() {
}
#endif // defined(OS_MACOSX)
class DeviceManagementServiceConfiguration
: public DeviceManagementService::Configuration {
public:
DeviceManagementServiceConfiguration() {}
virtual ~DeviceManagementServiceConfiguration() {}
virtual std::string GetServerUrl() OVERRIDE {
return BrowserPolicyConnector::GetDeviceManagementUrl();
}
virtual std::string GetAgentParameter() OVERRIDE {
chrome::VersionInfo version_info;
return base::StringPrintf("%s %s(%s)",
version_info.Name().c_str(),
version_info.Version().c_str(),
version_info.LastChange().c_str());
}
virtual std::string GetPlatformParameter() OVERRIDE {
std::string os_name = base::SysInfo::OperatingSystemName();
std::string os_hardware = base::SysInfo::OperatingSystemArchitecture();
#if defined(OS_CHROMEOS)
chromeos::system::StatisticsProvider* provider =
chromeos::system::StatisticsProvider::GetInstance();
std::string hwclass;
if (!provider->GetMachineStatistic(chromeos::system::kHardwareClassKey,
&hwclass)) {
LOG(ERROR) << "Failed to get machine information";
}
os_name += ",CrOS," + base::SysInfo::GetLsbReleaseBoard();
os_hardware += "," + hwclass;
#endif
std::string os_version("-");
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
int32 os_major_version = 0;
int32 os_minor_version = 0;
int32 os_bugfix_version = 0;
base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
&os_minor_version,
&os_bugfix_version);
os_version = base::StringPrintf("%d.%d.%d",
os_major_version,
os_minor_version,
os_bugfix_version);
#endif
return base::StringPrintf(
"%s|%s|%s", os_name.c_str(), os_hardware.c_str(), os_version.c_str());
}
};
} // namespace
ChromeBrowserPolicyConnector::ChromeBrowserPolicyConnector()
......@@ -149,7 +84,8 @@ void ChromeBrowserPolicyConnector::Init(
DCHECK(BrowserThread::IsThreadInitialized(BrowserThread::FILE));
scoped_ptr<DeviceManagementService::Configuration> configuration(
new DeviceManagementServiceConfiguration);
new DeviceManagementServiceConfiguration(
BrowserPolicyConnector::GetDeviceManagementUrl()));
scoped_ptr<DeviceManagementService> device_management_service(
new DeviceManagementService(configuration.Pass()));
device_management_service->ScheduleInitialization(
......
......@@ -23,6 +23,10 @@ class ConfigurationPolicyProvider;
// implementations and Android.
class ChromeBrowserPolicyConnector : public BrowserPolicyConnector {
public:
// Service initialization delay time in millisecond on startup. (So that
// displaying Chrome's GUI does not get delayed.)
static const int64 kServiceInitializationStartupDelay = 5000;
// Builds an uninitialized ChromeBrowserPolicyConnector, suitable for testing.
// Init() should be called to create and start the policy machinery.
ChromeBrowserPolicyConnector();
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/policy/device_management_service_configuration.h"
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "chrome/common/chrome_version_info.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#if defined(OS_CHROMEOS)
#include "chromeos/system/statistics_provider.h"
#endif
namespace policy {
DeviceManagementServiceConfiguration::DeviceManagementServiceConfiguration(
const std::string& server_url)
: server_url_(server_url) {
}
DeviceManagementServiceConfiguration::~DeviceManagementServiceConfiguration() {
}
std::string DeviceManagementServiceConfiguration::GetServerUrl() {
return server_url_;
}
std::string DeviceManagementServiceConfiguration::GetAgentParameter() {
chrome::VersionInfo version_info;
return base::StringPrintf("%s %s(%s)",
version_info.Name().c_str(),
version_info.Version().c_str(),
version_info.LastChange().c_str());
}
std::string DeviceManagementServiceConfiguration::GetPlatformParameter() {
std::string os_name = base::SysInfo::OperatingSystemName();
std::string os_hardware = base::SysInfo::OperatingSystemArchitecture();
#if defined(OS_CHROMEOS)
chromeos::system::StatisticsProvider* provider =
chromeos::system::StatisticsProvider::GetInstance();
std::string hwclass;
if (!provider->GetMachineStatistic(chromeos::system::kHardwareClassKey,
&hwclass)) {
LOG(ERROR) << "Failed to get machine information";
}
os_name += ",CrOS," + base::SysInfo::GetLsbReleaseBoard();
os_hardware += "," + hwclass;
#endif
std::string os_version("-");
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
int32 os_major_version = 0;
int32 os_minor_version = 0;
int32 os_bugfix_version = 0;
base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
&os_minor_version,
&os_bugfix_version);
os_version = base::StringPrintf("%d.%d.%d",
os_major_version,
os_minor_version,
os_bugfix_version);
#endif
return base::StringPrintf(
"%s|%s|%s", os_name.c_str(), os_hardware.c_str(), os_version.c_str());
}
} // namespace policy
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_CONFIGURATION_H_
#define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_CONFIGURATION_H_
#include <string>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "components/policy/core/common/cloud/device_management_service.h"
namespace policy {
// The real implementation of the device management service configuration that
// is used to create device management service instances.
class DeviceManagementServiceConfiguration
: public DeviceManagementService::Configuration {
public:
explicit DeviceManagementServiceConfiguration(const std::string& server_url);
virtual ~DeviceManagementServiceConfiguration();
virtual std::string GetServerUrl() OVERRIDE;
virtual std::string GetAgentParameter() OVERRIDE;
virtual std::string GetPlatformParameter() OVERRIDE;
private:
const std::string server_url_;
DISALLOW_COPY_AND_ASSIGN(DeviceManagementServiceConfiguration);
};
} // namespace policy
#endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_CONFIGURATION_H_
......@@ -1514,6 +1514,8 @@
'browser/policy/cloud/user_policy_signin_service_ios.mm',
'browser/policy/configuration_policy_handler_list_factory.cc',
'browser/policy/configuration_policy_handler_list_factory.h',
'browser/policy/device_management_service_configuration.cc',
'browser/policy/device_management_service_configuration.h',
'browser/policy/file_selection_dialogs_policy_handler.cc',
'browser/policy/file_selection_dialogs_policy_handler.h',
'browser/policy/javascript_policy_handler.cc',
......
......@@ -15,6 +15,9 @@ const char kAppOemManifestFile[] = "app-mode-oem-manifest";
// Possible values: parallel|postpone. Default: parallel.
const char kAshWebUIInit[] = "ash-webui-init";
// Specifies the URL of the consumer device management backend.
const char kConsumerDeviceManagementUrl[] = "consumer-device-management-url";
// Forces the stub implementation of dbus clients.
const char kDbusStub[] = "dbus-stub";
......
......@@ -22,6 +22,7 @@ namespace switches {
// Please keep alphabetized.
CHROMEOS_EXPORT extern const char kAppOemManifestFile[];
CHROMEOS_EXPORT extern const char kAshWebUIInit[];
CHROMEOS_EXPORT extern const char kConsumerDeviceManagementUrl[];
CHROMEOS_EXPORT extern const char kDbusStub[];
CHROMEOS_EXPORT extern const char kDerelictDetectionTimeout[];
CHROMEOS_EXPORT extern const char kDerelictIdleTimeout[];
......
......@@ -14,8 +14,7 @@ namespace switches {
const char kCloudPolicyInvalidationDelay[] = "cloud-policy-invalidation-delay";
// Specifies the URL at which to fetch configuration policy from the device
// management backend. Specifying this switch turns on managed policy from the
// device management backend.
// management backend.
const char kDeviceManagementUrl[] = "device-management-url";
// Enables fetching and storing cloud policy for components.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment