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

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

Issue 63153003: mac: Prepare for -Wunused-functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/password_syncable_service.h" 5 #include "chrome/browser/password_manager/password_syncable_service.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/password_manager/password_store.h" 9 #include "chrome/browser/password_manager/password_store.h"
10 #include "components/autofill/core/common/password_form.h" 10 #include "components/autofill/core/common/password_form.h"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 #include "sync/api/sync_error_factory.h" 12 #include "sync/api/sync_error_factory.h"
13 13
14 namespace {
15
16 // Converts the |PasswordSpecifics| obtained from sync to an
17 // object of type |PasswordForm|.
18 void ExtractPasswordFromSpecifics(
19 const sync_pb::PasswordSpecificsData& password,
20 autofill::PasswordForm* new_password) {
21 new_password->scheme =
22 static_cast<autofill::PasswordForm::Scheme>(password.scheme());
23 new_password->signon_realm = password.signon_realm();
24 new_password->origin = GURL(password.origin());
25 new_password->action = GURL(password.action());
26 new_password->username_element =
27 UTF8ToUTF16(password.username_element());
28 new_password->password_element =
29 UTF8ToUTF16(password.password_element());
30 new_password->username_value =
31 UTF8ToUTF16(password.username_value());
32 new_password->password_value =
33 UTF8ToUTF16(password.password_value());
34 new_password->ssl_valid = password.ssl_valid();
35 new_password->preferred = password.preferred();
36 new_password->date_created =
37 base::Time::FromInternalValue(password.date_created());
38 new_password->blacklisted_by_user =
39 password.blacklisted();
40 }
41
42 // Merges the sync password (obtained from the password specifics) and
43 // local password and stores the output in the |new_password_form| pointer.
44 bool MergeLocalAndSyncPasswords(
45 const sync_pb::PasswordSpecificsData& password_specifics,
46 const autofill::PasswordForm& password_form,
47 autofill::PasswordForm* new_password_form) {
48 if (password_specifics.scheme() == password_form.scheme &&
49 password_form.signon_realm == password_specifics.signon_realm() &&
50 password_form.origin.spec() == password_specifics.origin() &&
51 password_form.action.spec() == password_specifics.action() &&
52 UTF16ToUTF8(password_form.username_element) ==
53 password_specifics.username_element() &&
54 UTF16ToUTF8(password_form.password_element) ==
55 password_specifics.password_element() &&
56 UTF16ToUTF8(password_form.username_value) ==
57 password_specifics.username_value() &&
58 UTF16ToUTF8(password_form.password_value) ==
59 password_specifics.password_value() &&
60 password_specifics.ssl_valid() == password_form.ssl_valid &&
61 password_specifics.preferred() == password_form.preferred &&
62 password_specifics.date_created() ==
63 password_form.date_created.ToInternalValue() &&
64 password_specifics.blacklisted() ==
65 password_form.blacklisted_by_user) {
66 return false;
67 }
68
69 // If the passwords differ, take the one that was created more recently.
70 if (base::Time::FromInternalValue(password_specifics.date_created()) <=
71 password_form.date_created) {
72 *new_password_form = password_form;
73 } else {
74 ExtractPasswordFromSpecifics(password_specifics, new_password_form);
75 }
76
77 return true;
78 }
79
80 } // namespace
81
82 PasswordSyncableService::PasswordSyncableService( 14 PasswordSyncableService::PasswordSyncableService(
83 scoped_refptr<PasswordStore> password_store) 15 scoped_refptr<PasswordStore> password_store)
84 : password_store_(password_store) { 16 : password_store_(password_store) {
85 } 17 }
86 18
87 PasswordSyncableService::~PasswordSyncableService() {} 19 PasswordSyncableService::~PasswordSyncableService() {}
88 20
89 syncer::SyncMergeResult 21 syncer::SyncMergeResult
90 PasswordSyncableService::MergeDataAndStartSyncing( 22 PasswordSyncableService::MergeDataAndStartSyncing(
91 syncer::ModelType type, 23 syncer::ModelType type,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // static 131 // static
200 std::string PasswordSyncableService::MakeTag( 132 std::string PasswordSyncableService::MakeTag(
201 const sync_pb::PasswordSpecificsData& password) { 133 const sync_pb::PasswordSpecificsData& password) {
202 return MakeTag(password.origin(), 134 return MakeTag(password.origin(),
203 password.username_element(), 135 password.username_element(),
204 password.username_value(), 136 password.username_value(),
205 password.password_element(), 137 password.password_element(),
206 password.signon_realm()); 138 password.signon_realm());
207 } 139 }
208 140
OLDNEW
« no previous file with comments | « chrome/browser/metrics/variations/variations_service.cc ('k') | chrome/browser/policy/browser_policy_connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698