| 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> |
| 10 #include <stdint.h> |
| 9 | 11 |
| 10 #include <map> | 12 #include <map> |
| 11 #include <string> | 13 #include <string> |
| 12 #include <vector> | 14 #include <vector> |
| 13 | 15 |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
| 24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 scoped_ptr<PasswordForm> form(new PasswordForm()); | 128 scoped_ptr<PasswordForm> form(new PasswordForm()); |
| 128 form->origin = GURL(string_attr_map["origin_url"]); | 129 form->origin = GURL(string_attr_map["origin_url"]); |
| 129 form->action = GURL(string_attr_map["action_url"]); | 130 form->action = GURL(string_attr_map["action_url"]); |
| 130 form->username_element = UTF8ToUTF16(string_attr_map["username_element"]); | 131 form->username_element = UTF8ToUTF16(string_attr_map["username_element"]); |
| 131 form->username_value = UTF8ToUTF16(string_attr_map["username_value"]); | 132 form->username_value = UTF8ToUTF16(string_attr_map["username_value"]); |
| 132 form->password_element = UTF8ToUTF16(string_attr_map["password_element"]); | 133 form->password_element = UTF8ToUTF16(string_attr_map["password_element"]); |
| 133 form->submit_element = UTF8ToUTF16(string_attr_map["submit_element"]); | 134 form->submit_element = UTF8ToUTF16(string_attr_map["submit_element"]); |
| 134 form->signon_realm = string_attr_map["signon_realm"]; | 135 form->signon_realm = string_attr_map["signon_realm"]; |
| 135 form->ssl_valid = uint_attr_map["ssl_valid"]; | 136 form->ssl_valid = uint_attr_map["ssl_valid"]; |
| 136 form->preferred = uint_attr_map["preferred"]; | 137 form->preferred = uint_attr_map["preferred"]; |
| 137 int64 date_created = 0; | 138 int64_t date_created = 0; |
| 138 bool date_ok = base::StringToInt64(string_attr_map["date_created"], | 139 bool date_ok = base::StringToInt64(string_attr_map["date_created"], |
| 139 &date_created); | 140 &date_created); |
| 140 DCHECK(date_ok); | 141 DCHECK(date_ok); |
| 141 // In the past |date_created| was stored as time_t. Currently is stored as | 142 // In the past |date_created| was stored as time_t. Currently is stored as |
| 142 // base::Time's internal value. We need to distinguish, which format the | 143 // base::Time's internal value. We need to distinguish, which format the |
| 143 // number in |date_created| was stored in. We use the fact that | 144 // number in |date_created| was stored in. We use the fact that |
| 144 // kMaxPossibleTimeTValue interpreted as the internal value corresponds to an | 145 // kMaxPossibleTimeTValue interpreted as the internal value corresponds to an |
| 145 // unlikely date back in 17th century, and anything above | 146 // unlikely date back in 17th century, and anything above |
| 146 // kMaxPossibleTimeTValue clearly must be in the internal value format. | 147 // kMaxPossibleTimeTValue clearly must be in the internal value format. |
| 147 form->date_created = date_created < kMaxPossibleTimeTValue | 148 form->date_created = date_created < kMaxPossibleTimeTValue |
| 148 ? base::Time::FromTimeT(date_created) | 149 ? base::Time::FromTimeT(date_created) |
| 149 : base::Time::FromInternalValue(date_created); | 150 : base::Time::FromInternalValue(date_created); |
| 150 form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"]; | 151 form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"]; |
| 151 form->type = static_cast<PasswordForm::Type>(uint_attr_map["type"]); | 152 form->type = static_cast<PasswordForm::Type>(uint_attr_map["type"]); |
| 152 form->times_used = uint_attr_map["times_used"]; | 153 form->times_used = uint_attr_map["times_used"]; |
| 153 form->scheme = static_cast<PasswordForm::Scheme>(uint_attr_map["scheme"]); | 154 form->scheme = static_cast<PasswordForm::Scheme>(uint_attr_map["scheme"]); |
| 154 int64 date_synced = 0; | 155 int64_t date_synced = 0; |
| 155 base::StringToInt64(string_attr_map["date_synced"], &date_synced); | 156 base::StringToInt64(string_attr_map["date_synced"], &date_synced); |
| 156 form->date_synced = base::Time::FromInternalValue(date_synced); | 157 form->date_synced = base::Time::FromInternalValue(date_synced); |
| 157 form->display_name = UTF8ToUTF16(string_attr_map["display_name"]); | 158 form->display_name = UTF8ToUTF16(string_attr_map["display_name"]); |
| 158 form->icon_url = GURL(string_attr_map["avatar_url"]); | 159 form->icon_url = GURL(string_attr_map["avatar_url"]); |
| 159 form->federation_url = GURL(string_attr_map["federation_url"]); | 160 form->federation_url = GURL(string_attr_map["federation_url"]); |
| 160 form->skip_zero_click = uint_attr_map["skip_zero_click"]; | 161 form->skip_zero_click = uint_attr_map["skip_zero_click"]; |
| 161 form->generation_upload_status = | 162 form->generation_upload_status = |
| 162 static_cast<PasswordForm::GenerationUploadStatus>( | 163 static_cast<PasswordForm::GenerationUploadStatus>( |
| 163 uint_attr_map["generation_upload_status"]); | 164 uint_attr_map["generation_upload_status"]); |
| 164 if (!string_attr_map["form_data"].empty()) { | 165 if (!string_attr_map["form_data"].empty()) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 // matching is used to find a result, then the results signon realm, origin | 329 // matching is used to find a result, then the results signon realm, origin |
| 329 // and action are stored are replaced by those of |lookup_form_|. | 330 // and action are stored are replaced by those of |lookup_form_|. |
| 330 // Additionally, |lookup_form_->signon_realm| is also used to narrow down the | 331 // Additionally, |lookup_form_->signon_realm| is also used to narrow down the |
| 331 // found logins to those which indeed PSL-match the look-up. And finally, | 332 // found logins to those which indeed PSL-match the look-up. And finally, |
| 332 // |lookup_form_| set to NULL means that PSL matching is not required. | 333 // |lookup_form_| set to NULL means that PSL matching is not required. |
| 333 scoped_ptr<PasswordForm> lookup_form_; | 334 scoped_ptr<PasswordForm> lookup_form_; |
| 334 }; | 335 }; |
| 335 | 336 |
| 336 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { | 337 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { |
| 337 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 338 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 338 int64 date_created = form.date_created.ToInternalValue(); | 339 int64_t date_created = form.date_created.ToInternalValue(); |
| 339 // If we are asked to save a password with 0 date, use the current time. | 340 // If we are asked to save a password with 0 date, use the current time. |
| 340 // We don't want to actually save passwords as though on January 1, 1601. | 341 // We don't want to actually save passwords as though on January 1, 1601. |
| 341 if (!date_created) | 342 if (!date_created) |
| 342 date_created = base::Time::Now().ToInternalValue(); | 343 date_created = base::Time::Now().ToInternalValue(); |
| 343 int64 date_synced = form.date_synced.ToInternalValue(); | 344 int64_t date_synced = form.date_synced.ToInternalValue(); |
| 344 std::string form_data; | 345 std::string form_data; |
| 345 SerializeFormDataToBase64String(form.form_data, &form_data); | 346 SerializeFormDataToBase64String(form.form_data, &form_data); |
| 346 gnome_keyring_store_password( | 347 gnome_keyring_store_password( |
| 347 &kGnomeSchema, | 348 &kGnomeSchema, |
| 348 nullptr, // Default keyring. | 349 nullptr, // Default keyring. |
| 349 form.origin.spec().c_str(), // Display name. | 350 form.origin.spec().c_str(), // Display name. |
| 350 UTF16ToUTF8(form.password_value).c_str(), | 351 UTF16ToUTF8(form.password_value).c_str(), |
| 351 OnOperationDone, | 352 OnOperationDone, |
| 352 this, // data | 353 this, // data |
| 353 nullptr, // destroy_data | 354 nullptr, // destroy_data |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 ScopedVector<PasswordForm> forms; | 802 ScopedVector<PasswordForm> forms; |
| 802 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) | 803 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) |
| 803 return false; | 804 return false; |
| 804 | 805 |
| 805 for (size_t i = 0; i < forms.size(); ++i) { | 806 for (size_t i = 0; i < forms.size(); ++i) { |
| 806 if (!RemoveLogin(*forms[i], changes)) | 807 if (!RemoveLogin(*forms[i], changes)) |
| 807 return false; | 808 return false; |
| 808 } | 809 } |
| 809 return true; | 810 return true; |
| 810 } | 811 } |
| OLD | NEW |