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

Side by Side Diff: chrome/browser/ui/webui/policy_ui.cc

Issue 11946017: Remove old cloud policy code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits. Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/policy_ui.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ui/webui/policy_ui.h" 5 #include "chrome/browser/ui/webui/policy_ui.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"
(...skipping 22 matching lines...) Expand all
33 #include "chrome/common/time_format.h" 33 #include "chrome/common/time_format.h"
34 #include "chrome/common/url_constants.h" 34 #include "chrome/common/url_constants.h"
35 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
36 #include "content/public/browser/web_ui.h" 36 #include "content/public/browser/web_ui.h"
37 #include "grit/browser_resources.h" 37 #include "grit/browser_resources.h"
38 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
39 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
40 40
41 #if defined(OS_CHROMEOS) 41 #if defined(OS_CHROMEOS)
42 #include "chrome/browser/chromeos/login/user_manager.h" 42 #include "chrome/browser/chromeos/login/user_manager.h"
43 #include "chrome/browser/policy/cloud_policy_cache_base.h"
44 #include "chrome/browser/policy/cloud_policy_data_store.h"
45 #include "chrome/browser/policy/device_cloud_policy_manager_chromeos.h" 43 #include "chrome/browser/policy/device_cloud_policy_manager_chromeos.h"
46 #include "chrome/browser/policy/device_local_account_policy_service.h" 44 #include "chrome/browser/policy/device_local_account_policy_service.h"
47 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h" 45 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h"
48 #else 46 #else
49 #include "chrome/browser/policy/user_cloud_policy_manager.h" 47 #include "chrome/browser/policy/user_cloud_policy_manager.h"
50 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h" 48 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h"
51 #endif 49 #endif
52 50
53 namespace em = enterprise_management; 51 namespace em = enterprise_management;
54 52
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 interval = refresh_scheduler->refresh_delay(); 271 interval = refresh_scheduler->refresh_delay();
274 status_dict->SetString( 272 status_dict->SetString(
275 "fetchInterval", 273 "fetchInterval",
276 TimeFormat::TimeRemainingShort( 274 TimeFormat::TimeRemainingShort(
277 base::TimeDelta::FromMilliseconds(interval))); 275 base::TimeDelta::FromMilliseconds(interval)));
278 276
279 return store->is_managed(); 277 return store->is_managed();
280 } 278 }
281 279
282 #if defined(OS_CHROMEOS) 280 #if defined(OS_CHROMEOS)
283 // A cloud policy status provider implementation that reads status data from a
284 // CloudPolicySubsystem and observes it to forward changes to the status change
285 // callback.
286 // TODO(mnissler): Remove this once the legacy cloud policy code gets retired
287 // (http://crbug.com/108928).
288 class CloudPolicySubsystemStatusProvider
289 : public CloudPolicyStatusProvider,
290 public policy::CloudPolicySubsystem::Observer {
291 public:
292 CloudPolicySubsystemStatusProvider(policy::CloudPolicySubsystem* subsystem,
293 const std::string& refresh_pref)
294 : subsystem_(subsystem),
295 registrar_(subsystem, this),
296 refresh_pref_(refresh_pref) {}
297 virtual ~CloudPolicySubsystemStatusProvider() {}
298
299 // CloudPolicyStatusProvider:
300 virtual bool GetStatus(base::DictionaryValue* status_dict) OVERRIDE;
301
302 // policy::CloudPolicySubsystem::Observer:
303 virtual void OnPolicyStateChanged(
304 policy::CloudPolicySubsystem::PolicySubsystemState state,
305 policy::CloudPolicySubsystem::ErrorDetails error_details) OVERRIDE {
306 NotifyStatusChange();
307 }
308
309 private:
310 // The subsystem supplying status information.
311 policy::CloudPolicySubsystem* subsystem_;
312
313 // Manages the observer registration with |subsystem_|.
314 policy::CloudPolicySubsystem::ObserverRegistrar registrar_;
315
316 // The refresh interval is read from this pref key in
317 // g_browser_process->local_state().
318 const std::string refresh_pref_;
319
320 DISALLOW_COPY_AND_ASSIGN(CloudPolicySubsystemStatusProvider);
321 };
322
323 bool CloudPolicySubsystemStatusProvider::GetStatus(
324 base::DictionaryValue* status_dict) {
325 static const int kStatusErrorMap[] = {
326 IDS_POLICY_STATUS_OK,
327 IDS_POLICY_STATUS_NETWORK_ERROR,
328 IDS_POLICY_STATUS_NETWORK_ERROR, // this is also a network error.
329 IDS_POLICY_STATUS_DMTOKEN_ERROR,
330 IDS_POLICY_STATUS_LOCAL_ERROR,
331 IDS_POLICY_STATUS_SIGNATURE_ERROR,
332 IDS_POLICY_STATUS_SERIAL_ERROR,
333 };
334 policy::CloudPolicySubsystem::ErrorDetails error_details =
335 subsystem_->error_details();
336 DCHECK(static_cast<size_t>(error_details) < arraysize(kStatusErrorMap));
337 status_dict->SetString(
338 "statusMessage",
339 l10n_util::GetStringUTF16(kStatusErrorMap[error_details]));
340
341 string16 time_since_last_fetch;
342 base::Time last_refresh_time =
343 subsystem_->GetCloudPolicyCacheBase()->last_policy_refresh_time();
344 if (last_refresh_time.is_null()) {
345 time_since_last_fetch =
346 l10n_util::GetStringUTF16(IDS_POLICY_NEVER_FETCHED);
347 } else {
348 base::Time now = base::Time::NowFromSystemTime();
349 time_since_last_fetch = TimeFormat::TimeElapsed(now - last_refresh_time);
350 }
351 status_dict->SetString("timeSinceLastFetch", time_since_last_fetch);
352
353 policy::CloudPolicyDataStore* data_store = subsystem_->data_store();
354 status_dict->SetString(
355 "clientId",
356 data_store ? ASCIIToUTF16(data_store->device_id()) : string16());
357 status_dict->SetString(
358 "user",
359 data_store ? UTF8ToUTF16(data_store->user_name()) : string16());
360
361 PrefService* prefs = g_browser_process->local_state();
362 status_dict->SetString("fetchInterval",
363 TimeFormat::TimeRemainingShort(
364 base::TimeDelta::FromMilliseconds(
365 prefs->GetInteger(refresh_pref_.c_str()))));
366
367 return subsystem_->state() != policy::CloudPolicySubsystem::UNMANAGED;
368 }
369
370 // A cloud policy status provider that reads policy status from the policy core 281 // A cloud policy status provider that reads policy status from the policy core
371 // associated with the device-local account specified by |account_id| at 282 // associated with the device-local account specified by |account_id| at
372 // construction time. The indirection via account ID and 283 // construction time. The indirection via account ID and
373 // DeviceLocalAccountPolicyService is necessary because the device-local account 284 // DeviceLocalAccountPolicyService is necessary because the device-local account
374 // may go away any time behind the scenes, at which point the status message 285 // may go away any time behind the scenes, at which point the status message
375 // text will indicate CloudPolicyStore::STATUS_BAD_STATE. 286 // text will indicate CloudPolicyStore::STATUS_BAD_STATE.
376 class DeviceLocalAccountPolicyStatusProvider 287 class DeviceLocalAccountPolicyStatusProvider
377 : public CloudPolicyStatusProvider, 288 : public CloudPolicyStatusProvider,
378 public policy::DeviceLocalAccountPolicyService::Observer { 289 public policy::DeviceLocalAccountPolicyService::Observer {
379 public: 290 public:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 PolicyUIHandler::~PolicyUIHandler() { 346 PolicyUIHandler::~PolicyUIHandler() {
436 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this); 347 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this);
437 } 348 }
438 349
439 void PolicyUIHandler::RegisterMessages() { 350 void PolicyUIHandler::RegisterMessages() {
440 #if defined(OS_CHROMEOS) 351 #if defined(OS_CHROMEOS)
441 policy::BrowserPolicyConnector* connector = 352 policy::BrowserPolicyConnector* connector =
442 g_browser_process->browser_policy_connector(); 353 g_browser_process->browser_policy_connector();
443 if (connector->IsEnterpriseManaged()) { 354 if (connector->IsEnterpriseManaged()) {
444 enterprise_domain_ = UTF8ToUTF16(connector->GetEnterpriseDomain()); 355 enterprise_domain_ = UTF8ToUTF16(connector->GetEnterpriseDomain());
445 policy::DeviceCloudPolicyManagerChromeOS* device_policy_manager = 356 device_status_provider_.reset(
446 connector->GetDeviceCloudPolicyManager(); 357 new CloudPolicyCoreStatusProvider(
447 policy::CloudPolicySubsystem* device_subsystem = 358 connector->GetDeviceCloudPolicyManager()->core()));
448 connector->device_cloud_policy_subsystem();
449 if (device_policy_manager) {
450 device_status_provider_.reset(
451 new CloudPolicyCoreStatusProvider(device_policy_manager->core()));
452 } else if (device_subsystem) {
453 device_status_provider_.reset(
454 new CloudPolicySubsystemStatusProvider(
455 device_subsystem, prefs::kDevicePolicyRefreshRate));
456 }
457 } 359 }
458 360
459 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); 361 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
460 policy::CloudPolicyManager* user_cloud_policy_manager =
461 connector->GetUserCloudPolicyManager();
462 policy::CloudPolicySubsystem* user_subsystem =
463 connector->user_cloud_policy_subsystem();
464 if (user_manager->IsLoggedInAsPublicAccount()) { 362 if (user_manager->IsLoggedInAsPublicAccount()) {
465 policy::DeviceLocalAccountPolicyService* local_account_service = 363 policy::DeviceLocalAccountPolicyService* local_account_service =
466 connector->GetDeviceLocalAccountPolicyService(); 364 connector->GetDeviceLocalAccountPolicyService();
467 if (local_account_service) { 365 if (local_account_service) {
468 user_status_provider_.reset( 366 user_status_provider_.reset(
469 new DeviceLocalAccountPolicyStatusProvider( 367 new DeviceLocalAccountPolicyStatusProvider(
470 user_manager->GetLoggedInUser()->email(), local_account_service)); 368 user_manager->GetLoggedInUser()->email(), local_account_service));
471 } 369 }
472 } else if (user_cloud_policy_manager) { 370 } else {
473 user_status_provider_.reset( 371 user_status_provider_.reset(
474 new CloudPolicyCoreStatusProvider(user_cloud_policy_manager->core())); 372 new CloudPolicyCoreStatusProvider(
475 } else if (user_subsystem) { 373 connector->GetUserCloudPolicyManager()->core()));
476 user_status_provider_.reset(
477 new CloudPolicySubsystemStatusProvider(
478 user_subsystem, prefs::kUserPolicyRefreshRate));
479 } 374 }
480 #else 375 #else
481 policy::CloudPolicyManager* user_cloud_policy_manager = 376 policy::CloudPolicyManager* user_cloud_policy_manager =
482 policy::UserCloudPolicyManagerFactory::GetForProfile( 377 policy::UserCloudPolicyManagerFactory::GetForProfile(
483 Profile::FromWebUI(web_ui())); 378 Profile::FromWebUI(web_ui()));
484 if (user_cloud_policy_manager) { 379 if (user_cloud_policy_manager) {
485 user_status_provider_.reset( 380 user_status_provider_.reset(
486 new CloudPolicyCoreStatusProvider(user_cloud_policy_manager->core())); 381 new CloudPolicyCoreStatusProvider(user_cloud_policy_manager->core()));
487 } 382 }
488 #endif 383 #endif
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { 534 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) {
640 web_ui->AddMessageHandler(new PolicyUIHandler); 535 web_ui->AddMessageHandler(new PolicyUIHandler);
641 536
642 // Set up the chrome://policy/ source. 537 // Set up the chrome://policy/ source.
643 Profile* profile = Profile::FromWebUI(web_ui); 538 Profile* profile = Profile::FromWebUI(web_ui);
644 ChromeURLDataManager::AddWebUIDataSource(profile, CreatePolicyUIHTMLSource()); 539 ChromeURLDataManager::AddWebUIDataSource(profile, CreatePolicyUIHTMLSource());
645 } 540 }
646 541
647 PolicyUI::~PolicyUI() { 542 PolicyUI::~PolicyUI() {
648 } 543 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/policy_ui.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698