blob: cef0d9e783acd225d5a4a8b5db43caedf33d921f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/managed_mode.h"
#include "base/command_line.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_service.h"
// static
void ManagedMode::RegisterPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kInManagedMode, false);
// Set the value directly in the PrefService instead of using
// CommandLinePrefStore so we can change it at runtime.
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kManaged))
SetInManagedMode(true);
}
// static
bool ManagedMode::IsInManagedMode() {
// |g_browser_process| can be NULL during startup.
if (!g_browser_process)
return false;
return g_browser_process->local_state()->GetBoolean(prefs::kInManagedMode);
}
// static
bool ManagedMode::EnterManagedMode(Profile* profile) {
bool confirmed = PlatformConfirmEnter();
if (confirmed) {
// Close all other profiles.
// TODO(bauerb): This may not close all windows, for example if there is an
// onbeforeunload handler. We should cancel entering managed mode in that
// case.
std::vector<Profile*> profiles =
g_browser_process->profile_manager()->GetLoadedProfiles();
for (std::vector<Profile*>::iterator it = profiles.begin();
it != profiles.end(); ++it) {
if (*it != profile)
BrowserList::CloseAllBrowsersWithProfile(*it);
}
SetInManagedMode(true);
}
return confirmed;
}
// static
void ManagedMode::LeaveManagedMode() {
bool confirmed = PlatformConfirmLeave();
if (confirmed)
SetInManagedMode(false);
}
// static
bool ManagedMode::PlatformConfirmEnter() {
// TODO(bauerb): Show platform-specific confirmation dialog.
return true;
}
// static
bool ManagedMode::PlatformConfirmLeave() {
// TODO(bauerb): Show platform-specific confirmation dialog.
return true;
}
// static
void ManagedMode::SetInManagedMode(bool in_managed_mode) {
g_browser_process->local_state()->SetBoolean(prefs::kInManagedMode,
in_managed_mode);
// This causes the avatar and the profile menu to get updated.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
content::NotificationService::AllBrowserContextsAndSources(),
content::NotificationService::NoDetails());
}
|