| 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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 policy_provider->InitDefaults(); | 513 policy_provider->InitDefaults(); |
| 514 | 514 |
| 515 // Initialize the filter. | 515 // Initialize the filter. |
| 516 OnDefaultFilteringBehaviorChanged(); | 516 OnDefaultFilteringBehaviorChanged(); |
| 517 UpdateSiteLists(); | 517 UpdateSiteLists(); |
| 518 UpdateManualHosts(); | 518 UpdateManualHosts(); |
| 519 UpdateManualURLs(); | 519 UpdateManualURLs(); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void ManagedUserService::RegisterAndInitSync( | 522 void ManagedUserService::RegisterAndInitSync( |
| 523 ManagedUserRegistrationService* registration_service) { | 523 ManagedUserRegistrationService* registration_service, |
| 524 string16 name = UTF8ToUTF16(profile_->GetProfileName()); | 524 const ProfileManager::CreateCallback& callback) { |
| 525 string16 name = UTF8ToUTF16( |
| 526 profile_->GetPrefs()->GetString(prefs::kProfileName)); |
| 525 registration_service->Register( | 527 registration_service->Register( |
| 526 name, | 528 name, |
| 527 base::Bind(&ManagedUserService::OnManagedUserRegistered, | 529 base::Bind(&ManagedUserService::OnManagedUserRegistered, |
| 528 weak_ptr_factory_.GetWeakPtr())); | 530 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 529 } | 531 } |
| 530 | 532 |
| 531 void ManagedUserService::OnManagedUserRegistered( | 533 void ManagedUserService::OnManagedUserRegistered( |
| 534 const ProfileManager::CreateCallback& callback, |
| 532 const GoogleServiceAuthError& auth_error, | 535 const GoogleServiceAuthError& auth_error, |
| 533 const std::string& token) { | 536 const std::string& token) { |
| 534 if (auth_error.state() != GoogleServiceAuthError::NONE) { | 537 if (auth_error.state() != GoogleServiceAuthError::NONE) { |
| 535 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); | 538 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); |
| 536 DCHECK_EQ(std::string(), token); | 539 DCHECK_EQ(std::string(), token); |
| 540 callback.Run(profile_, Profile::CREATE_STATUS_REMOTE_FAIL); |
| 537 return; | 541 return; |
| 538 } | 542 } |
| 539 | 543 |
| 540 InitSync(token); | 544 InitSync(token); |
| 545 callback.Run(profile_, Profile::CREATE_STATUS_INITIALIZED); |
| 541 } | 546 } |
| 542 | 547 |
| 543 void ManagedUserService::UpdateManualHosts() { | 548 void ManagedUserService::UpdateManualHosts() { |
| 544 const DictionaryValue* dict = | 549 const DictionaryValue* dict = |
| 545 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); | 550 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); |
| 546 scoped_ptr<std::map<std::string, bool> > host_map( | 551 scoped_ptr<std::map<std::string, bool> > host_map( |
| 547 new std::map<std::string, bool>()); | 552 new std::map<std::string, bool>()); |
| 548 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 553 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 549 bool allow = false; | 554 bool allow = false; |
| 550 bool result = it.value().GetAsBoolean(&allow); | 555 bool result = it.value().GetAsBoolean(&allow); |
| 551 DCHECK(result); | 556 DCHECK(result); |
| 552 (*host_map)[it.key()] = allow; | 557 (*host_map)[it.key()] = allow; |
| 553 } | 558 } |
| 554 url_filter_context_.SetManualHosts(host_map.Pass()); | 559 url_filter_context_.SetManualHosts(host_map.Pass()); |
| 555 } | 560 } |
| 556 | 561 |
| 557 void ManagedUserService::UpdateManualURLs() { | 562 void ManagedUserService::UpdateManualURLs() { |
| 558 const DictionaryValue* dict = | 563 const DictionaryValue* dict = |
| 559 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 564 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
| 560 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 565 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
| 561 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 566 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 562 bool allow = false; | 567 bool allow = false; |
| 563 bool result = it.value().GetAsBoolean(&allow); | 568 bool result = it.value().GetAsBoolean(&allow); |
| 564 DCHECK(result); | 569 DCHECK(result); |
| 565 (*url_map)[GURL(it.key())] = allow; | 570 (*url_map)[GURL(it.key())] = allow; |
| 566 } | 571 } |
| 567 url_filter_context_.SetManualURLs(url_map.Pass()); | 572 url_filter_context_.SetManualURLs(url_map.Pass()); |
| 568 } | 573 } |
| OLD | NEW |