| 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" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 318 |
| 319 // This ScopedAllowWait should not be here. http://crbug.com/125331 | 319 // This ScopedAllowWait should not be here. http://crbug.com/125331 |
| 320 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 320 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 321 event.Wait(); | 321 event.Wait(); |
| 322 return success; | 322 return success; |
| 323 } | 323 } |
| 324 | 324 |
| 325 void NativeBackendKWallet::InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus, | 325 void NativeBackendKWallet::InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus, |
| 326 base::WaitableEvent* event, | 326 base::WaitableEvent* event, |
| 327 bool* success) { | 327 bool* success) { |
| 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 328 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 329 DCHECK(!session_bus_.get()); | 329 DCHECK(!session_bus_.get()); |
| 330 if (optional_bus.get()) { | 330 if (optional_bus.get()) { |
| 331 // The optional_bus parameter is given when this method is called in tests. | 331 // The optional_bus parameter is given when this method is called in tests. |
| 332 session_bus_ = optional_bus; | 332 session_bus_ = optional_bus; |
| 333 } else { | 333 } else { |
| 334 // Get a (real) connection to the session bus. | 334 // Get a (real) connection to the session bus. |
| 335 dbus::Bus::Options options; | 335 dbus::Bus::Options options; |
| 336 options.bus_type = dbus::Bus::SESSION; | 336 options.bus_type = dbus::Bus::SESSION; |
| 337 options.connection_type = dbus::Bus::PRIVATE; | 337 options.connection_type = dbus::Bus::PRIVATE; |
| 338 session_bus_ = new dbus::Bus(options); | 338 session_bus_ = new dbus::Bus(options); |
| 339 } | 339 } |
| 340 kwallet_proxy_ = | 340 kwallet_proxy_ = |
| 341 session_bus_->GetObjectProxy(kKWalletServiceName, | 341 session_bus_->GetObjectProxy(kKWalletServiceName, |
| 342 dbus::ObjectPath(kKWalletPath)); | 342 dbus::ObjectPath(kKWalletPath)); |
| 343 // kwalletd may not be running. If we get a temporary failure initializing it, | 343 // kwalletd may not be running. If we get a temporary failure initializing it, |
| 344 // try to start it and then try again. (Note the short-circuit evaluation.) | 344 // try to start it and then try again. (Note the short-circuit evaluation.) |
| 345 const InitResult result = InitWallet(); | 345 const InitResult result = InitWallet(); |
| 346 *success = (result == INIT_SUCCESS || | 346 *success = (result == INIT_SUCCESS || |
| 347 (result == TEMPORARY_FAIL && | 347 (result == TEMPORARY_FAIL && |
| 348 StartKWalletd() && InitWallet() == INIT_SUCCESS)); | 348 StartKWalletd() && InitWallet() == INIT_SUCCESS)); |
| 349 event->Signal(); | 349 event->Signal(); |
| 350 } | 350 } |
| 351 | 351 |
| 352 bool NativeBackendKWallet::StartKWalletd() { | 352 bool NativeBackendKWallet::StartKWalletd() { |
| 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 353 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 354 // Sadly kwalletd doesn't use DBus activation, so we have to make a call to | 354 // Sadly kwalletd doesn't use DBus activation, so we have to make a call to |
| 355 // klauncher to start it. | 355 // klauncher to start it. |
| 356 dbus::ObjectProxy* klauncher = | 356 dbus::ObjectProxy* klauncher = |
| 357 session_bus_->GetObjectProxy(kKLauncherServiceName, | 357 session_bus_->GetObjectProxy(kKLauncherServiceName, |
| 358 dbus::ObjectPath(kKLauncherPath)); | 358 dbus::ObjectPath(kKLauncherPath)); |
| 359 | 359 |
| 360 dbus::MethodCall method_call(kKLauncherInterface, | 360 dbus::MethodCall method_call(kKLauncherInterface, |
| 361 "start_service_by_desktop_name"); | 361 "start_service_by_desktop_name"); |
| 362 dbus::MessageWriter builder(&method_call); | 362 dbus::MessageWriter builder(&method_call); |
| 363 std::vector<std::string> empty; | 363 std::vector<std::string> empty; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 387 if (!error.empty() || ret) { | 387 if (!error.empty() || ret) { |
| 388 LOG(ERROR) << "Error launching kwalletd: error '" << error << "' " | 388 LOG(ERROR) << "Error launching kwalletd: error '" << error << "' " |
| 389 << " (code " << ret << ")"; | 389 << " (code " << ret << ")"; |
| 390 return false; | 390 return false; |
| 391 } | 391 } |
| 392 | 392 |
| 393 return true; | 393 return true; |
| 394 } | 394 } |
| 395 | 395 |
| 396 NativeBackendKWallet::InitResult NativeBackendKWallet::InitWallet() { | 396 NativeBackendKWallet::InitResult NativeBackendKWallet::InitWallet() { |
| 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 397 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 398 { | 398 { |
| 399 // Check that KWallet is enabled. | 399 // Check that KWallet is enabled. |
| 400 dbus::MethodCall method_call(kKWalletInterface, "isEnabled"); | 400 dbus::MethodCall method_call(kKWalletInterface, "isEnabled"); |
| 401 scoped_ptr<dbus::Response> response( | 401 scoped_ptr<dbus::Response> response( |
| 402 kwallet_proxy_->CallMethodAndBlock( | 402 kwallet_proxy_->CallMethodAndBlock( |
| 403 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | 403 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 404 if (!response.get()) { | 404 if (!response.get()) { |
| 405 LOG(ERROR) << "Error contacting kwalletd (isEnabled)"; | 405 LOG(ERROR) << "Error contacting kwalletd (isEnabled)"; |
| 406 return TEMPORARY_FAIL; | 406 return TEMPORARY_FAIL; |
| 407 } | 407 } |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 // 32-bit machines, in case we're reading a 64-bit pickle. (Probably rare, | 917 // 32-bit machines, in case we're reading a 64-bit pickle. (Probably rare, |
| 918 // since mostly we expect upgrades, not downgrades, but both are possible.) | 918 // since mostly we expect upgrades, not downgrades, but both are possible.) |
| 919 success = DeserializeValueSize( | 919 success = DeserializeValueSize( |
| 920 signon_realm, iter, version, !size_32, false, &forms); | 920 signon_realm, iter, version, !size_32, false, &forms); |
| 921 } | 921 } |
| 922 UMALogDeserializationStatus(success); | 922 UMALogDeserializationStatus(success); |
| 923 return forms.Pass(); | 923 return forms.Pass(); |
| 924 } | 924 } |
| 925 | 925 |
| 926 int NativeBackendKWallet::WalletHandle() { | 926 int NativeBackendKWallet::WalletHandle() { |
| 927 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 927 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 928 | 928 |
| 929 // Open the wallet. | 929 // Open the wallet. |
| 930 // TODO(mdm): Are we leaking these handles? Find out. | 930 // TODO(mdm): Are we leaking these handles? Find out. |
| 931 int32_t handle = kInvalidKWalletHandle; | 931 int32_t handle = kInvalidKWalletHandle; |
| 932 { | 932 { |
| 933 dbus::MethodCall method_call(kKWalletInterface, "open"); | 933 dbus::MethodCall method_call(kKWalletInterface, "open"); |
| 934 dbus::MessageWriter builder(&method_call); | 934 dbus::MessageWriter builder(&method_call); |
| 935 builder.AppendString(wallet_name_); // wallet | 935 builder.AppendString(wallet_name_); // wallet |
| 936 builder.AppendInt64(0); // wid | 936 builder.AppendInt64(0); // wid |
| 937 builder.AppendString(app_name_); // appid | 937 builder.AppendString(app_name_); // appid |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 return handle; | 1007 return handle; |
| 1008 } | 1008 } |
| 1009 | 1009 |
| 1010 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { | 1010 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { |
| 1011 // Originally, the folder name was always just "Chrome Form Data". | 1011 // Originally, the folder name was always just "Chrome Form Data". |
| 1012 // Now we use it to distinguish passwords for different profiles. | 1012 // Now we use it to distinguish passwords for different profiles. |
| 1013 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); | 1013 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); |
| 1014 } | 1014 } |
| OLD | NEW |