| OLD | NEW |
| 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/managed_mode/managed_mode.h" | 5 #include "chrome/browser/managed_mode/managed_mode.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/public/pref_change_registrar.h" | 8 #include "base/prefs/public/pref_change_registrar.h" |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 // static | 111 // static |
| 112 void ManagedMode::RegisterUserPrefs(PrefServiceSyncable* prefs) { | 112 void ManagedMode::RegisterUserPrefs(PrefServiceSyncable* prefs) { |
| 113 prefs->RegisterIntegerPref(prefs::kDefaultManagedModeFilteringBehavior, | 113 prefs->RegisterIntegerPref(prefs::kDefaultManagedModeFilteringBehavior, |
| 114 2, | 114 2, |
| 115 PrefServiceSyncable::UNSYNCABLE_PREF); | 115 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 116 prefs->RegisterListPref(prefs::kManagedModeWhitelist, | 116 prefs->RegisterListPref(prefs::kManagedModeWhitelist, |
| 117 PrefServiceSyncable::UNSYNCABLE_PREF); | 117 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 118 prefs->RegisterListPref(prefs::kManagedModeBlacklist, | 118 prefs->RegisterListPref(prefs::kManagedModeBlacklist, |
| 119 PrefServiceSyncable::UNSYNCABLE_PREF); | 119 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 120 prefs->RegisterStringPref(prefs::kManagedModeLocalPassphrase, |
| 121 "", |
| 122 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 123 prefs->RegisterStringPref(prefs::kManagedModeLocalSalt, |
| 124 "", |
| 125 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 120 } | 126 } |
| 121 | 127 |
| 122 // static | 128 // static |
| 123 void ManagedMode::Init(Profile* profile) { | 129 void ManagedMode::Init(Profile* profile) { |
| 124 GetInstance()->InitImpl(profile); | 130 GetInstance()->InitImpl(profile); |
| 125 } | 131 } |
| 126 | 132 |
| 127 void ManagedMode::InitImpl(Profile* profile) { | 133 void ManagedMode::InitImpl(Profile* profile) { |
| 128 DCHECK(g_browser_process); | 134 DCHECK(g_browser_process); |
| 129 DCHECK(g_browser_process->local_state()); | 135 DCHECK(g_browser_process->local_state()); |
| 130 | 136 |
| 131 Profile* original_profile = profile->GetOriginalProfile(); | 137 Profile* original_profile = profile->GetOriginalProfile(); |
| 132 // Set the value directly in the PrefService instead of using | 138 // Set the value directly in the PrefService instead of using |
| 133 // CommandLinePrefStore so we can change it at runtime. | 139 // CommandLinePrefStore so we can change it at runtime. |
| 134 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoManaged)) { | 140 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoManaged)) { |
| 135 SetInManagedMode(NULL); | 141 SetInManagedMode(NULL); |
| 136 } else if (IsInManagedModeImpl() || | 142 } else if (IsInManagedModeImpl() || |
| 137 CommandLine::ForCurrentProcess()->HasSwitch(switches::kManaged)) { | 143 CommandLine::ForCurrentProcess()->HasSwitch(switches::kManaged)) { |
| 138 SetInManagedMode(original_profile); | 144 SetInManagedMode(original_profile); |
| 139 } | 145 } |
| 140 } | 146 } |
| 141 | 147 |
| 142 // static | 148 // static |
| 143 bool ManagedMode::IsInManagedMode() { | 149 bool ManagedMode::IsInManagedMode() { |
| 144 return GetInstance()->IsInManagedModeImpl(); | 150 return GetInstance()->IsInManagedModeImpl(); |
| 145 } | 151 } |
| 146 | 152 |
| 153 // static |
| 154 bool ManagedMode::IsCustodianAuthenticated() { |
| 155 if (GetInstance()->managed_profile_) { |
| 156 PrefService* pref_service = GetInstance()->managed_profile_->GetPrefs(); |
| 157 if (pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty()) |
| 158 return true; |
| 159 } |
| 160 return GetInstance()->is_custodian_authenticated_; |
| 161 } |
| 162 |
| 163 // static |
| 164 void ManagedMode::SetCustodianAuthenticated(bool isAuthenticated) { |
| 165 GetInstance()->is_custodian_authenticated_ = isAuthenticated; |
| 166 } |
| 167 |
| 147 bool ManagedMode::IsInManagedModeImpl() const { | 168 bool ManagedMode::IsInManagedModeImpl() const { |
| 148 // |g_browser_process| can be NULL during startup. | 169 // |g_browser_process| can be NULL during startup. |
| 149 if (!g_browser_process) | 170 if (!g_browser_process) |
| 150 return false; | 171 return false; |
| 151 // Local State can be NULL during unit tests. | 172 // Local State can be NULL during unit tests. |
| 152 if (!g_browser_process->local_state()) | 173 if (!g_browser_process->local_state()) |
| 153 return false; | 174 return false; |
| 154 return g_browser_process->local_state()->GetBoolean(prefs::kInManagedMode); | 175 return g_browser_process->local_state()->GetBoolean(prefs::kInManagedMode); |
| 155 } | 176 } |
| 156 | 177 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 return; | 398 return; |
| 378 } | 399 } |
| 379 size_t count = browsers_to_close_.erase(browser); | 400 size_t count = browsers_to_close_.erase(browser); |
| 380 DCHECK_EQ(1u, count); | 401 DCHECK_EQ(1u, count); |
| 381 if (browsers_to_close_.empty()) | 402 if (browsers_to_close_.empty()) |
| 382 FinalizeEnter(true); | 403 FinalizeEnter(true); |
| 383 } | 404 } |
| 384 | 405 |
| 385 ManagedMode::ManagedMode() | 406 ManagedMode::ManagedMode() |
| 386 : managed_profile_(NULL), | 407 : managed_profile_(NULL), |
| 408 is_custodian_authenticated_(false), |
| 387 io_url_filter_context_( | 409 io_url_filter_context_( |
| 388 new URLFilterContext( | 410 new URLFilterContext( |
| 389 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))), | 411 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))), |
| 390 ui_url_filter_context_( | 412 ui_url_filter_context_( |
| 391 new URLFilterContext( | 413 new URLFilterContext( |
| 392 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))) { | 414 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))) { |
| 393 BrowserList::AddObserver(this); | 415 BrowserList::AddObserver(this); |
| 394 } | 416 } |
| 395 | 417 |
| 396 ManagedMode::~ManagedMode() { | 418 ManagedMode::~ManagedMode() { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 managed_profile_->GetPrefs()->GetList( | 549 managed_profile_->GetPrefs()->GetList( |
| 528 prefs::kManagedModeWhitelist)->DeepCopy()); | 550 prefs::kManagedModeWhitelist)->DeepCopy()); |
| 529 } | 551 } |
| 530 | 552 |
| 531 void ManagedMode::AddURLPatternToManualList( | 553 void ManagedMode::AddURLPatternToManualList( |
| 532 bool is_whitelist, | 554 bool is_whitelist, |
| 533 const std::string& url_pattern) { | 555 const std::string& url_pattern) { |
| 534 io_url_filter_context_->AddURLPatternToManualList(true, url_pattern); | 556 io_url_filter_context_->AddURLPatternToManualList(true, url_pattern); |
| 535 ui_url_filter_context_->AddURLPatternToManualList(true, url_pattern); | 557 ui_url_filter_context_->AddURLPatternToManualList(true, url_pattern); |
| 536 } | 558 } |
| OLD | NEW |