| 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 #ifndef CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/containers/scoped_ptr_hash_map.h" | 12 #include "base/containers/scoped_ptr_hash_map.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 15 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 16 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 16 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 17 #include "chromeos/dbus/session_manager_client.h" | 17 #include "chromeos/dbus/session_manager_client.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 19 #include "components/ownership/owner_key_util.h" | 19 #include "components/ownership/owner_key_util.h" |
| 20 #include "components/ownership/owner_settings_service.h" | 20 #include "components/ownership/owner_settings_service.h" |
| 21 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 21 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 23 | 24 |
| 24 class Profile; | 25 class Profile; |
| 25 | 26 |
| 26 namespace ownership { | 27 namespace ownership { |
| 27 class OwnerKeyUtil; | 28 class OwnerKeyUtil; |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace chromeos { | 31 namespace chromeos { |
| 31 | 32 |
| 32 // The class is a profile-keyed service which holds public/private | 33 // The class is a profile-keyed service which holds public/private |
| 33 // keypair corresponds to a profile. The keypair is reloaded automatically when | 34 // keypair corresponds to a profile. The keypair is reloaded automatically when |
| 34 // profile is created and TPM token is ready. Note that the private part of a | 35 // profile is created and TPM token is ready. Note that the private part of a |
| 35 // key can be loaded only for the owner. | 36 // key can be loaded only for the owner. |
| 36 // | 37 // |
| 37 // TODO (ygorshenin@): move write path for device settings here | 38 // TODO (ygorshenin@): move write path for device settings here |
| 38 // (crbug.com/230018). | 39 // (crbug.com/230018). |
| 39 class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, | 40 class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, |
| 40 public content::NotificationObserver, | 41 public content::NotificationObserver, |
| 41 public SessionManagerClient::Observer, | 42 public SessionManagerClient::Observer, |
| 42 public DeviceSettingsService::Observer { | 43 public DeviceSettingsService::Observer { |
| 43 public: | 44 public: |
| 45 typedef base::Callback<void(bool success)> OnManagementSettingsSetCallback; |
| 46 |
| 47 struct ManagementSettings { |
| 48 ManagementSettings(); |
| 49 ~ManagementSettings(); |
| 50 |
| 51 policy::ManagementMode management_mode; |
| 52 std::string request_token; |
| 53 std::string device_id; |
| 54 }; |
| 55 |
| 44 virtual ~OwnerSettingsServiceChromeOS(); | 56 virtual ~OwnerSettingsServiceChromeOS(); |
| 45 | 57 |
| 46 void OnTPMTokenReady(bool tpm_token_enabled); | 58 void OnTPMTokenReady(bool tpm_token_enabled); |
| 47 | 59 |
| 48 // ownership::OwnerSettingsService implementation: | 60 // ownership::OwnerSettingsService implementation: |
| 49 virtual bool HandlesSetting(const std::string& setting) override; | 61 virtual bool HandlesSetting(const std::string& setting) override; |
| 50 virtual bool Set(const std::string& setting, | 62 virtual bool Set(const std::string& setting, |
| 51 const base::Value& value) override; | 63 const base::Value& value) override; |
| 52 virtual bool CommitTentativeDeviceSettings( | 64 virtual bool CommitTentativeDeviceSettings( |
| 53 scoped_ptr<enterprise_management::PolicyData> policy) override; | 65 scoped_ptr<enterprise_management::PolicyData> policy) override; |
| 54 | 66 |
| 55 // NotificationObserver implementation: | 67 // NotificationObserver implementation: |
| 56 virtual void Observe(int type, | 68 virtual void Observe(int type, |
| 57 const content::NotificationSource& source, | 69 const content::NotificationSource& source, |
| 58 const content::NotificationDetails& details) override; | 70 const content::NotificationDetails& details) override; |
| 59 | 71 |
| 60 // SessionManagerClient::Observer: | 72 // SessionManagerClient::Observer: |
| 61 virtual void OwnerKeySet(bool success) override; | 73 virtual void OwnerKeySet(bool success) override; |
| 62 | 74 |
| 63 // DeviceSettingsService::Observer: | 75 // DeviceSettingsService::Observer: |
| 64 virtual void OwnershipStatusChanged() override; | 76 virtual void OwnershipStatusChanged() override; |
| 65 virtual void DeviceSettingsUpdated() override; | 77 virtual void DeviceSettingsUpdated() override; |
| 66 virtual void OnDeviceSettingsServiceShutdown() override; | 78 virtual void OnDeviceSettingsServiceShutdown() override; |
| 67 | 79 |
| 80 // Sets the management related settings. |
| 81 void SetManagementSettings(const ManagementSettings& settings, |
| 82 const OnManagementSettingsSetCallback& callback); |
| 83 |
| 68 // Checks if the user is the device owner, without the user profile having to | 84 // Checks if the user is the device owner, without the user profile having to |
| 69 // been initialized. Should be used only if login state is in safe mode. | 85 // been initialized. Should be used only if login state is in safe mode. |
| 70 static void IsOwnerForSafeModeAsync( | 86 static void IsOwnerForSafeModeAsync( |
| 71 const std::string& user_hash, | 87 const std::string& user_hash, |
| 72 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, | 88 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, |
| 73 const IsOwnerCallback& callback); | 89 const IsOwnerCallback& callback); |
| 74 | 90 |
| 75 // Assembles PolicyData based on |settings|, |policy_data| and | 91 // Assembles PolicyData based on |settings|, |policy_data| and |
| 76 // |user_id|. | 92 // |user_id|. |
| 77 static scoped_ptr<enterprise_management::PolicyData> AssemblePolicy( | 93 static scoped_ptr<enterprise_management::PolicyData> AssemblePolicy( |
| 78 const std::string& user_id, | 94 const std::string& user_id, |
| 79 const enterprise_management::PolicyData* policy_data, | 95 const enterprise_management::PolicyData* policy_data, |
| 80 const enterprise_management::ChromeDeviceSettingsProto* settings); | 96 const enterprise_management::ChromeDeviceSettingsProto* settings); |
| 81 | 97 |
| 82 // Updates device |settings|. | 98 // Updates device |settings|. |
| 83 static void UpdateDeviceSettings( | 99 static void UpdateDeviceSettings( |
| 84 const std::string& path, | 100 const std::string& path, |
| 85 const base::Value& value, | 101 const base::Value& value, |
| 86 enterprise_management::ChromeDeviceSettingsProto& settings); | 102 enterprise_management::ChromeDeviceSettingsProto& settings); |
| 87 | 103 |
| 88 bool has_pending_changes() const { | 104 bool has_pending_changes() const { |
| 89 return !pending_changes_.empty() || tentative_settings_.get(); | 105 return !pending_changes_.empty() || tentative_settings_.get() || |
| 106 has_pending_management_settings_; |
| 90 } | 107 } |
| 91 | 108 |
| 92 private: | 109 private: |
| 93 friend class OwnerSettingsServiceChromeOSFactory; | 110 friend class OwnerSettingsServiceChromeOSFactory; |
| 94 | 111 |
| 95 OwnerSettingsServiceChromeOS( | 112 OwnerSettingsServiceChromeOS( |
| 96 DeviceSettingsService* device_settings_service, | 113 DeviceSettingsService* device_settings_service, |
| 97 Profile* profile, | 114 Profile* profile, |
| 98 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); | 115 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); |
| 99 | 116 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 151 |
| 135 // Whether profile still needs to be initialized. | 152 // Whether profile still needs to be initialized. |
| 136 bool waiting_for_profile_creation_; | 153 bool waiting_for_profile_creation_; |
| 137 | 154 |
| 138 // Whether TPM token still needs to be initialized. | 155 // Whether TPM token still needs to be initialized. |
| 139 bool waiting_for_tpm_token_; | 156 bool waiting_for_tpm_token_; |
| 140 | 157 |
| 141 // A set of pending changes to device settings. | 158 // A set of pending changes to device settings. |
| 142 base::ScopedPtrHashMap<std::string, base::Value> pending_changes_; | 159 base::ScopedPtrHashMap<std::string, base::Value> pending_changes_; |
| 143 | 160 |
| 161 // True if there're pending changes to management settings. |
| 162 bool has_pending_management_settings_; |
| 163 |
| 164 // A set of pending changes to management settings. |
| 165 ManagementSettings pending_management_settings_; |
| 166 |
| 167 // A set of callbacks that need to be run after management settings |
| 168 // are set and policy is stored. |
| 169 std::vector<OnManagementSettingsSetCallback> |
| 170 pending_management_settings_callbacks_; |
| 171 |
| 144 // A protobuf containing pending changes to device settings. | 172 // A protobuf containing pending changes to device settings. |
| 145 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> | 173 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> |
| 146 tentative_settings_; | 174 tentative_settings_; |
| 147 | 175 |
| 148 content::NotificationRegistrar registrar_; | 176 content::NotificationRegistrar registrar_; |
| 149 | 177 |
| 150 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_; | 178 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_; |
| 151 | 179 |
| 152 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> store_settings_factory_; | 180 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> store_settings_factory_; |
| 153 | 181 |
| 154 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS); | 182 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS); |
| 155 }; | 183 }; |
| 156 | 184 |
| 157 } // namespace chromeos | 185 } // namespace chromeos |
| 158 | 186 |
| 159 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ | 187 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ |
| OLD | NEW |