Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / policy / browser_policy_connector_chromeos.cc
index 0b31559..af19adc 100644 (file)
@@ -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"
 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h"
 #include "chrome/browser/chromeos/policy/device_status_collector.h"
 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
+#include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.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 +50,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,14 +69,26 @@ 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()
     : device_cloud_policy_manager_(NULL),
       global_user_cloud_policy_provider_(NULL),
       weak_ptr_factory_(this) {
-  if (g_testing_install_attributes)
+  if (g_testing_install_attributes) {
     install_attributes_.reset(g_testing_install_attributes);
+    g_testing_install_attributes = NULL;
+  }
 
   // SystemSaltGetter or DBusThreadManager may be uninitialized on unit tests.
 
@@ -73,9 +96,13 @@ BrowserPolicyConnectorChromeOS::BrowserPolicyConnectorChromeOS()
   // (removing it now breaks tests). crbug.com/141016.
   if (chromeos::SystemSaltGetter::IsInitialized() &&
       chromeos::DBusThreadManager::IsInitialized()) {
+    state_keys_broker_.reset(new ServerBackedStateKeysBroker(
+        chromeos::DBusThreadManager::Get()->GetSessionManagerClient(),
+        base::MessageLoopProxy::current()));
+
     chromeos::CryptohomeClient* cryptohome_client =
         chromeos::DBusThreadManager::Get()->GetCryptohomeClient();
-    if (!g_testing_install_attributes) {
+    if (!install_attributes_) {
       install_attributes_.reset(
           new EnterpriseInstallAttributes(cryptohome_client));
     }
@@ -93,7 +120,8 @@ BrowserPolicyConnectorChromeOS::BrowserPolicyConnectorChromeOS()
         new DeviceCloudPolicyManagerChromeOS(device_cloud_policy_store.Pass(),
                                              base::MessageLoopProxy::current(),
                                              GetBackgroundTaskRunner(),
-                                             install_attributes_.get());
+                                             install_attributes_.get(),
+                                             state_keys_broker_.get());
     AddPolicyProvider(
         scoped_ptr<ConfigurationPolicyProvider>(device_cloud_policy_manager_));
   }
@@ -110,6 +138,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
@@ -215,6 +251,13 @@ void BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
   g_testing_install_attributes = attributes;
 }
 
+void BrowserPolicyConnectorChromeOS::RemoveInstallAttributesForTesting() {
+  if (g_testing_install_attributes) {
+    delete g_testing_install_attributes;
+    g_testing_install_attributes = NULL;
+  }
+}
+
 // static
 void BrowserPolicyConnectorChromeOS::RegisterPrefs(
     PrefRegistrySimple* registry) {