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

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

Issue 2017123002: Adds a base32 component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Migrates installer/setup/user_hive_visitor.cc to use base32 component Created 4 years, 6 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 | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file defines functions that integrate Chrome in Windows shell. These 5 // This file defines functions that integrate Chrome in Windows shell. These
6 // functions can be used by Chrome as well as Chrome installer. All of the 6 // functions can be used by Chrome as well as Chrome installer. All of the
7 // work is done by the local functions defined in anonymous namespace in 7 // work is done by the local functions defined in anonymous namespace in
8 // this class. 8 // this class.
9 9
10 #include "chrome/installer/util/shell_util.h" 10 #include "chrome/installer/util/shell_util.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "chrome/installer/util/browser_distribution.h" 50 #include "chrome/installer/util/browser_distribution.h"
51 #include "chrome/installer/util/install_util.h" 51 #include "chrome/installer/util/install_util.h"
52 #include "chrome/installer/util/installer_util_strings.h" 52 #include "chrome/installer/util/installer_util_strings.h"
53 #include "chrome/installer/util/l10n_string_util.h" 53 #include "chrome/installer/util/l10n_string_util.h"
54 #include "chrome/installer/util/master_preferences.h" 54 #include "chrome/installer/util/master_preferences.h"
55 #include "chrome/installer/util/master_preferences_constants.h" 55 #include "chrome/installer/util/master_preferences_constants.h"
56 #include "chrome/installer/util/registry_entry.h" 56 #include "chrome/installer/util/registry_entry.h"
57 #include "chrome/installer/util/scoped_user_protocol_entry.h" 57 #include "chrome/installer/util/scoped_user_protocol_entry.h"
58 #include "chrome/installer/util/util_constants.h" 58 #include "chrome/installer/util/util_constants.h"
59 #include "chrome/installer/util/work_item.h" 59 #include "chrome/installer/util/work_item.h"
60 #include "components/base32/base32.h"
60 61
61 using base::win::RegKey; 62 using base::win::RegKey;
62 63
63 namespace { 64 namespace {
64 65
65 // An enum used to tell QuickIsChromeRegistered() which level of registration 66 // An enum used to tell QuickIsChromeRegistered() which level of registration
66 // the caller wants to confirm. 67 // the caller wants to confirm.
67 enum RegistrationConfirmationLevel { 68 enum RegistrationConfirmationLevel {
68 // Only look for Chrome's ProgIds. 69 // Only look for Chrome's ProgIds.
69 // This is sufficient when we are trying to determine the suffix of the 70 // This is sufficient when we are trying to determine the suffix of the
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 UserSpecificRegistrySuffix::UserSpecificRegistrySuffix() { 130 UserSpecificRegistrySuffix::UserSpecificRegistrySuffix() {
130 base::string16 user_sid; 131 base::string16 user_sid;
131 if (!base::win::GetUserSidString(&user_sid)) { 132 if (!base::win::GetUserSidString(&user_sid)) {
132 NOTREACHED(); 133 NOTREACHED();
133 return; 134 return;
134 } 135 }
135 static_assert(sizeof(base::MD5Digest) == 16, "size of MD5 not as expected"); 136 static_assert(sizeof(base::MD5Digest) == 16, "size of MD5 not as expected");
136 base::MD5Digest md5_digest; 137 base::MD5Digest md5_digest;
137 std::string user_sid_ascii(base::UTF16ToASCII(user_sid)); 138 std::string user_sid_ascii(base::UTF16ToASCII(user_sid));
138 base::MD5Sum(user_sid_ascii.c_str(), user_sid_ascii.length(), &md5_digest); 139 base::MD5Sum(user_sid_ascii.c_str(), user_sid_ascii.length(), &md5_digest);
139 const base::string16 base32_md5( 140 std::string base32_md5 = base32::Base32Encode(
140 ShellUtil::ByteArrayToBase32(md5_digest.a, arraysize(md5_digest.a))); 141 base::StringPiece(reinterpret_cast<char*>(md5_digest.a),
141 // The value returned by the base32 algorithm above must never change and 142 arraysize(md5_digest.a)),
142 // must always be 26 characters long (i.e. if someone ever moves this to 143 base32::Base32EncodePolicy::OMIT_PADDING);
143 // base and implements the full base32 algorithm (i.e. with appended '=' 144 // The value returned by the base32 algorithm above must never change.
144 // signs in the output), they must provide a flag to allow this method to
145 // still request the output with no appended '=' signs).
146 DCHECK_EQ(base32_md5.length(), 26U); 145 DCHECK_EQ(base32_md5.length(), 26U);
147 suffix_.reserve(base32_md5.length() + 1); 146 suffix_.reserve(base32_md5.length() + 1);
148 suffix_.assign(1, L'.'); 147 suffix_.assign(1, L'.');
149 suffix_.append(base32_md5); 148 suffix_.append(base::ASCIIToUTF16(base32_md5));
150 } 149 }
151 150
152 bool UserSpecificRegistrySuffix::GetSuffix(base::string16* suffix) { 151 bool UserSpecificRegistrySuffix::GetSuffix(base::string16* suffix) {
153 if (suffix_.empty()) { 152 if (suffix_.empty()) {
154 NOTREACHED(); 153 NOTREACHED();
155 return false; 154 return false;
156 } 155 }
157 suffix->assign(suffix_); 156 suffix->assign(suffix_);
158 return true; 157 return true;
159 } 158 }
(...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2262 if (::GetUserName(user_name, &size) == 0 || size < 1) { 2261 if (::GetUserName(user_name, &size) == 0 || size < 1) {
2263 NOTREACHED(); 2262 NOTREACHED();
2264 return false; 2263 return false;
2265 } 2264 }
2266 suffix->reserve(size); 2265 suffix->reserve(size);
2267 suffix->assign(1, L'.'); 2266 suffix->assign(1, L'.');
2268 suffix->append(user_name, size - 1); 2267 suffix->append(user_name, size - 1);
2269 return true; 2268 return true;
2270 } 2269 }
2271 2270
2272 base::string16 ShellUtil::ByteArrayToBase32(const uint8_t* bytes, size_t size) {
2273 static const char kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
2274
2275 // Eliminate special cases first.
2276 if (size == 0) {
2277 return base::string16();
2278 } else if (size == 1) {
2279 base::string16 ret;
2280 ret.push_back(kEncoding[(bytes[0] & 0xf8) >> 3]);
2281 ret.push_back(kEncoding[(bytes[0] & 0x07) << 2]);
2282 return ret;
2283 } else if (size >= std::numeric_limits<size_t>::max() / 8) {
2284 // If |size| is too big, the calculation of |encoded_length| below will
2285 // overflow.
2286 NOTREACHED();
2287 return base::string16();
2288 }
2289
2290 // Overestimate the number of bits in the string by 4 so that dividing by 5
2291 // is the equivalent of rounding up the actual number of bits divided by 5.
2292 const size_t encoded_length = (size * 8 + 4) / 5;
2293
2294 base::string16 ret;
2295 ret.reserve(encoded_length);
2296
2297 // A bit stream which will be read from the left and appended to from the
2298 // right as it's emptied.
2299 uint16_t bit_stream = (bytes[0] << 8) + bytes[1];
2300 size_t next_byte_index = 2;
2301 int free_bits = 0;
2302 while (free_bits < 16) {
2303 // Extract the 5 leftmost bits in the stream
2304 ret.push_back(kEncoding[(bit_stream & 0xf800) >> 11]);
2305 bit_stream <<= 5;
2306 free_bits += 5;
2307
2308 // If there is enough room in the bit stream, inject another byte (if there
2309 // are any left...).
2310 if (free_bits >= 8 && next_byte_index < size) {
2311 free_bits -= 8;
2312 bit_stream += bytes[next_byte_index++] << free_bits;
2313 }
2314 }
2315
2316 DCHECK_EQ(ret.length(), encoded_length);
2317 return ret;
2318 }
2319
2320 // static 2271 // static
2321 bool ShellUtil::AddFileAssociations( 2272 bool ShellUtil::AddFileAssociations(
2322 const base::string16& prog_id, 2273 const base::string16& prog_id,
2323 const base::CommandLine& command_line, 2274 const base::CommandLine& command_line,
2324 const base::string16& file_type_name, 2275 const base::string16& file_type_name,
2325 const base::FilePath& icon_path, 2276 const base::FilePath& icon_path,
2326 const std::set<base::string16>& file_extensions) { 2277 const std::set<base::string16>& file_extensions) {
2327 ScopedVector<RegistryEntry> entries; 2278 ScopedVector<RegistryEntry> entries;
2328 2279
2329 // Create a class for this app. 2280 // Create a class for this app.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 itr != entries.end(); ++itr) 2331 itr != entries.end(); ++itr)
2381 (*itr)->AddToWorkItemList(root, items.get()); 2332 (*itr)->AddToWorkItemList(root, items.get());
2382 2333
2383 // Apply all the registry changes and if there is a problem, rollback 2334 // Apply all the registry changes and if there is a problem, rollback
2384 if (!items->Do()) { 2335 if (!items->Do()) {
2385 items->Rollback(); 2336 items->Rollback();
2386 return false; 2337 return false;
2387 } 2338 }
2388 return true; 2339 return true;
2389 } 2340 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698