summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/principals_private/principals_private_api.cc
blob: d088403b461b11e44aa0a99f8be1b6fd30922505 (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
// Copyright 2013 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/extensions/api/principals_private/principals_private_api.h"

#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/avatar_menu.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/signin/signin_header_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "components/signin/core/common/profile_management_switches.h"

namespace extensions {

bool PrincipalsPrivateExtensionFunction::RunSync() {
  if (!switches::IsEnableAccountConsistency()) {
    SetError(
        "Need to enable account consistency to use principalsPrivate API.");
    return false;
  }
  return RunSyncSafe();
}

bool PrincipalsPrivateSignOutFunction::RunSyncSafe() {
  Browser* browser = GetCurrentBrowser();
  if (browser) {
    profiles::LockProfile(browser->profile());
  }
  return true;
}

bool PrincipalsPrivateShowAvatarBubbleFunction::RunSyncSafe() {
  Browser* browser = GetCurrentBrowser();
  if (browser) {
    browser->window()->ShowAvatarBubbleFromAvatarButton(
        BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
        signin::ManageAccountsParams());
  }
  return true;
}

}  // namespace extensions