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

Side by Side Diff: client/settings.cc

Issue 987383002: Return a FilePath from Settings::file_path() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rebase Created 5 years, 9 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 | « client/settings.h ('k') | no next file » | 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 Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 initialized_() { 50 initialized_() {
51 } 51 }
52 52
53 Settings::~Settings() { 53 Settings::~Settings() {
54 } 54 }
55 55
56 bool Settings::Initialize() { 56 bool Settings::Initialize() {
57 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); 57 INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
58 58
59 ScopedFileHandle handle(HANDLE_EINTR( 59 ScopedFileHandle handle(HANDLE_EINTR(
60 open(file_path(), 60 open(file_path().value().c_str(),
61 O_CREAT | O_EXCL | O_WRONLY | O_EXLOCK, 61 O_CREAT | O_EXCL | O_WRONLY | O_EXLOCK,
62 0644))); 62 0644)));
63 63
64 // The file was created, so this is a new database that needs to be 64 // The file was created, so this is a new database that needs to be
65 // initialized with a client ID. 65 // initialized with a client ID.
66 if (handle.is_valid()) { 66 if (handle.is_valid()) {
67 bool initialized = InitializeSettings(handle.get()); 67 bool initialized = InitializeSettings(handle.get());
68 if (initialized) 68 if (initialized)
69 INITIALIZATION_STATE_SET_VALID(initialized_); 69 INITIALIZATION_STATE_SET_VALID(initialized_);
70 return initialized; 70 return initialized;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ScopedFileHandle handle = OpenForWritingAndReadSettings(&settings); 138 ScopedFileHandle handle = OpenForWritingAndReadSettings(&settings);
139 if (!handle.is_valid()) 139 if (!handle.is_valid())
140 return false; 140 return false;
141 141
142 settings.last_upload_attempt_time = InRangeCast<uint64_t>(time, 0); 142 settings.last_upload_attempt_time = InRangeCast<uint64_t>(time, 0);
143 143
144 return WriteSettings(handle.get(), settings); 144 return WriteSettings(handle.get(), settings);
145 } 145 }
146 146
147 ScopedFileHandle Settings::OpenForReading() { 147 ScopedFileHandle Settings::OpenForReading() {
148 ScopedFileHandle handle(HANDLE_EINTR(open(file_path(), O_RDONLY | O_SHLOCK))); 148 ScopedFileHandle handle(HANDLE_EINTR(
149 open(file_path().value().c_str(), O_RDONLY | O_SHLOCK)));
149 PLOG_IF(ERROR, !handle.is_valid()) << "open for reading"; 150 PLOG_IF(ERROR, !handle.is_valid()) << "open for reading";
150 return handle.Pass(); 151 return handle.Pass();
151 } 152 }
152 153
153 ScopedFileHandle Settings::OpenForReadingAndWriting() { 154 ScopedFileHandle Settings::OpenForReadingAndWriting() {
154 ScopedFileHandle handle(HANDLE_EINTR( 155 ScopedFileHandle handle(HANDLE_EINTR(
155 open(file_path(), O_RDWR | O_EXLOCK | O_CREAT, 0644))); 156 open(file_path().value().c_str(), O_RDWR | O_EXLOCK | O_CREAT, 0644)));
156 PLOG_IF(ERROR, !handle.is_valid()) << "open for writing"; 157 PLOG_IF(ERROR, !handle.is_valid()) << "open for writing";
157 return handle.Pass(); 158 return handle.Pass();
158 } 159 }
159 160
160 bool Settings::OpenAndReadSettings(Data* out_data) { 161 bool Settings::OpenAndReadSettings(Data* out_data) {
161 ScopedFileHandle handle = OpenForReading(); 162 ScopedFileHandle handle = OpenForReading();
162 if (!handle.is_valid()) 163 if (!handle.is_valid())
163 return false; 164 return false;
164 165
165 if (ReadSettings(handle.get(), out_data)) 166 if (ReadSettings(handle.get(), out_data))
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if (handle == kInvalidFileHandle) { 218 if (handle == kInvalidFileHandle) {
218 scoped_handle.reset(OpenForReadingAndWriting().release()); 219 scoped_handle.reset(OpenForReadingAndWriting().release());
219 handle = scoped_handle.get(); 220 handle = scoped_handle.get();
220 221
221 // Test if the file has already been recovered now that the exclusive lock 222 // Test if the file has already been recovered now that the exclusive lock
222 // is held. 223 // is held.
223 if (ReadSettings(handle, out_data)) 224 if (ReadSettings(handle, out_data))
224 return true; 225 return true;
225 } 226 }
226 227
227 LOG(INFO) << "Recovering settings file " << file_path(); 228 LOG(INFO) << "Recovering settings file " << file_path().value();
228 229
229 if (handle == kInvalidFileHandle) { 230 if (handle == kInvalidFileHandle) {
230 LOG(ERROR) << "Invalid file handle"; 231 LOG(ERROR) << "Invalid file handle";
231 return false; 232 return false;
232 } 233 }
233 234
234 if (!InitializeSettings(handle)) 235 if (!InitializeSettings(handle))
235 return false; 236 return false;
236 237
237 return ReadSettings(handle, out_data); 238 return ReadSettings(handle, out_data);
238 } 239 }
239 240
240 bool Settings::InitializeSettings(FileHandle handle) { 241 bool Settings::InitializeSettings(FileHandle handle) {
241 uuid_t uuid; 242 uuid_t uuid;
242 uuid_generate(uuid); 243 uuid_generate(uuid);
243 244
244 Data settings; 245 Data settings;
245 settings.client_id.InitializeFromBytes(uuid); 246 settings.client_id.InitializeFromBytes(uuid);
246 247
247 return WriteSettings(handle, settings); 248 return WriteSettings(handle, settings);
248 } 249 }
249 250
250 } // namespace crashpad 251 } // namespace crashpad
OLDNEW
« no previous file with comments | « client/settings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698