summaryrefslogtreecommitdiffstats
path: root/courgette
diff options
context:
space:
mode:
authorhuangs <huangs@chromium.org>2015-09-01 14:59:02 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-01 21:59:38 +0000
commitfc0511d9067759336f42d04e918e8a3ce0b84376 (patch)
tree34ce2475e10da2f9237b77198b244461d302f948 /courgette
parent3e5e31ce994d59d2f3b3aeca4df2cbc4c7a65ae4 (diff)
downloadchromium_src-fc0511d9067759336f42d04e918e8a3ce0b84376.zip
chromium_src-fc0511d9067759336f42d04e918e8a3ce0b84376.tar.gz
chromium_src-fc0511d9067759336f42d04e918e8a3ce0b84376.tar.bz2
[Courgette] Adding CourgetteConfig singleton and --experimental flag.
This prepare for upcoming experiments to reduce patch size. We want to avoid disrupting existing functionality. Review URL: https://codereview.chromium.org/1306193004 Cr-Commit-Position: refs/heads/master@{#346746}
Diffstat (limited to 'courgette')
-rw-r--r--courgette/BUILD.gn2
-rw-r--r--courgette/courgette.gyp2
-rw-r--r--courgette/courgette_config.cc34
-rw-r--r--courgette/courgette_config.h39
-rw-r--r--courgette/courgette_tool.cc6
-rw-r--r--courgette/ensemble_apply.cc7
-rw-r--r--courgette/ensemble_create.cc7
7 files changed, 93 insertions, 4 deletions
diff --git a/courgette/BUILD.gn b/courgette/BUILD.gn
index 1ebd2ee..2deef9c2 100644
--- a/courgette/BUILD.gn
+++ b/courgette/BUILD.gn
@@ -12,6 +12,8 @@ static_library("courgette_lib") {
"assembly_program.cc",
"assembly_program.h",
"courgette.h",
+ "courgette_config.cc",
+ "courgette_config.h",
"crc.cc",
"crc.h",
"difference_estimator.cc",
diff --git a/courgette/courgette.gyp b/courgette/courgette.gyp
index 8ff08bc..5ece6e9 100644
--- a/courgette/courgette.gyp
+++ b/courgette/courgette.gyp
@@ -12,6 +12,8 @@
'assembly_program.cc',
'assembly_program.h',
'courgette.h',
+ 'courgette_config.cc',
+ 'courgette_config.h',
'crc.cc',
'crc.h',
'difference_estimator.cc',
diff --git a/courgette/courgette_config.cc b/courgette/courgette_config.cc
new file mode 100644
index 0000000..b92e43a
--- /dev/null
+++ b/courgette/courgette_config.cc
@@ -0,0 +1,34 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "courgette/courgette_config.h"
+
+#include "base/command_line.h"
+#include "courgette/ensemble.h"
+
+namespace courgette {
+
+namespace {
+
+static const uint32 kExperimentalVersion = 0xDEADBEEF;
+
+} // namespace
+
+// static
+CourgetteConfig* CourgetteConfig::GetInstance() {
+ return Singleton<CourgetteConfig>::get();
+}
+
+uint32 CourgetteConfig::ensemble_version() const {
+ return is_experimental_ ? kExperimentalVersion : CourgettePatchFile::kVersion;
+}
+
+void CourgetteConfig::Initialize(const base::CommandLine& command_line) {
+ is_experimental_ = command_line.HasSwitch("experimental");
+}
+
+CourgetteConfig::CourgetteConfig() : is_experimental_(false) {
+}
+
+} // namespace courgette
diff --git a/courgette/courgette_config.h b/courgette/courgette_config.h
new file mode 100644
index 0000000..cbcfc22
--- /dev/null
+++ b/courgette/courgette_config.h
@@ -0,0 +1,39 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COURGETTE_COURGETTE_CONFIG_H_
+#define COURGETTE_COURGETTE_CONFIG_H_
+
+#include "base/macros.h"
+#include "base/memory/singleton.h"
+
+namespace base {
+class CommandLine;
+} // namespace base
+
+namespace courgette {
+
+// A singleton class to hold global configurations for Courgette, mainly for
+// experimental purposes.
+class CourgetteConfig {
+ public:
+ static CourgetteConfig* GetInstance();
+
+ void Initialize(const base::CommandLine& command_line);
+
+ bool is_experimental() const { return is_experimental_; }
+
+ uint32 ensemble_version() const;
+
+ private:
+ bool is_experimental_;
+
+ CourgetteConfig();
+
+ friend struct DefaultSingletonTraits<CourgetteConfig>;
+};
+
+} // namespace courgette
+
+#endif // COURGETTE_COURGETTE_CONFIG_H_
diff --git a/courgette/courgette_tool.cc b/courgette/courgette_tool.cc
index 962e078..eb3e823 100644
--- a/courgette/courgette_tool.cc
+++ b/courgette/courgette_tool.cc
@@ -15,6 +15,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "courgette/courgette.h"
+#include "courgette/courgette_config.h"
#include "courgette/streams.h"
#include "courgette/third_party/bsdiff.h"
@@ -429,6 +430,7 @@ int main(int argc, const char* argv[]) {
base::CommandLine::Init(argc, argv);
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
+ courgette::CourgetteConfig::GetInstance()->Initialize(command_line);
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_ALL;
@@ -470,6 +472,10 @@ int main(int argc, const char* argv[]) {
" -supported -asm, -dis, -disadj, -gen or -apply, -genbsdiff"
" or -applybsdiff.");
+ if (courgette::CourgetteConfig::GetInstance()->is_experimental()) {
+ fprintf(stderr, "Experimental flag enabled. Do not use in production.\n");
+ }
+
while (repeat_count-- > 0) {
if (cmd_sup) {
if (values.size() != 1)
diff --git a/courgette/ensemble_apply.cc b/courgette/ensemble_apply.cc
index 121fae8..62297fd 100644
--- a/courgette/ensemble_apply.cc
+++ b/courgette/ensemble_apply.cc
@@ -10,6 +10,7 @@
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
+#include "courgette/courgette_config.h"
#include "courgette/crc.h"
#include "courgette/patcher_x86_32.h"
#include "courgette/region.h"
@@ -96,7 +97,9 @@ Status EnsemblePatchApplication::ReadHeader(SourceStream* header_stream) {
if (!header_stream->ReadVarint32(&version))
return C_BAD_ENSEMBLE_VERSION;
- if (version != CourgettePatchFile::kVersion)
+ uint32 expected_ensemble_version =
+ CourgetteConfig::GetInstance()->ensemble_version();
+ if (version != expected_ensemble_version)
return C_BAD_ENSEMBLE_VERSION;
if (!header_stream->ReadVarint32(&source_checksum_))
@@ -426,4 +429,4 @@ Status ApplyEnsemblePatch(const base::FilePath::CharType* old_file_name,
return C_OK;
}
-} // namespace
+} // namespace courgette
diff --git a/courgette/ensemble_create.cc b/courgette/ensemble_create.cc
index ea5873c..a0c2e0b 100644
--- a/courgette/ensemble_create.cc
+++ b/courgette/ensemble_create.cc
@@ -21,6 +21,7 @@
#include "base/logging.h"
#include "base/time/time.h"
+#include "courgette/courgette_config.h"
#include "courgette/crc.h"
#include "courgette/difference_estimator.h"
#include "courgette/region.h"
@@ -435,8 +436,10 @@ Status GenerateEnsemblePatch(SourceStream* base,
//
// Final output stream has a header followed by a StreamSet.
//
+ uint32 ensemble_version =
+ CourgetteConfig::GetInstance()->ensemble_version();
if (!final_patch->WriteVarint32(CourgettePatchFile::kMagic) ||
- !final_patch->WriteVarint32(CourgettePatchFile::kVersion) ||
+ !final_patch->WriteVarint32(ensemble_version) ||
!final_patch->WriteVarint32(CalculateCrc(old_region.start(),
old_region.length())) ||
!final_patch->WriteVarint32(CalculateCrc(new_region.start(),
@@ -452,4 +455,4 @@ Status GenerateEnsemblePatch(SourceStream* base,
return C_OK;
}
-} // namespace
+} // namespace courgette