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

Side by Side Diff: chrome/browser/sxs_linux.cc

Issue 1240183002: Update SplitString calls in chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 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/sxs_linux.h" 5 #include "chrome/browser/sxs_linux.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 bool DoAddChannelMarkToUserDataDir(const base::FilePath& user_data_dir) { 62 bool DoAddChannelMarkToUserDataDir(const base::FilePath& user_data_dir) {
63 std::string product_channel_name(GetChannelMarkForThisExecutable()); 63 std::string product_channel_name(GetChannelMarkForThisExecutable());
64 base::FilePath channels_path(user_data_dir.AppendASCII(kChannelsFileName)); 64 base::FilePath channels_path(user_data_dir.AppendASCII(kChannelsFileName));
65 std::vector<std::string> user_data_dir_channels; 65 std::vector<std::string> user_data_dir_channels;
66 66
67 // Note: failure to read the channels file is not fatal. It's possible 67 // Note: failure to read the channels file is not fatal. It's possible
68 // and legitimate that it doesn't exist, e.g. for new profile or for profile 68 // and legitimate that it doesn't exist, e.g. for new profile or for profile
69 // existing before channel marks have been introduced. 69 // existing before channel marks have been introduced.
70 std::string channels_contents; 70 std::string channels_contents;
71 if (base::ReadFileToString(channels_path, &channels_contents)) 71 if (base::ReadFileToString(channels_path, &channels_contents)) {
72 base::SplitString(channels_contents, '\n', &user_data_dir_channels); 72 base::SplitString(channels_contents, "\n",
73 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
74 }
73 75
74 if (std::find(user_data_dir_channels.begin(), 76 if (std::find(user_data_dir_channels.begin(),
75 user_data_dir_channels.end(), 77 user_data_dir_channels.end(),
76 product_channel_name) != user_data_dir_channels.end()) { 78 product_channel_name) != user_data_dir_channels.end()) {
77 // No need to do further disk writes if our channel mark is already present. 79 // No need to do further disk writes if our channel mark is already present.
78 return true; 80 return true;
79 } 81 }
80 82
81 user_data_dir_channels.push_back(product_channel_name); 83 user_data_dir_channels.push_back(product_channel_name);
82 return base::ImportantFileWriter::WriteFileAtomically( 84 return base::ImportantFileWriter::WriteFileAtomically(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 121 }
120 122
121 base::FilePath channels_path(source_path.AppendASCII(kChannelsFileName)); 123 base::FilePath channels_path(source_path.AppendASCII(kChannelsFileName));
122 124
123 std::string channels_contents; 125 std::string channels_contents;
124 if (!base::ReadFileToString(channels_path, &channels_contents)) { 126 if (!base::ReadFileToString(channels_path, &channels_contents)) {
125 LOG(WARNING) << "Failed to read channels file."; 127 LOG(WARNING) << "Failed to read channels file.";
126 return chrome::RESULT_CODE_SXS_MIGRATION_FAILED; 128 return chrome::RESULT_CODE_SXS_MIGRATION_FAILED;
127 } 129 }
128 130
129 std::vector<std::string> user_data_dir_channels; 131 std::vector<std::string> user_data_dir_channels = base::SplitString(
130 base::SplitString(channels_contents, '\n', &user_data_dir_channels); 132 channels_contents, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
131 133
132 if (user_data_dir_channels.size() != 1) { 134 if (user_data_dir_channels.size() != 1) {
133 LOG(WARNING) << "User data dir migration is only possible when the profile " 135 LOG(WARNING) << "User data dir migration is only possible when the profile "
134 << "is only used with a single channel."; 136 << "is only used with a single channel.";
135 return chrome::RESULT_CODE_SXS_MIGRATION_FAILED; 137 return chrome::RESULT_CODE_SXS_MIGRATION_FAILED;
136 } 138 }
137 139
138 if (user_data_dir_channels[0] != GetChannelMarkForThisExecutable()) { 140 if (user_data_dir_channels[0] != GetChannelMarkForThisExecutable()) {
139 LOG(WARNING) << "User data dir migration is only possible when the profile " 141 LOG(WARNING) << "User data dir migration is only possible when the profile "
140 << "is used with the same channel."; 142 << "is used with the same channel.";
141 return chrome::RESULT_CODE_SXS_MIGRATION_FAILED; 143 return chrome::RESULT_CODE_SXS_MIGRATION_FAILED;
142 } 144 }
143 145
144 base::FilePath target_path = 146 base::FilePath target_path =
145 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( 147 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
146 switches::kMigrateDataDirForSxS); 148 switches::kMigrateDataDirForSxS);
147 149
148 if (!base::Move(source_path, target_path)) { 150 if (!base::Move(source_path, target_path)) {
149 LOG(ERROR) << "Failed to rename '" << source_path.value() 151 LOG(ERROR) << "Failed to rename '" << source_path.value()
150 << "' to '" << target_path.value() << "'"; 152 << "' to '" << target_path.value() << "'";
151 return chrome::RESULT_CODE_SXS_MIGRATION_FAILED; 153 return chrome::RESULT_CODE_SXS_MIGRATION_FAILED;
152 } 154 }
153 155
154 return content::RESULT_CODE_NORMAL_EXIT; 156 return content::RESULT_CODE_NORMAL_EXIT;
155 } 157 }
156 158
157 } // namespace sxs_linux 159 } // namespace sxs_linux
OLDNEW
« no previous file with comments | « chrome/browser/supervised_user/supervised_user_whitelist_service.cc ('k') | chrome/browser/themes/theme_properties.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698