principals_private_api.cc revision f2477e01787aa58f445919b809d89e252beef54f
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/extensions/api/principals_private/principals_private_api.h"
6
7#include "chrome/browser/browser_process.h"
8#include "chrome/browser/profiles/avatar_menu.h"
9#include "chrome/browser/profiles/profile_window.h"
10#include "chrome/browser/profiles/profiles_state.h"
11#include "chrome/browser/ui/browser.h"
12#include "chrome/browser/ui/browser_window.h"
13
14namespace extensions {
15
16bool PrincipalsPrivateExtensionFunction::RunImpl() {
17  if (!profiles::IsNewProfileManagementEnabled()) {
18    SetError(
19        "Need to enable new-profile-management to use principalsPrivate API.");
20    return false;
21  }
22  return RunImplSafe();
23}
24
25bool PrincipalsPrivateSignOutFunction::RunImplSafe() {
26  Browser* browser = GetCurrentBrowser();
27  if (browser) {
28    profiles::LockProfile(browser->profile());
29  }
30  return true;
31}
32
33bool PrincipalsPrivateShowAvatarBubbleFunction::RunImplSafe() {
34  Browser* browser = GetCurrentBrowser();
35  if (browser)
36    browser->window()->ShowAvatarBubbleFromAvatarButton();
37  return true;
38}
39
40}  // namespace extensions
41