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_kwallet_x.h" | 5 #include "chrome/browser/password_manager/native_backend_kwallet_x.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
17 #include "dbus/message.h" | 17 #include "dbus/message.h" |
18 #include "dbus/object_path.h" | |
19 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
20 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
21 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
22 | 21 |
23 using content::BrowserThread; | 22 using content::BrowserThread; |
24 using webkit::forms::PasswordForm; | 23 using webkit::forms::PasswordForm; |
25 | 24 |
26 // We could localize this string, but then changing your locale would cause | 25 // We could localize this string, but then changing your locale would cause |
27 // you to lose access to all your stored passwords. Maybe best not to do that. | 26 // you to lose access to all your stored passwords. Maybe best not to do that. |
28 const char NativeBackendKWallet::kKWalletFolder[] = "Chrome Form Data"; | 27 const char NativeBackendKWallet::kKWalletFolder[] = "Chrome Form Data"; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // The optional_bus parameter is given when this method is called in tests. | 96 // The optional_bus parameter is given when this method is called in tests. |
98 session_bus_ = optional_bus; | 97 session_bus_ = optional_bus; |
99 } else { | 98 } else { |
100 // Get a (real) connection to the session bus. | 99 // Get a (real) connection to the session bus. |
101 dbus::Bus::Options options; | 100 dbus::Bus::Options options; |
102 options.bus_type = dbus::Bus::SESSION; | 101 options.bus_type = dbus::Bus::SESSION; |
103 options.connection_type = dbus::Bus::PRIVATE; | 102 options.connection_type = dbus::Bus::PRIVATE; |
104 session_bus_ = new dbus::Bus(options); | 103 session_bus_ = new dbus::Bus(options); |
105 } | 104 } |
106 kwallet_proxy_ = | 105 kwallet_proxy_ = |
107 session_bus_->GetObjectProxy(kKWalletServiceName, | 106 session_bus_->GetObjectProxy(kKWalletServiceName, kKWalletPath); |
108 dbus::ObjectPath(kKWalletPath)); | |
109 // kwalletd may not be running. If we get a temporary failure initializing it, | 107 // kwalletd may not be running. If we get a temporary failure initializing it, |
110 // try to start it and then try again. (Note the short-circuit evaluation.) | 108 // try to start it and then try again. (Note the short-circuit evaluation.) |
111 const InitResult result = InitWallet(); | 109 const InitResult result = InitWallet(); |
112 *success = (result == INIT_SUCCESS || | 110 *success = (result == INIT_SUCCESS || |
113 (result == TEMPORARY_FAIL && | 111 (result == TEMPORARY_FAIL && |
114 StartKWalletd() && InitWallet() == INIT_SUCCESS)); | 112 StartKWalletd() && InitWallet() == INIT_SUCCESS)); |
115 event->Signal(); | 113 event->Signal(); |
116 } | 114 } |
117 | 115 |
118 bool NativeBackendKWallet::StartKWalletd() { | 116 bool NativeBackendKWallet::StartKWalletd() { |
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
120 // Sadly kwalletd doesn't use DBus activation, so we have to make a call to | 118 // Sadly kwalletd doesn't use DBus activation, so we have to make a call to |
121 // klauncher to start it. | 119 // klauncher to start it. |
122 dbus::ObjectProxy* klauncher = | 120 dbus::ObjectProxy* klauncher = |
123 session_bus_->GetObjectProxy(kKLauncherServiceName, | 121 session_bus_->GetObjectProxy(kKLauncherServiceName, kKLauncherPath); |
124 dbus::ObjectPath(kKLauncherPath)); | |
125 | 122 |
126 dbus::MethodCall method_call(kKLauncherInterface, | 123 dbus::MethodCall method_call(kKLauncherInterface, |
127 "start_service_by_desktop_name"); | 124 "start_service_by_desktop_name"); |
128 dbus::MessageWriter builder(&method_call); | 125 dbus::MessageWriter builder(&method_call); |
129 std::vector<std::string> empty; | 126 std::vector<std::string> empty; |
130 builder.AppendString("kwalletd"); // serviceName | 127 builder.AppendString("kwalletd"); // serviceName |
131 builder.AppendArrayOfStrings(empty); // urls | 128 builder.AppendArrayOfStrings(empty); // urls |
132 builder.AppendArrayOfStrings(empty); // envs | 129 builder.AppendArrayOfStrings(empty); // envs |
133 builder.AppendString(""); // startup_id | 130 builder.AppendString(""); // startup_id |
134 builder.AppendBool(false); // blind | 131 builder.AppendBool(false); // blind |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 // Each other profile must be able to migrate the shared data as well, | 890 // Each other profile must be able to migrate the shared data as well, |
894 // so we must leave it alone. After a few releases, we'll add code to | 891 // so we must leave it alone. After a few releases, we'll add code to |
895 // delete them, and eventually remove this migration code. | 892 // delete them, and eventually remove this migration code. |
896 // TODO(mdm): follow through with the plan above. | 893 // TODO(mdm): follow through with the plan above. |
897 PasswordStoreX::SetPasswordsUseLocalProfileId(prefs_); | 894 PasswordStoreX::SetPasswordsUseLocalProfileId(prefs_); |
898 } else { | 895 } else { |
899 // We failed to migrate for some reason. Use the old folder name. | 896 // We failed to migrate for some reason. Use the old folder name. |
900 folder_name_ = kKWalletFolder; | 897 folder_name_ = kKWalletFolder; |
901 } | 898 } |
902 } | 899 } |
OLD | NEW |