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

Side by Side Diff: chrome/browser/password_manager/keyring_proxy/gnome_keyring_loader.cc

Issue 8509038: Linux: split GNOME Keyring integration into a separate process. Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: merge Created 8 years, 11 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/password_manager/keyring_proxy/gnome_keyring_loader.h"
6
7 #include <dlfcn.h>
8 #include <stdio.h>
9
10 namespace keyring_proxy {
11
12 #define GNOME_KEYRING_DEFINE_POINTER(name) \
13 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name;
14 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER)
15 #undef GNOME_KEYRING_DEFINE_POINTER
16
17 bool GnomeKeyringLoader::keyring_loaded = false;
18
19 #if defined(DLOPEN_GNOME_KEYRING)
20
21 #define GNOME_KEYRING_FUNCTION_INFO(name) \
22 {"gnome_keyring_"#name, reinterpret_cast<void**>(&gnome_keyring_##name)},
23 const GnomeKeyringLoader::FunctionInfo GnomeKeyringLoader::functions[] = {
24 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_FUNCTION_INFO)
25 {NULL, NULL}
26 };
27 #undef GNOME_KEYRING_FUNCTION_INFO
28
29 // Load the library and initialize the function pointers.
30 bool GnomeKeyringLoader::LoadGnomeKeyring() {
31 if (keyring_loaded)
32 return true;
33
34 void* handle = dlopen("libgnome-keyring.so.0", RTLD_NOW | RTLD_GLOBAL);
35 if (!handle) {
36 // We wanted to use GNOME Keyring, but we couldn't load it. Warn, because
37 // either the user asked for this, or we autodetected it incorrectly. (Or
38 // the system has broken libraries, which is also good to warn about.)
39 fprintf(stderr, "Could not load libgnome-keyring.so.0: %s\n", dlerror());
40 return false;
41 }
42
43 for (size_t i = 0; functions[i].name; ++i) {
44 dlerror();
45 *functions[i].pointer = dlsym(handle, functions[i].name);
46 const char* error = dlerror();
47 if (error) {
48 fprintf(stderr, "Unable to load symbol %s: %s\n",
49 functions[i].name, error);
50 dlclose(handle);
51 return false;
52 }
53 }
54
55 keyring_loaded = true;
56 // We leak the library handle. That's OK: this function is called only once.
57 return true;
58 }
59
60 #else // defined(DLOPEN_GNOME_KEYRING)
61
62 bool GnomeKeyringLoader::LoadGnomeKeyring() {
63 if (keyring_loaded)
64 return true;
65 #define GNOME_KEYRING_ASSIGN_POINTER(name) \
66 gnome_keyring_##name = &::gnome_keyring_##name;
67 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_ASSIGN_POINTER)
68 #undef GNOME_KEYRING_ASSIGN_POINTER
69 keyring_loaded = true;
70 return true;
71 }
72
73 #endif // defined(DLOPEN_GNOME_KEYRING)
74
75 } // namespace keyring_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698