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

Side by Side Diff: remoting/test/refresh_token_store.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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 | « remoting/test/refresh_token_store.h ('k') | remoting/test/remote_host_info_fetcher.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 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 "remoting/test/refresh_token_store.h" 5 #include "remoting/test/refresh_token_store.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/important_file_writer.h" 8 #include "base/files/important_file_writer.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 15
15 namespace { 16 namespace {
16 const base::FilePath::CharType kTokenFileName[] = 17 const base::FilePath::CharType kTokenFileName[] =
17 FILE_PATH_LITERAL("refresh_tokens.json"); 18 FILE_PATH_LITERAL("refresh_tokens.json");
18 const base::FilePath::CharType kRemotingFolder[] = 19 const base::FilePath::CharType kRemotingFolder[] =
19 FILE_PATH_LITERAL("remoting"); 20 FILE_PATH_LITERAL("remoting");
20 const base::FilePath::CharType kRefreshTokenStoreFolder[] = 21 const base::FilePath::CharType kRefreshTokenStoreFolder[] =
21 FILE_PATH_LITERAL("token_store"); 22 FILE_PATH_LITERAL("token_store");
22 } // namespace 23 } // namespace
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 base::FilePath refresh_token_file_path(GetPathForRefreshTokenFile()); 65 base::FilePath refresh_token_file_path(GetPathForRefreshTokenFile());
65 DCHECK(!refresh_token_file_path.empty()); 66 DCHECK(!refresh_token_file_path.empty());
66 VLOG(1) << "Reading token from: " << refresh_token_file_path.value(); 67 VLOG(1) << "Reading token from: " << refresh_token_file_path.value();
67 68
68 std::string file_contents; 69 std::string file_contents;
69 if (!base::ReadFileToString(refresh_token_file_path, &file_contents)) { 70 if (!base::ReadFileToString(refresh_token_file_path, &file_contents)) {
70 VLOG(1) << "Couldn't read token file: " << refresh_token_file_path.value(); 71 VLOG(1) << "Couldn't read token file: " << refresh_token_file_path.value();
71 return std::string(); 72 return std::string();
72 } 73 }
73 74
74 scoped_ptr<base::Value> token_data(base::JSONReader::Read(file_contents)); 75 std::unique_ptr<base::Value> token_data(
76 base::JSONReader::Read(file_contents));
75 base::DictionaryValue* tokens = nullptr; 77 base::DictionaryValue* tokens = nullptr;
76 if (!token_data || !token_data->GetAsDictionary(&tokens)) { 78 if (!token_data || !token_data->GetAsDictionary(&tokens)) {
77 LOG(ERROR) << "Refresh token file contents were not valid JSON, " 79 LOG(ERROR) << "Refresh token file contents were not valid JSON, "
78 << "could not retrieve token."; 80 << "could not retrieve token.";
79 return std::string(); 81 return std::string();
80 } 82 }
81 83
82 std::string refresh_token; 84 std::string refresh_token;
83 if (!tokens->GetStringWithoutPathExpansion(user_name_, &refresh_token)) { 85 if (!tokens->GetStringWithoutPathExpansion(user_name_, &refresh_token)) {
84 // This may not be an error as the file could exist but contain refresh 86 // This may not be an error as the file could exist but contain refresh
(...skipping 21 matching lines...) Expand all
106 } 108 }
107 109
108 std::string file_contents("{}"); 110 std::string file_contents("{}");
109 if (base::PathExists(file_path)) { 111 if (base::PathExists(file_path)) {
110 if (!base::ReadFileToString(file_path, &file_contents)) { 112 if (!base::ReadFileToString(file_path, &file_contents)) {
111 LOG(ERROR) << "Invalid token file: " << file_path.value(); 113 LOG(ERROR) << "Invalid token file: " << file_path.value();
112 return false; 114 return false;
113 } 115 }
114 } 116 }
115 117
116 scoped_ptr<base::Value> token_data(base::JSONReader::Read(file_contents)); 118 std::unique_ptr<base::Value> token_data(
119 base::JSONReader::Read(file_contents));
117 base::DictionaryValue* tokens = nullptr; 120 base::DictionaryValue* tokens = nullptr;
118 if (!token_data || !token_data->GetAsDictionary(&tokens)) { 121 if (!token_data || !token_data->GetAsDictionary(&tokens)) {
119 LOG(ERROR) << "Invalid refresh token file format, could not store token."; 122 LOG(ERROR) << "Invalid refresh token file format, could not store token.";
120 return false; 123 return false;
121 } 124 }
122 125
123 std::string json_string; 126 std::string json_string;
124 tokens->SetStringWithoutPathExpansion(user_name_, refresh_token); 127 tokens->SetStringWithoutPathExpansion(user_name_, refresh_token);
125 if (!base::JSONWriter::Write(*token_data, &json_string)) { 128 if (!base::JSONWriter::Write(*token_data, &json_string)) {
126 LOG(ERROR) << "Couldn't convert JSON data to string"; 129 LOG(ERROR) << "Couldn't convert JSON data to string";
(...skipping 24 matching lines...) Expand all
151 } 154 }
152 155
153 // If no file has been specified, then we will use a default file name. 156 // If no file has been specified, then we will use a default file name.
154 if (refresh_token_file_path.Extension().empty()) { 157 if (refresh_token_file_path.Extension().empty()) {
155 refresh_token_file_path = refresh_token_file_path.Append(kTokenFileName); 158 refresh_token_file_path = refresh_token_file_path.Append(kTokenFileName);
156 } 159 }
157 160
158 return refresh_token_file_path; 161 return refresh_token_file_path;
159 } 162 }
160 163
161 scoped_ptr<RefreshTokenStore> RefreshTokenStore::OnDisk( 164 std::unique_ptr<RefreshTokenStore> RefreshTokenStore::OnDisk(
162 const std::string& user_name, 165 const std::string& user_name,
163 const base::FilePath& refresh_token_file_path) { 166 const base::FilePath& refresh_token_file_path) {
164 return make_scoped_ptr<RefreshTokenStore>( 167 return base::WrapUnique<RefreshTokenStore>(
165 new RefreshTokenStoreOnDisk(user_name, refresh_token_file_path)); 168 new RefreshTokenStoreOnDisk(user_name, refresh_token_file_path));
166 } 169 }
167 170
168 } // namespace test 171 } // namespace test
169 } // namespace remoting 172 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/refresh_token_store.h ('k') | remoting/test/remote_host_info_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698