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

Side by Side Diff: chrome/browser/managed_mode/managed_user_service.cc

Issue 104493005: Update some uses of Value in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 12 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
OLDNEW
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/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 // Normalize the URL. 448 // Normalize the URL.
449 GURL normalized_url = ManagedModeURLFilter::Normalize(url); 449 GURL normalized_url = ManagedModeURLFilter::Normalize(url);
450 450
451 // Escape the URL. 451 // Escape the URL.
452 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true)); 452 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true));
453 453
454 // Add the prefix. 454 // Add the prefix.
455 std::string key = ManagedUserSettingsService::MakeSplitSettingKey( 455 std::string key = ManagedUserSettingsService::MakeSplitSettingKey(
456 kManagedUserAccessRequestKeyPrefix, output); 456 kManagedUserAccessRequestKeyPrefix, output);
457 457
458 scoped_ptr<DictionaryValue> dict(new DictionaryValue); 458 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
459 459
460 // TODO(sergiu): Use sane time here when it's ready. 460 // TODO(sergiu): Use sane time here when it's ready.
461 dict->SetDouble(kManagedUserAccessRequestTime, base::Time::Now().ToJsTime()); 461 dict->SetDouble(kManagedUserAccessRequestTime, base::Time::Now().ToJsTime());
462 462
463 dict->SetString(kManagedUserName, profile_->GetProfileName()); 463 dict->SetString(kManagedUserName, profile_->GetProfileName());
464 464
465 GetSettingsService()->UploadItem(key, dict.PassAs<Value>()); 465 GetSettingsService()->UploadItem(key, dict.PassAs<base::Value>());
466 } 466 }
467 467
468 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost( 468 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost(
469 const std::string& hostname) { 469 const std::string& hostname) {
470 const DictionaryValue* dict = 470 const base::DictionaryValue* dict =
471 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); 471 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts);
472 bool allow = false; 472 bool allow = false;
473 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow)) 473 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow))
474 return MANUAL_NONE; 474 return MANUAL_NONE;
475 475
476 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; 476 return allow ? MANUAL_ALLOW : MANUAL_BLOCK;
477 } 477 }
478 478
479 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForURL( 479 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForURL(
480 const GURL& url) { 480 const GURL& url) {
481 const DictionaryValue* dict = 481 const base::DictionaryValue* dict =
482 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); 482 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs);
483 GURL normalized_url = ManagedModeURLFilter::Normalize(url); 483 GURL normalized_url = ManagedModeURLFilter::Normalize(url);
484 bool allow = false; 484 bool allow = false;
485 if (!dict->GetBooleanWithoutPathExpansion(normalized_url.spec(), &allow)) 485 if (!dict->GetBooleanWithoutPathExpansion(normalized_url.spec(), &allow))
486 return MANUAL_NONE; 486 return MANUAL_NONE;
487 487
488 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; 488 return allow ? MANUAL_ALLOW : MANUAL_BLOCK;
489 } 489 }
490 490
491 void ManagedUserService::GetManualExceptionsForHost(const std::string& host, 491 void ManagedUserService::GetManualExceptionsForHost(const std::string& host,
492 std::vector<GURL>* urls) { 492 std::vector<GURL>* urls) {
493 const DictionaryValue* dict = 493 const base::DictionaryValue* dict =
494 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); 494 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs);
495 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { 495 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
496 GURL url(it.key()); 496 GURL url(it.key());
497 if (url.host() == host) 497 if (url.host() == host)
498 urls->push_back(url); 498 urls->push_back(url);
499 } 499 }
500 } 500 }
501 501
502 void ManagedUserService::InitSync(const std::string& refresh_token) { 502 void ManagedUserService::InitSync(const std::string& refresh_token) {
503 ProfileSyncService* service = 503 ProfileSyncService* service =
504 ProfileSyncServiceFactory::GetForProfile(profile_); 504 ProfileSyncServiceFactory::GetForProfile(profile_);
505 // Tell the sync service that setup is in progress so we don't start syncing 505 // Tell the sync service that setup is in progress so we don't start syncing
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianEmail, 626 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianEmail,
627 signin->GetAuthenticatedUsername()); 627 signin->GetAuthenticatedUsername());
628 } else { 628 } else {
629 DCHECK_EQ(std::string(), token); 629 DCHECK_EQ(std::string(), token);
630 } 630 }
631 631
632 callback.Run(auth_error); 632 callback.Run(auth_error);
633 } 633 }
634 634
635 void ManagedUserService::UpdateManualHosts() { 635 void ManagedUserService::UpdateManualHosts() {
636 const DictionaryValue* dict = 636 const base::DictionaryValue* dict =
637 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); 637 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts);
638 scoped_ptr<std::map<std::string, bool> > host_map( 638 scoped_ptr<std::map<std::string, bool> > host_map(
639 new std::map<std::string, bool>()); 639 new std::map<std::string, bool>());
640 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { 640 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
641 bool allow = false; 641 bool allow = false;
642 bool result = it.value().GetAsBoolean(&allow); 642 bool result = it.value().GetAsBoolean(&allow);
643 DCHECK(result); 643 DCHECK(result);
644 (*host_map)[it.key()] = allow; 644 (*host_map)[it.key()] = allow;
645 } 645 }
646 url_filter_context_.SetManualHosts(host_map.Pass()); 646 url_filter_context_.SetManualHosts(host_map.Pass());
647 } 647 }
648 648
649 void ManagedUserService::UpdateManualURLs() { 649 void ManagedUserService::UpdateManualURLs() {
650 const DictionaryValue* dict = 650 const base::DictionaryValue* dict =
651 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); 651 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs);
652 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); 652 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>());
653 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { 653 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
654 bool allow = false; 654 bool allow = false;
655 bool result = it.value().GetAsBoolean(&allow); 655 bool result = it.value().GetAsBoolean(&allow);
656 DCHECK(result); 656 DCHECK(result);
657 (*url_map)[GURL(it.key())] = allow; 657 (*url_map)[GURL(it.key())] = allow;
658 } 658 }
659 url_filter_context_.SetManualURLs(url_map.Pass()); 659 url_filter_context_.SetManualURLs(url_map.Pass());
660 } 660 }
661 661
662 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) { 662 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) {
663 bool profile_became_active = profile_->IsSameProfile(browser->profile()); 663 bool profile_became_active = profile_->IsSameProfile(browser->profile());
664 if (!is_profile_active_ && profile_became_active) 664 if (!is_profile_active_ && profile_became_active)
665 RecordProfileAndBrowserEventsHelper(kOpenManagedProfileKeyPrefix); 665 RecordProfileAndBrowserEventsHelper(kOpenManagedProfileKeyPrefix);
666 else if (is_profile_active_ && !profile_became_active) 666 else if (is_profile_active_ && !profile_became_active)
667 RecordProfileAndBrowserEventsHelper(kSwitchFromManagedProfileKeyPrefix); 667 RecordProfileAndBrowserEventsHelper(kSwitchFromManagedProfileKeyPrefix);
668 668
669 is_profile_active_ = profile_became_active; 669 is_profile_active_ = profile_became_active;
670 } 670 }
671 671
672 void ManagedUserService::RecordProfileAndBrowserEventsHelper( 672 void ManagedUserService::RecordProfileAndBrowserEventsHelper(
673 const char* key_prefix) { 673 const char* key_prefix) {
674 std::string key = ManagedUserSettingsService::MakeSplitSettingKey( 674 std::string key = ManagedUserSettingsService::MakeSplitSettingKey(
675 key_prefix, 675 key_prefix,
676 base::Int64ToString(base::TimeTicks::Now().ToInternalValue())); 676 base::Int64ToString(base::TimeTicks::Now().ToInternalValue()));
677 677
678 scoped_ptr<DictionaryValue> dict(new DictionaryValue); 678 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
679 679
680 // TODO(bauerb): Use sane time when ready. 680 // TODO(bauerb): Use sane time when ready.
681 dict->SetDouble(kEventTimestamp, base::Time::Now().ToJsTime()); 681 dict->SetDouble(kEventTimestamp, base::Time::Now().ToJsTime());
682 682
683 GetSettingsService()->UploadItem(key, dict.PassAs<Value>()); 683 GetSettingsService()->UploadItem(key, dict.PassAs<base::Value>());
684 } 684 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698