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

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

Powered by Google App Engine
This is Rietveld 408576698