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

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

Issue 10692158: Refactor URLBlacklistManager to use URLMatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 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) 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.h" 5 #include "chrome/browser/managed_mode.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_system.h" 9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/managed_mode_url_filter.h"
10 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
13 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" 14 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/browser_thread.h"
Joao da Silva 2012/07/13 12:32:11 Nit: order
Bernhard Bauer 2012/07/13 14:21:07 Done.
20 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
22 24
25 using content::BrowserThread;
26
27 // A bridge from ManagedMode (which lives on the UI thread) to
28 // ManagedModeURLFilter (which lives on the IO thread).
29 class ManagedMode::URLFilterContext {
30 public:
31 URLFilterContext() {}
32 ~URLFilterContext() {}
33
34 const ManagedModeURLFilter* url_filter() const {
35 return &url_filter_;
36 }
37
38 void SetActive(bool in_managed_mode) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 // Because ManagedMode is a singleton, we can pass the pointer to
41 // |url_filter_| unretained.
Joao da Silva 2012/07/13 12:32:11 What do you think of this pattern instead: - Mana
Bernhard Bauer 2012/07/13 14:21:07 Yup; see the comment below.
42 BrowserThread::PostTask(BrowserThread::IO,
43 FROM_HERE,
44 base::Bind(
45 &ManagedModeURLFilter::SetActive,
46 base::Unretained(&url_filter_),
47 in_managed_mode));
48 }
49
50 void SetWhitelist(scoped_ptr<base::ListValue> whitelist) {
Joao da Silva 2012/07/13 12:32:11 Is this used?
Bernhard Bauer 2012/07/13 14:21:07 Not yet, but it will be once I have the source of
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
52 BrowserThread::PostTask(BrowserThread::IO,
53 FROM_HERE,
54 base::Bind(
55 &ManagedModeURLFilter::SetWhitelist,
56 base::Unretained(&url_filter_),
57 base::Passed(&whitelist),
58 base::Closure()));
59 }
60
61 private:
62 ManagedModeURLFilter url_filter_;
63
64 DISALLOW_COPY_AND_ASSIGN(URLFilterContext);
65 };
66
23 // static 67 // static
24 ManagedMode* ManagedMode::GetInstance() { 68 ManagedMode* ManagedMode::GetInstance() {
25 return Singleton<ManagedMode>::get(); 69 return Singleton<ManagedMode, LeakySingletonTraits<ManagedMode> >::get();
26 } 70 }
27 71
28 // static 72 // static
29 void ManagedMode::RegisterPrefs(PrefService* prefs) { 73 void ManagedMode::RegisterPrefs(PrefService* prefs) {
30 prefs->RegisterBooleanPref(prefs::kInManagedMode, false); 74 prefs->RegisterBooleanPref(prefs::kInManagedMode, false);
31 } 75 }
32 76
33 // static 77 // static
34 void ManagedMode::Init(Profile* profile) { 78 void ManagedMode::Init(Profile* profile) {
35 GetInstance()->InitImpl(profile); 79 GetInstance()->InitImpl(profile);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 void ManagedMode::LeaveManagedMode() { 169 void ManagedMode::LeaveManagedMode() {
126 GetInstance()->LeaveManagedModeImpl(); 170 GetInstance()->LeaveManagedModeImpl();
127 } 171 }
128 172
129 void ManagedMode::LeaveManagedModeImpl() { 173 void ManagedMode::LeaveManagedModeImpl() {
130 bool confirmed = PlatformConfirmLeave(); 174 bool confirmed = PlatformConfirmLeave();
131 if (confirmed) 175 if (confirmed)
132 SetInManagedMode(NULL); 176 SetInManagedMode(NULL);
133 } 177 }
134 178
179 const ManagedModeURLFilter* ManagedMode::GetURLFilter() {
battre 2012/07/13 14:10:53 nit: // static
Bernhard Bauer 2012/07/13 14:21:07 Done.
180 return GetInstance()->GetURLFilterImpl();
181 }
182
183 const ManagedModeURLFilter* ManagedMode::GetURLFilterImpl() {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
185 if (!url_filter_context_.get())
186 url_filter_context_.reset(new URLFilterContext);
187
188 return url_filter_context_->url_filter();
189 }
190
135 std::string ManagedMode::GetDebugPolicyProviderName() const { 191 std::string ManagedMode::GetDebugPolicyProviderName() const {
136 // Save the string space in official builds. 192 // Save the string space in official builds.
137 #ifdef NDEBUG 193 #ifdef NDEBUG
138 NOTREACHED(); 194 NOTREACHED();
139 return std::string(); 195 return std::string();
140 #else 196 #else
141 return "Managed Mode"; 197 return "Managed Mode";
142 #endif 198 #endif
143 } 199 }
144 200
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 DCHECK_EQ(1u, count); 241 DCHECK_EQ(1u, count);
186 if (browsers_to_close_.empty()) 242 if (browsers_to_close_.empty())
187 FinalizeEnter(true); 243 FinalizeEnter(true);
188 } 244 }
189 245
190 ManagedMode::ManagedMode() : managed_profile_(NULL) { 246 ManagedMode::ManagedMode() : managed_profile_(NULL) {
191 BrowserList::AddObserver(this); 247 BrowserList::AddObserver(this);
192 } 248 }
193 249
194 ManagedMode::~ManagedMode() { 250 ManagedMode::~ManagedMode() {
251 // This class usually is a leaky singleton, so this destructor shouldn't be
252 // called. We still do some cleanup, in case we're owned by a unit test.
195 BrowserList::RemoveObserver(this); 253 BrowserList::RemoveObserver(this);
196 DCHECK_EQ(0u, callbacks_.size()); 254 DCHECK_EQ(0u, callbacks_.size());
197 DCHECK_EQ(0u, browsers_to_close_.size()); 255 DCHECK_EQ(0u, browsers_to_close_.size());
198 } 256 }
199 257
200 void ManagedMode::Observe(int type, 258 void ManagedMode::Observe(int type,
201 const content::NotificationSource& source, 259 const content::NotificationSource& source,
202 const content::NotificationDetails& details) { 260 const content::NotificationDetails& details) {
203 // Return early if we don't have any queued callbacks. 261 // Return early if we don't have any queued callbacks.
204 if (callbacks_.empty()) 262 if (callbacks_.empty())
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 299
242 bool ManagedMode::PlatformConfirmLeave() { 300 bool ManagedMode::PlatformConfirmLeave() {
243 // TODO(bauerb): Show platform-specific confirmation dialog. 301 // TODO(bauerb): Show platform-specific confirmation dialog.
244 return true; 302 return true;
245 } 303 }
246 304
247 void ManagedMode::SetInManagedMode(Profile* newly_managed_profile) { 305 void ManagedMode::SetInManagedMode(Profile* newly_managed_profile) {
248 // Register the ManagementPolicy::Provider before changing the pref when 306 // Register the ManagementPolicy::Provider before changing the pref when
249 // setting it, and unregister it after changing the pref when clearing it, 307 // setting it, and unregister it after changing the pref when clearing it,
250 // so pref observers see the correct ManagedMode state. 308 // so pref observers see the correct ManagedMode state.
251 if (newly_managed_profile) { 309 bool in_managed_mode = !!newly_managed_profile;
310 if (in_managed_mode) {
252 DCHECK(!managed_profile_ || managed_profile_ == newly_managed_profile); 311 DCHECK(!managed_profile_ || managed_profile_ == newly_managed_profile);
253 extensions::ExtensionSystem::Get( 312 extensions::ExtensionSystem::Get(
254 newly_managed_profile)->management_policy()->RegisterProvider(this); 313 newly_managed_profile)->management_policy()->RegisterProvider(this);
255 g_browser_process->local_state()->SetBoolean(prefs::kInManagedMode, true);
256 } else { 314 } else {
257 extensions::ExtensionSystem::Get( 315 extensions::ExtensionSystem::Get(
258 managed_profile_)->management_policy()->UnregisterProvider(this); 316 managed_profile_)->management_policy()->UnregisterProvider(this);
259 g_browser_process->local_state()->SetBoolean(prefs::kInManagedMode, false);
260 } 317 }
318
319 url_filter_context_->SetActive(in_managed_mode);
Joao da Silva 2012/07/13 12:32:11 Is this guaranteed to be non-NULL at this stage?
Bernhard Bauer 2012/07/13 14:21:07 Hm, good point. I probably do need to set up every
320 g_browser_process->local_state()->SetBoolean(prefs::kInManagedMode,
321 in_managed_mode);
261 managed_profile_ = newly_managed_profile; 322 managed_profile_ = newly_managed_profile;
262 323
263 // This causes the avatar and the profile menu to get updated. 324 // This causes the avatar and the profile menu to get updated.
264 content::NotificationService::current()->Notify( 325 content::NotificationService::current()->Notify(
265 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 326 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
266 content::NotificationService::AllBrowserContextsAndSources(), 327 content::NotificationService::AllBrowserContextsAndSources(),
267 content::NotificationService::NoDetails()); 328 content::NotificationService::NoDetails());
268 } 329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698