Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / password_manager / native_backend_gnome_x.h
blob925eb09c6de6261ffb74b97be8f0525a30673f2a
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_
8 #include <gnome-keyring.h>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/password_manager/password_store_factory.h"
15 #include "chrome/browser/password_manager/password_store_x.h"
16 #include "chrome/browser/profiles/profile.h"
18 namespace autofill {
19 struct PasswordForm;
22 // Many of the gnome_keyring_* functions use variable arguments, which makes
23 // them difficult if not impossible to truly wrap in C. Therefore, we use
24 // appropriately-typed function pointers and scoping to make the fact that we
25 // might be dynamically loading the library almost invisible. As a bonus, we
26 // also get a simple way to mock the library for testing. Classes that inherit
27 // from GnomeKeyringLoader will use its versions of the gnome_keyring_*
28 // functions. Note that it has only static fields.
29 class GnomeKeyringLoader {
30 protected:
31 static bool LoadGnomeKeyring();
33 // Call a given parameter with the name of each function we use from GNOME
34 // Keyring. Make sure to adjust the unit test if you change these.
35 // The list of functions is divided into those we plan to mock in the unittest,
36 // and those which we use without mocking in the test.
37 #define GNOME_KEYRING_FOR_EACH_MOCKED_FUNC(F) \
38 F(is_available) \
39 F(store_password) \
40 F(delete_password) \
41 F(find_items) \
42 F(result_to_message)
43 #define GNOME_KEYRING_FOR_EACH_NON_MOCKED_FUNC(F) \
44 F(attribute_list_free) \
45 F(attribute_list_new) \
46 F(attribute_list_append_string) \
47 F(attribute_list_append_uint32)
48 #define GNOME_KEYRING_FOR_EACH_FUNC(F) \
49 GNOME_KEYRING_FOR_EACH_NON_MOCKED_FUNC(F) \
50 GNOME_KEYRING_FOR_EACH_MOCKED_FUNC(F)
52 // Declare the actual function pointers that we'll use in client code.
53 #define GNOME_KEYRING_DECLARE_POINTER(name) \
54 static typeof(&::gnome_keyring_##name) gnome_keyring_##name;
55 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DECLARE_POINTER)
56 #undef GNOME_KEYRING_DECLARE_POINTER
58 // Set to true if LoadGnomeKeyring() has already succeeded.
59 static bool keyring_loaded;
61 private:
62 #if defined(DLOPEN_GNOME_KEYRING)
63 struct FunctionInfo {
64 const char* name;
65 void** pointer;
68 // Make it easy to initialize the function pointers in LoadGnomeKeyring().
69 static const FunctionInfo functions[];
70 #endif // defined(DLOPEN_GNOME_KEYRING)
73 // NativeBackend implementation using GNOME Keyring.
74 class NativeBackendGnome : public PasswordStoreX::NativeBackend,
75 public GnomeKeyringLoader {
76 public:
77 explicit NativeBackendGnome(LocalProfileId id);
79 virtual ~NativeBackendGnome();
81 virtual bool Init() OVERRIDE;
83 // Implements NativeBackend interface.
84 virtual bool AddLogin(const autofill::PasswordForm& form) OVERRIDE;
85 virtual bool UpdateLogin(const autofill::PasswordForm& form) OVERRIDE;
86 virtual bool RemoveLogin(const autofill::PasswordForm& form) OVERRIDE;
87 virtual bool RemoveLoginsCreatedBetween(
88 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE;
89 virtual bool GetLogins(const autofill::PasswordForm& form,
90 PasswordFormList* forms) OVERRIDE;
91 virtual bool GetLoginsCreatedBetween(const base::Time& get_begin,
92 const base::Time& get_end,
93 PasswordFormList* forms) OVERRIDE;
94 virtual bool GetAutofillableLogins(PasswordFormList* forms) OVERRIDE;
95 virtual bool GetBlacklistLogins(PasswordFormList* forms) OVERRIDE;
97 private:
98 // Adds a login form without checking for one to replace first.
99 bool RawAddLogin(const autofill::PasswordForm& form);
101 // Reads PasswordForms from the keyring with the given autofillability state.
102 bool GetLoginsList(PasswordFormList* forms, bool autofillable);
104 // Helper for GetLoginsCreatedBetween().
105 bool GetAllLogins(PasswordFormList* forms);
107 // Generates a profile-specific app string based on profile_id_.
108 std::string GetProfileSpecificAppString() const;
110 // The local profile id, used to generate the app string.
111 const LocalProfileId profile_id_;
113 // The app string, possibly based on the local profile id.
114 std::string app_string_;
116 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome);
119 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_