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

Side by Side Diff: components/signin/core/browser/webdata/token_service_table.cc

Issue 2672833002: [Desktop] Add diagnostics about loading the refresh tokens. (Closed)
Patch Set: Fix compile Created 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/signin/core/browser/webdata/token_service_table.h" 5 #include "components/signin/core/browser/webdata/token_service_table.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 sql::Statement s(db_->GetUniqueStatement( 90 sql::Statement s(db_->GetUniqueStatement(
91 "INSERT OR REPLACE INTO token_service " 91 "INSERT OR REPLACE INTO token_service "
92 "(service, encrypted_token) VALUES (?, ?)")); 92 "(service, encrypted_token) VALUES (?, ?)"));
93 s.BindString(0, service); 93 s.BindString(0, service);
94 s.BindBlob(1, encrypted_token.data(), 94 s.BindBlob(1, encrypted_token.data(),
95 static_cast<int>(encrypted_token.length())); 95 static_cast<int>(encrypted_token.length()));
96 96
97 return s.Run(); 97 return s.Run();
98 } 98 }
99 99
100 bool TokenServiceTable::GetAllTokens( 100 TokenServiceTable::Result TokenServiceTable::GetAllTokens(
101 std::map<std::string, std::string>* tokens) { 101 std::map<std::string, std::string>* tokens) {
102 sql::Statement s(db_->GetUniqueStatement( 102 sql::Statement s(db_->GetUniqueStatement(
103 "SELECT service, encrypted_token FROM token_service")); 103 "SELECT service, encrypted_token FROM token_service"));
104 104
105 UMA_HISTOGRAM_BOOLEAN("Signin.TokenTable.GetAllTokensSqlStatementValidity", 105 UMA_HISTOGRAM_BOOLEAN("Signin.TokenTable.GetAllTokensSqlStatementValidity",
106 s.is_valid()); 106 s.is_valid());
107 107
108 if (!s.is_valid()) { 108 if (!s.is_valid()) {
109 LOG(ERROR) << "Failed to load tokens (invalid SQL statement)."; 109 LOG(ERROR) << "Failed to load tokens (invalid SQL statement).";
110 return false; 110 return TOKEN_DB_RESULT_SQL_INVALID_STATEMENT;
111 } 111 }
112 112
113 bool read_all_tokens_result = true; 113 Result read_all_tokens_result = TOKEN_DB_RESULT_SUCCESS;
114 while (s.Step()) { 114 while (s.Step()) {
115 ReadOneTokenResult read_token_result = READ_ONE_TOKEN_MAX_VALUE; 115 ReadOneTokenResult read_token_result = READ_ONE_TOKEN_MAX_VALUE;
116 116
117 std::string encrypted_token; 117 std::string encrypted_token;
118 std::string decrypted_token; 118 std::string decrypted_token;
119 std::string service; 119 std::string service;
120 service = s.ColumnString(0); 120 service = s.ColumnString(0);
121 bool entry_ok = !service.empty() && 121 bool entry_ok = !service.empty() &&
122 s.ColumnBlobAsString(1, &encrypted_token); 122 s.ColumnBlobAsString(1, &encrypted_token);
123 if (entry_ok) { 123 if (entry_ok) {
124 if (OSCrypt::DecryptString(encrypted_token, &decrypted_token)) { 124 if (OSCrypt::DecryptString(encrypted_token, &decrypted_token)) {
125 (*tokens)[service] = decrypted_token; 125 (*tokens)[service] = decrypted_token;
126 read_token_result = READ_ONE_TOKEN_SUCCESS; 126 read_token_result = READ_ONE_TOKEN_SUCCESS;
127 } else { 127 } else {
128 // Chrome relies on native APIs to encrypt and decrypt the tokens which 128 // Chrome relies on native APIs to encrypt and decrypt the tokens which
129 // may fail (see http://crbug.com/686485). 129 // may fail (see http://crbug.com/686485).
130 LOG(ERROR) << "Failed to decrypt token for service " << service; 130 LOG(ERROR) << "Failed to decrypt token for service " << service;
131 read_token_result = READ_ONE_TOKEN_DB_SUCCESS_DECRYPT_FAILED; 131 read_token_result = READ_ONE_TOKEN_DB_SUCCESS_DECRYPT_FAILED;
132 read_all_tokens_result = false; 132 read_all_tokens_result = TOKEN_DB_RESULT_DECRYPT_ERROR;
133 } 133 }
134 } else { 134 } else {
135 LOG(ERROR) << "Bad token entry for service " << service; 135 LOG(ERROR) << "Bad token entry for service " << service;
136 read_token_result = READ_ONE_TOKEN_DB_FAILED_BAD_ENTRY; 136 read_token_result = READ_ONE_TOKEN_DB_FAILED_BAD_ENTRY;
137 read_all_tokens_result = false; 137 read_all_tokens_result = TOKEN_DB_RESULT_BAD_ENTRY;
138 } 138 }
139 DCHECK_LT(read_token_result, READ_ONE_TOKEN_MAX_VALUE); 139 DCHECK_LT(read_token_result, READ_ONE_TOKEN_MAX_VALUE);
140 UMA_HISTOGRAM_ENUMERATION("Signin.TokenTable.ReadTokenFromDBResult", 140 UMA_HISTOGRAM_ENUMERATION("Signin.TokenTable.ReadTokenFromDBResult",
141 read_token_result, 141 read_token_result,
142 READ_ONE_TOKEN_MAX_VALUE); 142 READ_ONE_TOKEN_MAX_VALUE);
143 } 143 }
144 return read_all_tokens_result; 144 return read_all_tokens_result;
145 } 145 }
OLDNEW
« no previous file with comments | « components/signin/core/browser/webdata/token_service_table.h ('k') | components/signin/core/browser/webdata/token_web_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698