| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/managed_mode/managed_user_service.h" | 5 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 286 |
| 287 void ManagedUserService::DidBlockNavigation( | 287 void ManagedUserService::DidBlockNavigation( |
| 288 content::WebContents* web_contents) { | 288 content::WebContents* web_contents) { |
| 289 for (std::vector<NavigationBlockedCallback>::iterator it = | 289 for (std::vector<NavigationBlockedCallback>::iterator it = |
| 290 navigation_blocked_callbacks_.begin(); | 290 navigation_blocked_callbacks_.begin(); |
| 291 it != navigation_blocked_callbacks_.end(); ++it) { | 291 it != navigation_blocked_callbacks_.end(); ++it) { |
| 292 it->Run(web_contents); | 292 it->Run(web_contents); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 void ManagedUserService::AddInitCallback( | |
| 297 const base::Closure& callback) { | |
| 298 init_callbacks_.push_back(callback); | |
| 299 } | |
| 300 | |
| 301 std::string ManagedUserService::GetDebugPolicyProviderName() const { | 296 std::string ManagedUserService::GetDebugPolicyProviderName() const { |
| 302 // Save the string space in official builds. | 297 // Save the string space in official builds. |
| 303 #ifdef NDEBUG | 298 #ifdef NDEBUG |
| 304 NOTREACHED(); | 299 NOTREACHED(); |
| 305 return std::string(); | 300 return std::string(); |
| 306 #else | 301 #else |
| 307 return "Managed User Service"; | 302 return "Managed User Service"; |
| 308 #endif | 303 #endif |
| 309 } | 304 } |
| 310 | 305 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 std::vector<GURL>* urls) { | 516 std::vector<GURL>* urls) { |
| 522 const DictionaryValue* dict = | 517 const DictionaryValue* dict = |
| 523 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 518 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
| 524 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 519 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 525 GURL url(it.key()); | 520 GURL url(it.key()); |
| 526 if (url.host() == host) | 521 if (url.host() == host) |
| 527 urls->push_back(url); | 522 urls->push_back(url); |
| 528 } | 523 } |
| 529 } | 524 } |
| 530 | 525 |
| 531 void ManagedUserService::InitForTesting() { | |
| 532 DCHECK(!profile_->IsManaged()); | |
| 533 profile_->GetPrefs()->SetString(prefs::kManagedUserId, "Test ID"); | |
| 534 Init(); | |
| 535 } | |
| 536 | |
| 537 void ManagedUserService::InitSync(const std::string& refresh_token) { | 526 void ManagedUserService::InitSync(const std::string& refresh_token) { |
| 538 ProfileSyncService* service = | 527 ProfileSyncService* service = |
| 539 ProfileSyncServiceFactory::GetForProfile(profile_); | 528 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 540 // Tell the sync service that setup is in progress so we don't start syncing | 529 // Tell the sync service that setup is in progress so we don't start syncing |
| 541 // until we've finished configuration. | 530 // until we've finished configuration. |
| 542 service->SetSetupInProgress(true); | 531 service->SetSetupInProgress(true); |
| 543 | 532 |
| 544 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 533 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| 545 token_service->UpdateCredentialsWithOAuth2( | 534 token_service->UpdateCredentialsWithOAuth2( |
| 546 GaiaAuthConsumer::ClientOAuthResult(refresh_token, std::string(), 0)); | 535 GaiaAuthConsumer::ClientOAuthResult(refresh_token, std::string(), 0)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 base::Bind(&ManagedUserService::UpdateManualURLs, | 593 base::Bind(&ManagedUserService::UpdateManualURLs, |
| 605 base::Unretained(this))); | 594 base::Unretained(this))); |
| 606 | 595 |
| 607 BrowserList::AddObserver(this); | 596 BrowserList::AddObserver(this); |
| 608 | 597 |
| 609 // Initialize the filter. | 598 // Initialize the filter. |
| 610 OnDefaultFilteringBehaviorChanged(); | 599 OnDefaultFilteringBehaviorChanged(); |
| 611 UpdateSiteLists(); | 600 UpdateSiteLists(); |
| 612 UpdateManualHosts(); | 601 UpdateManualHosts(); |
| 613 UpdateManualURLs(); | 602 UpdateManualURLs(); |
| 614 | |
| 615 // Call the callbacks to notify that the ManagedUserService has been | |
| 616 // initialized. | |
| 617 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); | |
| 618 it != init_callbacks_.end(); | |
| 619 ++it) { | |
| 620 it->Run(); | |
| 621 } | |
| 622 } | 603 } |
| 623 | 604 |
| 624 void ManagedUserService::RegisterAndInitSync( | 605 void ManagedUserService::RegisterAndInitSync( |
| 625 ManagedUserRegistrationUtility* registration_utility, | 606 ManagedUserRegistrationUtility* registration_utility, |
| 626 Profile* custodian_profile, | 607 Profile* custodian_profile, |
| 627 const std::string& managed_user_id, | 608 const std::string& managed_user_id, |
| 628 const AuthErrorCallback& callback) { | 609 const AuthErrorCallback& callback) { |
| 629 DCHECK(ProfileIsManaged()); | 610 DCHECK(ProfileIsManaged()); |
| 630 DCHECK(!custodian_profile->IsManaged()); | 611 DCHECK(!custodian_profile->IsManaged()); |
| 631 | 612 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 key_prefix, | 699 key_prefix, |
| 719 base::Int64ToString(base::TimeTicks::Now().ToInternalValue())); | 700 base::Int64ToString(base::TimeTicks::Now().ToInternalValue())); |
| 720 | 701 |
| 721 scoped_ptr<DictionaryValue> dict(new DictionaryValue); | 702 scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
| 722 | 703 |
| 723 // TODO(bauerb): Use sane time when ready. | 704 // TODO(bauerb): Use sane time when ready. |
| 724 dict->SetDouble(kEventTimestamp, base::Time::Now().ToJsTime()); | 705 dict->SetDouble(kEventTimestamp, base::Time::Now().ToJsTime()); |
| 725 | 706 |
| 726 GetSettingsService()->UploadItem(key, dict.PassAs<Value>()); | 707 GetSettingsService()->UploadItem(key, dict.PassAs<Value>()); |
| 727 } | 708 } |
| OLD | NEW |