OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/password_manager/native_backend_gnome_x.h" | 5 #include "chrome/browser/password_manager/native_backend_gnome_x.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <gnome-keyring.h> | 8 #include <gnome-keyring.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 30 matching lines...) Expand all Loading... |
41 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); | 41 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); |
42 } | 42 } |
43 | 43 |
44 #define GNOME_KEYRING_DEFINE_POINTER(name) \ | 44 #define GNOME_KEYRING_DEFINE_POINTER(name) \ |
45 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; | 45 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; |
46 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) | 46 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) |
47 #undef GNOME_KEYRING_DEFINE_POINTER | 47 #undef GNOME_KEYRING_DEFINE_POINTER |
48 | 48 |
49 bool GnomeKeyringLoader::keyring_loaded = false; | 49 bool GnomeKeyringLoader::keyring_loaded = false; |
50 | 50 |
51 #if defined(DLOPEN_GNOME_KEYRING) | |
52 | |
53 #define GNOME_KEYRING_FUNCTION_INFO(name) \ | 51 #define GNOME_KEYRING_FUNCTION_INFO(name) \ |
54 {"gnome_keyring_"#name, reinterpret_cast<void**>(&gnome_keyring_##name)}, | 52 {"gnome_keyring_"#name, reinterpret_cast<void**>(&gnome_keyring_##name)}, |
55 const GnomeKeyringLoader::FunctionInfo GnomeKeyringLoader::functions[] = { | 53 const GnomeKeyringLoader::FunctionInfo GnomeKeyringLoader::functions[] = { |
56 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_FUNCTION_INFO) | 54 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_FUNCTION_INFO) |
57 {nullptr, nullptr} | 55 {nullptr, nullptr} |
58 }; | 56 }; |
59 #undef GNOME_KEYRING_FUNCTION_INFO | 57 #undef GNOME_KEYRING_FUNCTION_INFO |
60 | 58 |
61 /* Load the library and initialize the function pointers. */ | 59 /* Load the library and initialize the function pointers. */ |
62 bool GnomeKeyringLoader::LoadGnomeKeyring() { | 60 bool GnomeKeyringLoader::LoadGnomeKeyring() { |
(...skipping 19 matching lines...) Expand all Loading... |
82 dlclose(handle); | 80 dlclose(handle); |
83 return false; | 81 return false; |
84 } | 82 } |
85 } | 83 } |
86 | 84 |
87 keyring_loaded = true; | 85 keyring_loaded = true; |
88 // We leak the library handle. That's OK: this function is called only once. | 86 // We leak the library handle. That's OK: this function is called only once. |
89 return true; | 87 return true; |
90 } | 88 } |
91 | 89 |
92 #else // defined(DLOPEN_GNOME_KEYRING) | |
93 | |
94 bool GnomeKeyringLoader::LoadGnomeKeyring() { | |
95 if (keyring_loaded) | |
96 return true; | |
97 #define GNOME_KEYRING_ASSIGN_POINTER(name) \ | |
98 gnome_keyring_##name = &::gnome_keyring_##name; | |
99 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_ASSIGN_POINTER) | |
100 #undef GNOME_KEYRING_ASSIGN_POINTER | |
101 keyring_loaded = true; | |
102 return true; | |
103 } | |
104 | |
105 #endif // defined(DLOPEN_GNOME_KEYRING) | |
106 | |
107 namespace { | 90 namespace { |
108 | 91 |
109 const char kGnomeKeyringAppString[] = "chrome"; | 92 const char kGnomeKeyringAppString[] = "chrome"; |
110 | 93 |
111 // Convert the attributes of a given keyring entry into a new PasswordForm. | 94 // Convert the attributes of a given keyring entry into a new PasswordForm. |
112 // Note: does *not* get the actual password, as that is not a key attribute! | 95 // Note: does *not* get the actual password, as that is not a key attribute! |
113 // Returns NULL if the attributes are for the wrong application. | 96 // Returns NULL if the attributes are for the wrong application. |
114 std::unique_ptr<PasswordForm> FormFromAttributes( | 97 std::unique_ptr<PasswordForm> FormFromAttributes( |
115 GnomeKeyringAttributeList* attrs) { | 98 GnomeKeyringAttributeList* attrs) { |
116 // Read the string and int attributes into the appropriate map. | 99 // Read the string and int attributes into the appropriate map. |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 ScopedVector<PasswordForm> forms; | 823 ScopedVector<PasswordForm> forms; |
841 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) | 824 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) |
842 return false; | 825 return false; |
843 | 826 |
844 for (size_t i = 0; i < forms.size(); ++i) { | 827 for (size_t i = 0; i < forms.size(); ++i) { |
845 if (!RemoveLogin(*forms[i], changes)) | 828 if (!RemoveLogin(*forms[i], changes)) |
846 return false; | 829 return false; |
847 } | 830 } |
848 return true; | 831 return true; |
849 } | 832 } |
OLD | NEW |