This source file includes following definitions.
- ParseAdditionalModuleID
- ParseAdditionalModuleIDs
- LoadModuleIDs
#include "chrome/browser/install_verification/win/module_ids.h"
#include <utility>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "grit/browser_resources.h"
#include "ui/base/resource/resource_bundle.h"
namespace {
struct { size_t id; const char* module_name_digest; }
kExpectedInstallModules[] = {
{1u, "c8cc47613e155f2129f480c6ced84549"},
{2u, "49b78a23b0d8d5d8fb60d4e472b22764"},
};
void ParseAdditionalModuleID(
const base::StringPiece& line,
ModuleIDs* module_ids) {
DCHECK(module_ids);
base::CStringTokenizer line_tokenizer(line.begin(), line.end(), " ");
if (!line_tokenizer.GetNext())
return;
base::StringPiece id_piece(line_tokenizer.token_piece());
if (!line_tokenizer.GetNext())
return;
base::StringPiece digest_piece(line_tokenizer.token_piece());
if (line_tokenizer.GetNext())
return;
unsigned id = 0;
if (!StringToUint(id_piece, &id))
return;
if (digest_piece.length() != 32)
return;
for (base::StringPiece::const_iterator it = digest_piece.begin();
it != digest_piece.end(); ++it) {
if (!IsHexDigit(*it))
return;
}
module_ids->insert(std::make_pair(digest_piece.as_string(), id));
}
}
void ParseAdditionalModuleIDs(
const base::StringPiece& raw_data,
ModuleIDs* module_ids) {
DCHECK(module_ids);
base::CStringTokenizer file_tokenizer(raw_data.begin(),
raw_data.end(),
"\r\n");
while (file_tokenizer.GetNext()) {
ParseAdditionalModuleID(base::StringPiece(file_tokenizer.token_piece()),
module_ids);
}
}
void LoadModuleIDs(ModuleIDs* module_ids) {
for (size_t i = 0; i < arraysize(kExpectedInstallModules); ++i) {
module_ids->insert(
std::make_pair(
kExpectedInstallModules[i].module_name_digest,
kExpectedInstallModules[i].id));
}
ParseAdditionalModuleIDs(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_ADDITIONAL_MODULE_IDS),
module_ids);
}