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

Side by Side Diff: chrome/installer/util/delete_tree_work_item.cc

Issue 1468803002: Switch to static_assert. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@assert1
Patch Set: message cleanup Created 5 years 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/installer/util/delete_tree_work_item.h" 5 #include "chrome/installer/util/delete_tree_work_item.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Casts a value of an unsigned type to a signed type of the same size provided 15 // Casts a value of an unsigned type to a signed type of the same size provided
16 // that there is no overflow. 16 // that there is no overflow.
17 template<typename L, typename R> 17 template<typename L, typename R>
18 bool SafeCast(L left, R* right) { 18 bool SafeCast(L left, R* right) {
19 DCHECK(right); 19 DCHECK(right);
20 COMPILE_ASSERT(sizeof(left) == sizeof(right), 20 static_assert(sizeof(left) == sizeof(right),
21 must_add_support_for_crazy_data_types); 21 "Items SafeCast is used with must be of the same size");
22 if (left > static_cast<L>(std::numeric_limits<R>::max())) 22 if (left > static_cast<L>(std::numeric_limits<R>::max()))
23 return false; 23 return false;
24 *right = static_cast<L>(left); 24 *right = static_cast<L>(left);
25 return true; 25 return true;
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 DeleteTreeWorkItem::DeleteTreeWorkItem( 30 DeleteTreeWorkItem::DeleteTreeWorkItem(
31 const base::FilePath& root_path, 31 const base::FilePath& root_path,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 backup_dir.path().Append(key_file.BaseName()); 158 backup_dir.path().Append(key_file.BaseName());
159 if (base::PathExists(backup_file) && 159 if (base::PathExists(backup_file) &&
160 !base::Move(backup_file, key_file)) { 160 !base::Move(backup_file, key_file)) {
161 // This could happen if we could not delete the key file to begin with. 161 // This could happen if we could not delete the key file to begin with.
162 PLOG(WARNING) << "Rollback: Failed to move backup file back in place: " 162 PLOG(WARNING) << "Rollback: Failed to move backup file back in place: "
163 << backup_file.value() << " to " << key_file.value(); 163 << backup_file.value() << " to " << key_file.value();
164 } 164 }
165 } 165 }
166 } 166 }
167 } 167 }
OLDNEW
« no previous file with comments | « chrome/installer/util/channel_info.cc ('k') | chrome/installer/util/google_update_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698