| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_KWALLET_DBUS_H_ | |
| 6 #define CHROME_BROWSER_PASSWORD_MANAGER_KWALLET_DBUS_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/nix/xdg_util.h" | |
| 14 | |
| 15 namespace dbus { | |
| 16 class Bus; | |
| 17 class ObjectProxy; | |
| 18 } | |
| 19 | |
| 20 // Contains wrappers for dbus invocations related to KWallet. | |
| 21 class KWalletDBus { | |
| 22 public: | |
| 23 // Error code for dbus calls to kwallet. | |
| 24 enum Error { SUCCESS = 0, CANNOT_CONTACT, CANNOT_READ }; | |
| 25 | |
| 26 explicit KWalletDBus(base::nix::DesktopEnvironment desktop_env); | |
| 27 ~KWalletDBus(); | |
| 28 | |
| 29 // Set the bus that we will use. Required before any other operation. | |
| 30 // The owner of KWalletDBus is responsible for killing the bus. | |
| 31 void SetSessionBus(scoped_refptr<dbus::Bus> session_bus); | |
| 32 | |
| 33 // Expose the bus so that shutdown can be scheduled asynchronously. | |
| 34 dbus::Bus* GetSessionBus(); | |
| 35 | |
| 36 // Use KLauncher to start the KWallet service. Returns true if successful. | |
| 37 bool StartKWalletd() WARN_UNUSED_RESULT; | |
| 38 | |
| 39 // The functions below are wrappers for calling the eponymous KWallet dbus | |
| 40 // methods. They take pointers to locations where the return values will be | |
| 41 // written. More KWallet documentation at | |
| 42 // https://api.kde.org/4.12-api/kdelibs-apidocs/kdeui/html/classKWallet_1_1Wal
let.html | |
| 43 | |
| 44 // Determine if the KDE wallet is enabled. | |
| 45 Error IsEnabled(bool* enabled) WARN_UNUSED_RESULT; | |
| 46 | |
| 47 // Get the name of the wallet used to store network passwords. | |
| 48 Error NetworkWallet(std::string* wallet_name_ptr) WARN_UNUSED_RESULT; | |
| 49 | |
| 50 // Open the |wallet_name| wallet for use. | |
| 51 Error Open(const std::string& wallet_name, | |
| 52 const std::string& app_name, | |
| 53 int* handle_ptr) WARN_UNUSED_RESULT; | |
| 54 | |
| 55 // Determine if the current folder has they entry key. | |
| 56 Error HasEntry(int wallet_handle, | |
| 57 const std::string& folder_name, | |
| 58 const std::string& signon_realm, | |
| 59 const std::string& app_name, | |
| 60 bool* has_entry_ptr) WARN_UNUSED_RESULT; | |
| 61 | |
| 62 // Read the entry key from the current folder. | |
| 63 Error ReadEntry(int wallet_handle, | |
| 64 const std::string& folder_name, | |
| 65 const std::string& signon_realm, | |
| 66 const std::string& app_name, | |
| 67 std::vector<uint8_t>* bytes_ptr) WARN_UNUSED_RESULT; | |
| 68 | |
| 69 // Return the list of keys of all entries in this folder. | |
| 70 Error EntryList(int wallet_handle, | |
| 71 const std::string& folder_name, | |
| 72 const std::string& app_name, | |
| 73 std::vector<std::string>* entry_list_ptr) WARN_UNUSED_RESULT; | |
| 74 | |
| 75 // Remove the entry key from the current folder. | |
| 76 // |*return_code_ptr| is 0 on success. | |
| 77 Error RemoveEntry(int wallet_handle, | |
| 78 const std::string& folder_name, | |
| 79 const std::string& signon_realm, | |
| 80 const std::string& app_name, | |
| 81 int* return_code_ptr) WARN_UNUSED_RESULT; | |
| 82 | |
| 83 // Write a binary entry to the current folder. | |
| 84 // |*return_code_ptr| is 0 on success. | |
| 85 Error WriteEntry(int wallet_handle, | |
| 86 const std::string& folder_name, | |
| 87 const std::string& signon_realm, | |
| 88 const std::string& app_name, | |
| 89 const uint8_t* data, | |
| 90 size_t length, | |
| 91 int* return_code_ptr) WARN_UNUSED_RESULT; | |
| 92 | |
| 93 // Determine if the folder |folder_name| exists in the wallet. | |
| 94 Error HasFolder(int handle, | |
| 95 const std::string& folder_name, | |
| 96 const std::string& app_name, | |
| 97 bool* has_folder_ptr) WARN_UNUSED_RESULT; | |
| 98 | |
| 99 // Created the folder |folder_name|. | |
| 100 Error CreateFolder(int handle, | |
| 101 const std::string& folder_name, | |
| 102 const std::string& app_name, | |
| 103 bool* success_ptr) WARN_UNUSED_RESULT; | |
| 104 | |
| 105 private: | |
| 106 // DBus handle for communication with klauncher and kwalletd. | |
| 107 scoped_refptr<dbus::Bus> session_bus_; | |
| 108 // Object proxy for kwalletd. We do not own this. | |
| 109 dbus::ObjectProxy* kwallet_proxy_; | |
| 110 | |
| 111 // KWallet DBus name. | |
| 112 std::string dbus_service_name_; | |
| 113 // DBus path to KWallet interfaces. | |
| 114 std::string dbus_path_; | |
| 115 // The name used for logging and by klauncher when starting KWallet. | |
| 116 std::string kwalletd_name_; | |
| 117 | |
| 118 DISALLOW_COPY_AND_ASSIGN(KWalletDBus); | |
| 119 }; | |
| 120 | |
| 121 #endif // CHROME_BROWSER_PASSWORD_MANAGER_KWALLET_DBUS_H_ | |
| OLD | NEW |