Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: chrome/browser/chromeos/policy/device_local_account_policy_service.cc

Issue 822523003: Implement device-local account policy pushing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_2_442800_switch_device_cloud_policy_invalidator
Patch Set: Rebased. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/chromeos/policy/device_local_account_policy_service.h" 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_enumerator.h" 12 #include "base/files/file_enumerator.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.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/sequenced_task_runner.h" 18 #include "base/sequenced_task_runner.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/thread_task_runner_handle.h"
21 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chromeos/policy/affiliated_cloud_policy_invalidator.h"
22 #include "chrome/browser/chromeos/policy/device_local_account.h" 24 #include "chrome/browser/chromeos/policy/device_local_account.h"
23 #include "chrome/browser/chromeos/policy/device_local_account_external_data_serv ice.h" 25 #include "chrome/browser/chromeos/policy/device_local_account_external_data_serv ice.h"
24 #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h" 26 #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h"
25 #include "chrome/browser/chromeos/settings/device_settings_service.h" 27 #include "chrome/browser/chromeos/settings/device_settings_service.h"
26 #include "chrome/common/chrome_content_client.h" 28 #include "chrome/common/chrome_content_client.h"
27 #include "chromeos/chromeos_paths.h" 29 #include "chromeos/chromeos_paths.h"
28 #include "chromeos/dbus/session_manager_client.h" 30 #include "chromeos/dbus/session_manager_client.h"
29 #include "chromeos/settings/cros_settings_names.h" 31 #include "chromeos/settings/cros_settings_names.h"
30 #include "chromeos/settings/cros_settings_provider.h" 32 #include "chromeos/settings/cros_settings_provider.h"
31 #include "components/policy/core/browser/browser_policy_connector.h" 33 #include "components/policy/core/browser/browser_policy_connector.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 115 }
114 116
115 } // namespace 117 } // namespace
116 118
117 DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker( 119 DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker(
118 const DeviceLocalAccount& account, 120 const DeviceLocalAccount& account,
119 const base::FilePath& component_policy_cache_path, 121 const base::FilePath& component_policy_cache_path,
120 scoped_ptr<DeviceLocalAccountPolicyStore> store, 122 scoped_ptr<DeviceLocalAccountPolicyStore> store,
121 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager, 123 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager,
122 const base::Closure& policy_update_callback, 124 const base::Closure& policy_update_callback,
123 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 125 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
124 : account_id_(account.account_id), 126 AffiliatedInvalidationServiceProvider* invalidation_service_provider)
127 : invalidation_service_provider_(invalidation_service_provider),
128 account_id_(account.account_id),
125 user_id_(account.user_id), 129 user_id_(account.user_id),
126 component_policy_cache_path_(component_policy_cache_path), 130 component_policy_cache_path_(component_policy_cache_path),
127 store_(store.Pass()), 131 store_(store.Pass()),
128 extension_tracker_(account, store_.get(), &schema_registry_), 132 extension_tracker_(account, store_.get(), &schema_registry_),
129 external_data_manager_(external_data_manager), 133 external_data_manager_(external_data_manager),
130 core_(dm_protocol::kChromePublicAccountPolicyType, 134 core_(dm_protocol::kChromePublicAccountPolicyType,
131 store_->account_id(), 135 store_->account_id(),
132 store_.get(), 136 store_.get(),
133 task_runner), 137 task_runner),
134 policy_update_callback_(policy_update_callback) { 138 policy_update_callback_(policy_update_callback) {
(...skipping 18 matching lines...) Expand all
153 DeviceLocalAccountPolicyBroker::~DeviceLocalAccountPolicyBroker() { 157 DeviceLocalAccountPolicyBroker::~DeviceLocalAccountPolicyBroker() {
154 store_->RemoveObserver(this); 158 store_->RemoveObserver(this);
155 external_data_manager_->SetPolicyStore(nullptr); 159 external_data_manager_->SetPolicyStore(nullptr);
156 external_data_manager_->Disconnect(); 160 external_data_manager_->Disconnect();
157 } 161 }
158 162
159 void DeviceLocalAccountPolicyBroker::Initialize() { 163 void DeviceLocalAccountPolicyBroker::Initialize() {
160 store_->Load(); 164 store_->Load();
161 } 165 }
162 166
167 bool DeviceLocalAccountPolicyBroker::HasInvalidatorForTest() const {
168 return invalidator_;
169 }
170
163 void DeviceLocalAccountPolicyBroker::ConnectIfPossible( 171 void DeviceLocalAccountPolicyBroker::ConnectIfPossible(
164 chromeos::DeviceSettingsService* device_settings_service, 172 chromeos::DeviceSettingsService* device_settings_service,
165 DeviceManagementService* device_management_service, 173 DeviceManagementService* device_management_service,
166 scoped_refptr<net::URLRequestContextGetter> request_context) { 174 scoped_refptr<net::URLRequestContextGetter> request_context) {
167 if (core_.client()) 175 if (core_.client())
168 return; 176 return;
169 177
170 scoped_ptr<CloudPolicyClient> client(CreateClient(device_settings_service, 178 scoped_ptr<CloudPolicyClient> client(CreateClient(device_settings_service,
171 device_management_service, 179 device_management_service,
172 request_context)); 180 request_context));
173 if (!client) 181 if (!client)
174 return; 182 return;
175 183
176 CreateComponentCloudPolicyService(request_context, client.get()); 184 CreateComponentCloudPolicyService(request_context, client.get());
177 core_.Connect(client.Pass()); 185 core_.Connect(client.Pass());
178 external_data_manager_->Connect(request_context); 186 external_data_manager_->Connect(request_context);
179 core_.StartRefreshScheduler(); 187 core_.StartRefreshScheduler();
180 UpdateRefreshDelay(); 188 UpdateRefreshDelay();
189 invalidator_.reset(new AffiliatedCloudPolicyInvalidator(
190 em::DeviceRegisterRequest::DEVICE,
191 &core_,
192 invalidation_service_provider_));
181 } 193 }
182 194
183 void DeviceLocalAccountPolicyBroker::UpdateRefreshDelay() { 195 void DeviceLocalAccountPolicyBroker::UpdateRefreshDelay() {
184 if (core_.refresh_scheduler()) { 196 if (core_.refresh_scheduler()) {
185 const base::Value* policy_value = 197 const base::Value* policy_value =
186 store_->policy_map().GetValue(key::kPolicyRefreshRate); 198 store_->policy_map().GetValue(key::kPolicyRefreshRate);
187 int delay = 0; 199 int delay = 0;
188 if (policy_value && policy_value->GetAsInteger(&delay)) 200 if (policy_value && policy_value->GetAsInteger(&delay))
189 core_.refresh_scheduler()->SetRefreshDelay(delay); 201 core_.refresh_scheduler()->SetRefreshDelay(delay);
190 } 202 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 content::BrowserThread::GetMessageLoopProxyForThread( 248 content::BrowserThread::GetMessageLoopProxyForThread(
237 content::BrowserThread::FILE), 249 content::BrowserThread::FILE),
238 content::BrowserThread::GetMessageLoopProxyForThread( 250 content::BrowserThread::GetMessageLoopProxyForThread(
239 content::BrowserThread::IO))); 251 content::BrowserThread::IO)));
240 } 252 }
241 253
242 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService( 254 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService(
243 chromeos::SessionManagerClient* session_manager_client, 255 chromeos::SessionManagerClient* session_manager_client,
244 chromeos::DeviceSettingsService* device_settings_service, 256 chromeos::DeviceSettingsService* device_settings_service,
245 chromeos::CrosSettings* cros_settings, 257 chromeos::CrosSettings* cros_settings,
258 AffiliatedInvalidationServiceProvider* invalidation_service_provider,
246 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, 259 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner,
247 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner, 260 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner,
248 scoped_refptr<base::SequencedTaskRunner> 261 scoped_refptr<base::SequencedTaskRunner>
249 external_data_service_backend_task_runner, 262 external_data_service_backend_task_runner,
250 scoped_refptr<base::SequencedTaskRunner> io_task_runner, 263 scoped_refptr<base::SequencedTaskRunner> io_task_runner,
251 scoped_refptr<net::URLRequestContextGetter> request_context) 264 scoped_refptr<net::URLRequestContextGetter> request_context)
252 : session_manager_client_(session_manager_client), 265 : session_manager_client_(session_manager_client),
253 device_settings_service_(device_settings_service), 266 device_settings_service_(device_settings_service),
254 cros_settings_(cros_settings), 267 cros_settings_(cros_settings),
268 invalidation_service_provider_(invalidation_service_provider),
255 device_management_service_(nullptr), 269 device_management_service_(nullptr),
256 waiting_for_cros_settings_(false), 270 waiting_for_cros_settings_(false),
257 orphan_extension_cache_deletion_state_(NOT_STARTED), 271 orphan_extension_cache_deletion_state_(NOT_STARTED),
258 store_background_task_runner_(store_background_task_runner), 272 store_background_task_runner_(store_background_task_runner),
259 extension_cache_task_runner_(extension_cache_task_runner), 273 extension_cache_task_runner_(extension_cache_task_runner),
260 request_context_(request_context), 274 request_context_(request_context),
261 local_accounts_subscription_(cros_settings_->AddSettingsObserver( 275 local_accounts_subscription_(cros_settings_->AddSettingsObserver(
262 chromeos::kAccountsPrefDeviceLocalAccounts, 276 chromeos::kAccountsPrefDeviceLocalAccounts,
263 base::Bind(&DeviceLocalAccountPolicyService:: 277 base::Bind(&DeviceLocalAccountPolicyService::
264 UpdateAccountListIfNonePending, 278 UpdateAccountListIfNonePending,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 store.get()); 469 store.get());
456 broker.reset(new DeviceLocalAccountPolicyBroker( 470 broker.reset(new DeviceLocalAccountPolicyBroker(
457 *it, 471 *it,
458 component_policy_cache_root_.Append( 472 component_policy_cache_root_.Append(
459 GetCacheSubdirectoryForAccountID(it->account_id)), 473 GetCacheSubdirectoryForAccountID(it->account_id)),
460 store.Pass(), 474 store.Pass(),
461 external_data_manager, 475 external_data_manager,
462 base::Bind(&DeviceLocalAccountPolicyService::NotifyPolicyUpdated, 476 base::Bind(&DeviceLocalAccountPolicyService::NotifyPolicyUpdated,
463 base::Unretained(this), 477 base::Unretained(this),
464 it->user_id), 478 it->user_id),
465 base::MessageLoopProxy::current())); 479 base::ThreadTaskRunnerHandle::Get(),
480 invalidation_service_provider_));
466 } 481 }
467 482
468 // Fire up the cloud connection for fetching policy for the account from 483 // Fire up the cloud connection for fetching policy for the account from
469 // the cloud if this is an enterprise-managed device. 484 // the cloud if this is an enterprise-managed device.
470 broker->ConnectIfPossible(device_settings_service_, 485 broker->ConnectIfPossible(device_settings_service_,
471 device_management_service_, 486 device_management_service_,
472 request_context_); 487 request_context_);
473 488
474 policy_brokers_[it->user_id] = broker.release(); 489 policy_brokers_[it->user_id] = broker.release();
475 if (!broker_initialized) { 490 if (!broker_initialized) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 } 575 }
561 return nullptr; 576 return nullptr;
562 } 577 }
563 578
564 void DeviceLocalAccountPolicyService::NotifyPolicyUpdated( 579 void DeviceLocalAccountPolicyService::NotifyPolicyUpdated(
565 const std::string& user_id) { 580 const std::string& user_id) {
566 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(user_id)); 581 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(user_id));
567 } 582 }
568 583
569 } // namespace policy 584 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698