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

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 comments. 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"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 {"times_used", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, 112 {"times_used", SECRET_SCHEMA_ATTRIBUTE_INTEGER},
113 {"date_synced", SECRET_SCHEMA_ATTRIBUTE_STRING}, 113 {"date_synced", SECRET_SCHEMA_ATTRIBUTE_STRING},
114 {"display_name", SECRET_SCHEMA_ATTRIBUTE_STRING}, 114 {"display_name", SECRET_SCHEMA_ATTRIBUTE_STRING},
115 {"avatar_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, 115 {"avatar_url", SECRET_SCHEMA_ATTRIBUTE_STRING},
116 {"federation_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, 116 {"federation_url", SECRET_SCHEMA_ATTRIBUTE_STRING},
117 {"is_zero_click", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, 117 {"is_zero_click", SECRET_SCHEMA_ATTRIBUTE_INTEGER},
118 // This field is always "chrome-profile_id" so that we can search for it. 118 // This field is always "chrome-profile_id" so that we can search for it.
119 {"application", SECRET_SCHEMA_ATTRIBUTE_STRING}, 119 {"application", SECRET_SCHEMA_ATTRIBUTE_STRING},
120 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}}; 120 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}};
121 121
122 char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) { 122 std::string GetStringFromAttributes(GHashTable* attrs, const char* keyname) {
vabr (Chromium) 2015/01/29 14:10:34 I would suggest still returning char* and carefull
dvadym 2015/01/29 14:21:40 Done.
123 return static_cast<char*>(g_hash_table_lookup(attrs, keyname)); 123 gpointer value = g_hash_table_lookup(attrs, keyname);
124 return value ? std::string(static_cast<char*>(value)) : std::string();
124 } 125 }
125 126
126 uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) { 127 uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) {
127 char* value = static_cast<char*>(g_hash_table_lookup(attrs, keyname)); 128 gpointer value = g_hash_table_lookup(attrs, keyname);
129 if (value == NULL)
vabr (Chromium) 2015/01/29 14:10:34 nit: NULL -> nullptr
dvadym 2015/01/29 14:21:40 Done.
130 return uint32_t();
128 uint32_t result; 131 uint32_t result;
129 bool value_ok = base::StringToUint(value, &result); 132 bool value_ok = base::StringToUint(static_cast<char*>(value), &result);
130 DCHECK(value_ok); 133 DCHECK(value_ok);
131 return result; 134 return result;
132 } 135 }
133 136
134 // Convert the attributes into a new PasswordForm. 137 // Convert the attributes into a new PasswordForm.
135 // Note: does *not* get the actual password, as that is not a key attribute! 138 // 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. 139 // Returns nullptr if the attributes are for the wrong application.
137 scoped_ptr<PasswordForm> FormOutOfAttributes(GHashTable* attrs) { 140 scoped_ptr<PasswordForm> FormOutOfAttributes(GHashTable* attrs) {
138 base::StringPiece app_value = GetStringFromAttributes(attrs, "application"); 141 std::string app_string = GetStringFromAttributes(attrs, "application");
vabr (Chromium) 2015/01/29 14:10:34 Please do not convert to std::string, that harms p
dvadym 2015/01/29 14:21:39 Done.
142 base::StringPiece app_value = app_string;
139 if (!app_value.starts_with(kLibsecretAppString)) 143 if (!app_value.starts_with(kLibsecretAppString))
140 return scoped_ptr<PasswordForm>(); 144 return scoped_ptr<PasswordForm>();
141 145
142 scoped_ptr<PasswordForm> form(new PasswordForm()); 146 scoped_ptr<PasswordForm> form(new PasswordForm());
143 form->origin = GURL(GetStringFromAttributes(attrs, "origin_url")); 147 form->origin = GURL(GetStringFromAttributes(attrs, "origin_url"));
144 form->action = GURL(GetStringFromAttributes(attrs, "action_url")); 148 form->action = GURL(GetStringFromAttributes(attrs, "action_url"));
145 form->username_element = 149 form->username_element =
146 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_element")); 150 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_element"));
147 form->username_value = 151 form->username_value =
148 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_value")); 152 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_value"));
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 return true; 586 return true;
583 } 587 }
584 588
585 std::string NativeBackendLibsecret::GetProfileSpecificAppString( 589 std::string NativeBackendLibsecret::GetProfileSpecificAppString(
586 LocalProfileId id) { 590 LocalProfileId id) {
587 // Originally, the application string was always just "chrome" and used only 591 // 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 592 // 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. 593 // for nothing. Now we use it to distinguish passwords for different profiles.
590 return base::StringPrintf("%s-%d", kLibsecretAppString, id); 594 return base::StringPrintf("%s-%d", kLibsecretAppString, id);
591 } 595 }
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