Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/password_manager/native_backend_libsecret.cc

Issue 891463002: Fill empty fields from keyring result with default values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/password_manager/native_backend_libsecret_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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_libsecret.h" 5 #include "chrome/browser/password_manager/native_backend_libsecret.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <list> 8 #include <list>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 17
18 using autofill::PasswordForm; 18 using autofill::PasswordForm;
19 using base::UTF8ToUTF16; 19 using base::UTF8ToUTF16;
20 using base::UTF16ToUTF8; 20 using base::UTF16ToUTF8;
21 21
22 namespace {
23 const char kEmptyString[] = "";
24 }
25
22 typeof(&::secret_password_store_sync) 26 typeof(&::secret_password_store_sync)
23 LibsecretLoader::secret_password_store_sync; 27 LibsecretLoader::secret_password_store_sync;
24 typeof(&::secret_service_search_sync) 28 typeof(&::secret_service_search_sync)
25 LibsecretLoader::secret_service_search_sync; 29 LibsecretLoader::secret_service_search_sync;
26 typeof(&::secret_password_clear_sync) 30 typeof(&::secret_password_clear_sync)
27 LibsecretLoader::secret_password_clear_sync; 31 LibsecretLoader::secret_password_clear_sync;
28 typeof(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; 32 typeof(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret;
29 typeof(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; 33 typeof(&::secret_value_get_text) LibsecretLoader::secret_value_get_text;
30 typeof(&::secret_item_get_attributes) 34 typeof(&::secret_item_get_attributes)
31 LibsecretLoader::secret_item_get_attributes; 35 LibsecretLoader::secret_item_get_attributes;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 {"times_used", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, 116 {"times_used", SECRET_SCHEMA_ATTRIBUTE_INTEGER},
113 {"date_synced", SECRET_SCHEMA_ATTRIBUTE_STRING}, 117 {"date_synced", SECRET_SCHEMA_ATTRIBUTE_STRING},
114 {"display_name", SECRET_SCHEMA_ATTRIBUTE_STRING}, 118 {"display_name", SECRET_SCHEMA_ATTRIBUTE_STRING},
115 {"avatar_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, 119 {"avatar_url", SECRET_SCHEMA_ATTRIBUTE_STRING},
116 {"federation_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, 120 {"federation_url", SECRET_SCHEMA_ATTRIBUTE_STRING},
117 {"is_zero_click", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, 121 {"is_zero_click", SECRET_SCHEMA_ATTRIBUTE_INTEGER},
118 // This field is always "chrome-profile_id" so that we can search for it. 122 // This field is always "chrome-profile_id" so that we can search for it.
119 {"application", SECRET_SCHEMA_ATTRIBUTE_STRING}, 123 {"application", SECRET_SCHEMA_ATTRIBUTE_STRING},
120 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}}; 124 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}};
121 125
122 char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) { 126 const char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) {
123 return static_cast<char*>(g_hash_table_lookup(attrs, keyname)); 127 gpointer value = g_hash_table_lookup(attrs, keyname);
128 return value ? static_cast<char*>(value) : kEmptyString;
124 } 129 }
125 130
126 uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) { 131 uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) {
127 char* value = static_cast<char*>(g_hash_table_lookup(attrs, keyname)); 132 gpointer value = g_hash_table_lookup(attrs, keyname);
133 if (!value)
134 return uint32_t();
128 uint32_t result; 135 uint32_t result;
129 bool value_ok = base::StringToUint(value, &result); 136 bool value_ok = base::StringToUint(static_cast<char*>(value), &result);
130 DCHECK(value_ok); 137 DCHECK(value_ok);
131 return result; 138 return result;
132 } 139 }
133 140
134 // Convert the attributes into a new PasswordForm. 141 // Convert the attributes into a new PasswordForm.
135 // Note: does *not* get the actual password, as that is not a key attribute! 142 // Note: does *not* get the actual password, as that is not a key attribute!
136 // Returns nullptr if the attributes are for the wrong application. 143 // Returns nullptr if the attributes are for the wrong application.
137 scoped_ptr<PasswordForm> FormOutOfAttributes(GHashTable* attrs) { 144 scoped_ptr<PasswordForm> FormOutOfAttributes(GHashTable* attrs) {
138 base::StringPiece app_value = GetStringFromAttributes(attrs, "application"); 145 base::StringPiece app_value = GetStringFromAttributes(attrs, "application");
139 if (!app_value.starts_with(kLibsecretAppString)) 146 if (!app_value.starts_with(kLibsecretAppString))
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 return true; 589 return true;
583 } 590 }
584 591
585 std::string NativeBackendLibsecret::GetProfileSpecificAppString( 592 std::string NativeBackendLibsecret::GetProfileSpecificAppString(
586 LocalProfileId id) { 593 LocalProfileId id) {
587 // Originally, the application string was always just "chrome" and used only 594 // Originally, the application string was always just "chrome" and used only
588 // so that we had *something* to search for since GNOME Keyring won't search 595 // so that we had *something* to search for since GNOME Keyring won't search
589 // for nothing. Now we use it to distinguish passwords for different profiles. 596 // for nothing. Now we use it to distinguish passwords for different profiles.
590 return base::StringPrintf("%s-%d", kLibsecretAppString, id); 597 return base::StringPrintf("%s-%d", kLibsecretAppString, id);
591 } 598 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/password_manager/native_backend_libsecret_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698