File: keyring_util_linux.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (76 lines) | stat: -rw-r--r-- 3,176 bytes parent folder | download | duplicates (2)
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
// Copyright 2016 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.

#ifndef COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_
#define COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_

// libgnome-keyring has been deprecated in favor of libsecret.
// See: https://mail.gnome.org/archives/commits-list/2013-October/msg08876.html
//
// The define below turns off the deprecations, in order to avoid build
// failures with Gnome 3.12. When we move to libsecret, the define can be
// removed, together with the include below it.
//
// The porting is tracked in http://crbug.com/355223
#define GNOME_KEYRING_DEPRECATED
#define GNOME_KEYRING_DEPRECATED_FOR(x)
#include <gnome-keyring.h>

#include "base/macros.h"

// Many of the gnome_keyring_* functions use variable arguments, which makes
// them difficult if not impossible to truly wrap in C. Therefore, we use
// appropriately-typed function pointers and scoping to make the fact that we
// might be dynamically loading the library almost invisible. As a bonus, we
// also get a simple way to mock the library for testing. Classes that inherit
// from GnomeKeyringLoader will use its versions of the gnome_keyring_*
// functions. Note that it has only static fields.
class GnomeKeyringLoader {
 public:
  static bool LoadGnomeKeyring();

  // Declare the actual function pointers that we'll use in client code.
  // These functions will contact the service.
  static decltype(&::gnome_keyring_is_available) gnome_keyring_is_available_ptr;
  static decltype(
      &::gnome_keyring_store_password) gnome_keyring_store_password_ptr;
  static decltype(
      &::gnome_keyring_delete_password) gnome_keyring_delete_password_ptr;
  static decltype(&::gnome_keyring_find_items) gnome_keyring_find_items_ptr;
  static decltype(
      &::gnome_keyring_find_password_sync) gnome_keyring_find_password_sync_ptr;
  static decltype(&::gnome_keyring_store_password_sync)
      gnome_keyring_store_password_sync_ptr;

  // These functions do not contact the service.
  static decltype(
      &::gnome_keyring_result_to_message) gnome_keyring_result_to_message_ptr;
  static decltype(&::gnome_keyring_attribute_list_free)
      gnome_keyring_attribute_list_free_ptr;
  static decltype(
      &::gnome_keyring_attribute_list_new) gnome_keyring_attribute_list_new_ptr;
  static decltype(&::gnome_keyring_attribute_list_append_string)
      gnome_keyring_attribute_list_append_string_ptr;
  static decltype(&::gnome_keyring_attribute_list_append_uint32)
      gnome_keyring_attribute_list_append_uint32_ptr;
  static decltype(
      &::gnome_keyring_free_password) gnome_keyring_free_password_ptr;
  // We also use gnome_keyring_attribute_list_index(), which is a macro and
  // can't be referenced.

 protected:
  // Set to true if LoadGnomeKeyring() has already succeeded.
  static bool keyring_loaded;

 private:
  struct FunctionInfo {
    const char* name;
    void** pointer;
  };

  // Make it easy to initialize the function pointers in LoadGnomeKeyring().
  static const FunctionInfo functions[];
};

#endif  // COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_