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> |
11 | 11 |
| 12 #include <limits> |
12 #include <map> | 13 #include <map> |
13 #include <memory> | 14 #include <memory> |
14 #include <string> | 15 #include <string> |
15 #include <utility> | 16 #include <utility> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
(...skipping 19 matching lines...) Expand all Loading... |
41 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); | 42 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); |
42 } | 43 } |
43 | 44 |
44 #define GNOME_KEYRING_DEFINE_POINTER(name) \ | 45 #define GNOME_KEYRING_DEFINE_POINTER(name) \ |
45 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; | 46 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; |
46 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) | 47 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) |
47 #undef GNOME_KEYRING_DEFINE_POINTER | 48 #undef GNOME_KEYRING_DEFINE_POINTER |
48 | 49 |
49 bool GnomeKeyringLoader::keyring_loaded = false; | 50 bool GnomeKeyringLoader::keyring_loaded = false; |
50 | 51 |
51 #if defined(DLOPEN_GNOME_KEYRING) | |
52 | |
53 #define GNOME_KEYRING_FUNCTION_INFO(name) \ | 52 #define GNOME_KEYRING_FUNCTION_INFO(name) \ |
54 {"gnome_keyring_"#name, reinterpret_cast<void**>(&gnome_keyring_##name)}, | 53 {"gnome_keyring_"#name, reinterpret_cast<void**>(&gnome_keyring_##name)}, |
55 const GnomeKeyringLoader::FunctionInfo GnomeKeyringLoader::functions[] = { | 54 const GnomeKeyringLoader::FunctionInfo GnomeKeyringLoader::functions[] = { |
56 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_FUNCTION_INFO) | 55 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_FUNCTION_INFO) |
57 {nullptr, nullptr} | 56 {nullptr, nullptr} |
58 }; | 57 }; |
59 #undef GNOME_KEYRING_FUNCTION_INFO | 58 #undef GNOME_KEYRING_FUNCTION_INFO |
60 | 59 |
61 /* Load the library and initialize the function pointers. */ | 60 /* Load the library and initialize the function pointers. */ |
62 bool GnomeKeyringLoader::LoadGnomeKeyring() { | 61 bool GnomeKeyringLoader::LoadGnomeKeyring() { |
(...skipping 19 matching lines...) Expand all Loading... |
82 dlclose(handle); | 81 dlclose(handle); |
83 return false; | 82 return false; |
84 } | 83 } |
85 } | 84 } |
86 | 85 |
87 keyring_loaded = true; | 86 keyring_loaded = true; |
88 // We leak the library handle. That's OK: this function is called only once. | 87 // We leak the library handle. That's OK: this function is called only once. |
89 return true; | 88 return true; |
90 } | 89 } |
91 | 90 |
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 { | 91 namespace { |
108 | 92 |
109 const char kGnomeKeyringAppString[] = "chrome"; | 93 const char kGnomeKeyringAppString[] = "chrome"; |
110 | 94 |
111 // Convert the attributes of a given keyring entry into a new PasswordForm. | 95 // 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! | 96 // 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. | 97 // Returns NULL if the attributes are for the wrong application. |
114 std::unique_ptr<PasswordForm> FormFromAttributes( | 98 std::unique_ptr<PasswordForm> FormFromAttributes( |
115 GnomeKeyringAttributeList* attrs) { | 99 GnomeKeyringAttributeList* attrs) { |
116 // Read the string and int attributes into the appropriate map. | 100 // 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; | 824 ScopedVector<PasswordForm> forms; |
841 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) | 825 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) |
842 return false; | 826 return false; |
843 | 827 |
844 for (size_t i = 0; i < forms.size(); ++i) { | 828 for (size_t i = 0; i < forms.size(); ++i) { |
845 if (!RemoveLogin(*forms[i], changes)) | 829 if (!RemoveLogin(*forms[i], changes)) |
846 return false; | 830 return false; |
847 } | 831 } |
848 return true; | 832 return true; |
849 } | 833 } |
OLD | NEW |