diff options
author | mad@google.com <mad@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-27 16:23:14 +0000 |
---|---|---|
committer | mad@google.com <mad@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-27 16:23:14 +0000 |
commit | ae393ec70a52e34e9f17536faf1889b69d767b3a (patch) | |
tree | 3ae0d5993ce400117f79885ebdda8b539f82637e /chrome | |
parent | 3530cd9023fed0204e7df17b11f121d89ca6303a (diff) | |
download | chromium_src-ae393ec70a52e34e9f17536faf1889b69d767b3a.zip chromium_src-ae393ec70a52e34e9f17536faf1889b69d767b3a.tar.gz chromium_src-ae393ec70a52e34e9f17536faf1889b69d767b3a.tar.bz2 |
Cleanup some unncessary dependencies on libxml.
As working on change committed in rev50132, instead of yet adding another project to the dependency list of libxml, I decided to abstract the dependency in the metrics helper.
BUG=0
TEST=None
Review URL: http://codereview.chromium.org/2753010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50952 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/metrics/metrics_service.cc | 3 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service.h | 6 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 | ||||
-rw-r--r-- | chrome/chrome_installer_util.gypi | 1 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 3 | ||||
-rw-r--r-- | chrome/common/metrics_helpers.cc | 120 | ||||
-rw-r--r-- | chrome/common/metrics_helpers.h | 10 | ||||
-rw-r--r-- | chrome/test/interactive_ui/interactive_ui_tests.gypi | 1 |
8 files changed, 84 insertions, 62 deletions
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index 21c1789..c158226 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -187,6 +187,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "webkit/glue/plugins/plugin_list.h" +#include "libxml/xmlwriter.h" #if !defined(OS_WIN) #include "base/rand_util.h" @@ -700,7 +701,7 @@ void MetricsService::InitializeMetricsState() { // Initialize uptime counters. int64 startup_uptime = MetricsLog::GetIncrementalUptime(pref); - DCHECK(0 == startup_uptime); + DCHECK_EQ(0, startup_uptime); // For backwards compatibility, leave this intact in case Omaha is checking // them. prefs::kStabilityLastTimestampSec may also be useless now. // TODO(jar): Delete these if they have no uses. diff --git a/chrome/browser/metrics/metrics_service.h b/chrome/browser/metrics/metrics_service.h index 016640d..de6b6ba 100644 --- a/chrome/browser/metrics/metrics_service.h +++ b/chrome/browser/metrics/metrics_service.h @@ -36,6 +36,12 @@ class HistogramSynchronizer; class PrefService; class TemplateURLModel; +// Forward declaration of the xmlNode to avoid having tons of gyp files +// needing to depend on the libxml third party lib. +struct _xmlNode; +typedef struct _xmlNode xmlNode; +typedef xmlNode* xmlNodePtr; + // This is used to quickly log stats from child process related notifications in // MetricsService::child_stats_buffer_. The buffer's contents are transferred // out when Local State is periodically saved. The information is then diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index b609d73..0c6726d 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -569,7 +569,6 @@ '../skia/skia.gyp:skia', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', - '../third_party/libxml/libxml.gyp:libxml', '../third_party/npapi/npapi.gyp:npapi', '../third_party/hunspell/hunspell.gyp:hunspell', '../webkit/support/webkit_support.gyp:glue', @@ -1591,7 +1590,6 @@ '../third_party/icu/icu.gyp:*', '../third_party/libjpeg/libjpeg.gyp:*', '../third_party/libpng/libpng.gyp:*', - '../third_party/libxml/libxml.gyp:*', '../third_party/libxslt/libxslt.gyp:*', '../third_party/lzma_sdk/lzma_sdk.gyp:*', '../third_party/modp_b64/modp_b64.gyp:*', diff --git a/chrome/chrome_installer_util.gypi b/chrome/chrome_installer_util.gypi index f36a559..a7dac66 100644 --- a/chrome/chrome_installer_util.gypi +++ b/chrome/chrome_installer_util.gypi @@ -80,7 +80,6 @@ '<(DEPTH)/third_party/bspatch/bspatch.gyp:bspatch', '<(DEPTH)/third_party/icu/icu.gyp:icui18n', '<(DEPTH)/third_party/icu/icu.gyp:icuuc', - '<(DEPTH)/third_party/libxml/libxml.gyp:libxml', '<(DEPTH)/third_party/lzma_sdk/lzma_sdk.gyp:lzma_sdk', ], 'sources': [ diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 3c4ba96..10c8633 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -464,7 +464,6 @@ '../testing/gtest.gyp:gtest', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', - '../third_party/libxml/libxml.gyp:libxml', ], 'include_dirs': [ '..', @@ -1984,7 +1983,6 @@ '../testing/gtest.gyp:gtest', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', - '../third_party/libxml/libxml.gyp:libxml', '../third_party/npapi/npapi.gyp:npapi', '../third_party/WebKit/WebKit/chromium/WebKit.gyp:webkit', ], @@ -2094,7 +2092,6 @@ 'test_support_ui', '../skia/skia.gyp:skia', '../testing/gtest.gyp:gtest', - '../third_party/libxml/libxml.gyp:libxml', '../third_party/libxslt/libxslt.gyp:libxslt', '../third_party/npapi/npapi.gyp:npapi', ], diff --git a/chrome/common/metrics_helpers.cc b/chrome/common/metrics_helpers.cc index 99cda5a..68f9083 100644 --- a/chrome/common/metrics_helpers.cc +++ b/chrome/common/metrics_helpers.cc @@ -23,6 +23,7 @@ #include "base/third_party/nspr/prtime.h" #include "chrome/common/logging_chrome.h" #include "googleurl/src/gurl.h" +#include "libxml/xmlwriter.h" #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) @@ -34,67 +35,98 @@ using base::TimeDelta; extern "C" IMAGE_DOS_HEADER __ImageBase; #endif -// static -std::string MetricsLogBase::version_extension_; +namespace { // libxml take xmlChar*, which is unsigned char* inline const unsigned char* UnsignedChar(const char* input) { return reinterpret_cast<const unsigned char*>(input); } +} // namespace + +class MetricsLogBase::XmlWrapper { + public: + XmlWrapper() + : doc_(NULL), + buffer_(NULL), + writer_(NULL) { + buffer_ = xmlBufferCreate(); + DCHECK(buffer_); + + #if defined(OS_CHROMEOS) + writer_ = xmlNewTextWriterDoc(&doc_, /* compression */ 0); + #else + writer_ = xmlNewTextWriterMemory(buffer_, /* compression */ 0); + #endif // OS_CHROMEOS + DCHECK(writer_); + + int result = xmlTextWriterSetIndent(writer_, 2); + DCHECK_EQ(0, result); + } + + ~XmlWrapper() { + FreeDocWriter(); + if (buffer_) { + xmlBufferFree(buffer_); + buffer_ = NULL; + } + } + + void FreeDocWriter() { + if (writer_) { + xmlFreeTextWriter(writer_); + writer_ = NULL; + } + if (doc_) { + xmlFreeDoc(doc_); + doc_ = NULL; + } + } + + xmlDocPtr doc() const { return doc_; } + xmlTextWriterPtr writer() const { return writer_; } + xmlBufferPtr buffer() const { return buffer_; } + + private: + xmlDocPtr doc_; + xmlBufferPtr buffer_; + xmlTextWriterPtr writer_; +}; + +// static +std::string MetricsLogBase::version_extension_; + MetricsLogBase::MetricsLogBase(const std::string& client_id, int session_id, const std::string& version_string) : start_time_(Time::Now()), client_id_(client_id), session_id_(IntToString(session_id)), locked_(false), - doc_(NULL), - buffer_(NULL), - writer_(NULL), + xml_wrapper_(new XmlWrapper), num_events_(0) { - buffer_ = xmlBufferCreate(); - DCHECK(buffer_); - - #if defined(OS_CHROMEOS) - writer_ = xmlNewTextWriterDoc(&doc_, /* compression */ 0); - #else - writer_ = xmlNewTextWriterMemory(buffer_, /* compression */ 0); - #endif // OS_CHROMEOS - DCHECK(writer_); - - int result = xmlTextWriterSetIndent(writer_, 2); - DCHECK_EQ(0, result); - StartElement("log"); WriteAttribute("clientid", client_id_); WriteInt64Attribute("buildtime", GetBuildTime()); WriteAttribute("appversion", version_string); - - DCHECK_GE(result, 0); } MetricsLogBase::~MetricsLogBase() { - FreeDocWriter(); - - if (buffer_) { - xmlBufferFree(buffer_); - buffer_ = NULL; - } + delete xml_wrapper_; } void MetricsLogBase::CloseLog() { DCHECK(!locked_); locked_ = true; - int result = xmlTextWriterEndDocument(writer_); + int result = xmlTextWriterEndDocument(xml_wrapper_->writer()); DCHECK_GE(result, 0); - result = xmlTextWriterFlush(writer_); + result = xmlTextWriterFlush(xml_wrapper_->writer()); DCHECK_GE(result, 0); #if defined(OS_CHROMEOS) - xmlNodePtr root = xmlDocGetRootElement(doc_); + xmlNodePtr root = xmlDocGetRootElement(xml_wrapper_->doc()); if (!hardware_class_.empty()) { // The hardware class is determined after the first ongoing log is // constructed, so this adds the root element's "hardwareclass" @@ -105,19 +137,20 @@ void MetricsLogBase::CloseLog() { // Flattens the XML tree into a character buffer. PerfTimer dump_timer; - result = xmlNodeDump(buffer_, doc_, root, /* level */ 0, /* format */ 1); + result = xmlNodeDump(xml_wrapper_->buffer(), xml_wrapper_->doc(), + root, /* level */ 0, /* format */ 1); DCHECK_GE(result, 0); UMA_HISTOGRAM_TIMES("UMA.XMLNodeDumpTime", dump_timer.Elapsed()); PerfTimer free_timer; - FreeDocWriter(); + xml_wrapper_->FreeDocWriter(); UMA_HISTOGRAM_TIMES("UMA.XMLWriterDestructionTime", free_timer.Elapsed()); #endif // OS_CHROMEOS } int MetricsLogBase::GetEncodedLogSize() { DCHECK(locked_); - return buffer_->use; + return xml_wrapper_->buffer()->use; } bool MetricsLogBase::GetEncodedLog(char* buffer, int buffer_size) { @@ -125,13 +158,13 @@ bool MetricsLogBase::GetEncodedLog(char* buffer, int buffer_size) { if (buffer_size < GetEncodedLogSize()) return false; - memcpy(buffer, buffer_->content, GetEncodedLogSize()); + memcpy(buffer, xml_wrapper_->buffer()->content, GetEncodedLogSize()); return true; } std::string MetricsLogBase::GetEncodedLogString() { DCHECK(locked_); - return std::string(reinterpret_cast<char*>(buffer_->content)); + return std::string(reinterpret_cast<char*>(xml_wrapper_->buffer()->content)); } int MetricsLogBase::GetElapsedSeconds() { @@ -285,7 +318,7 @@ void MetricsLogBase::WriteAttribute(const std::string& name, DCHECK(!locked_); DCHECK(!name.empty()); - int result = xmlTextWriterWriteAttribute(writer_, + int result = xmlTextWriterWriteAttribute(xml_wrapper_->writer(), UnsignedChar(name.c_str()), UnsignedChar(value.c_str())); DCHECK_GE(result, 0); @@ -314,30 +347,19 @@ const char* MetricsLogBase::WindowEventTypeToString(WindowEventType type) { } } -void MetricsLogBase::FreeDocWriter() { - if (writer_) { - xmlFreeTextWriter(writer_); - writer_ = NULL; - } - - if (doc_) { - xmlFreeDoc(doc_); - doc_ = NULL; - } -} - void MetricsLogBase::StartElement(const char* name) { DCHECK(!locked_); DCHECK(name); - int result = xmlTextWriterStartElement(writer_, UnsignedChar(name)); + int result = xmlTextWriterStartElement(xml_wrapper_->writer(), + UnsignedChar(name)); DCHECK_GE(result, 0); } void MetricsLogBase::EndElement() { DCHECK(!locked_); - int result = xmlTextWriterEndElement(writer_); + int result = xmlTextWriterEndElement(xml_wrapper_->writer()); DCHECK_GE(result, 0); } diff --git a/chrome/common/metrics_helpers.h b/chrome/common/metrics_helpers.h index 61f3d70..6d8b27e 100644 --- a/chrome/common/metrics_helpers.h +++ b/chrome/common/metrics_helpers.h @@ -17,8 +17,6 @@ #include "base/time.h" #include "chrome/common/page_transition_types.h" -#include "libxml/xmlwriter.h" - class GURL; class MetricsLog; @@ -105,6 +103,8 @@ class MetricsLogBase { } protected: + class XmlWrapper; + // Returns a string containing the current time. // Virtual so that it can be overridden for testing. virtual std::string GetCurrentTimeString(); @@ -165,9 +165,9 @@ class MetricsLogBase { // not a real lock. bool locked_; - xmlDocPtr doc_; - xmlBufferPtr buffer_; - xmlTextWriterPtr writer_; + // Isolated to limit the dependency on the XML library for our consumers. + XmlWrapper* xml_wrapper_; + int num_events_; // the number of events recorded in this log DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); diff --git a/chrome/test/interactive_ui/interactive_ui_tests.gypi b/chrome/test/interactive_ui/interactive_ui_tests.gypi index a7f1a8d..65cec5f 100644 --- a/chrome/test/interactive_ui/interactive_ui_tests.gypi +++ b/chrome/test/interactive_ui/interactive_ui_tests.gypi @@ -17,7 +17,6 @@ '<(DEPTH)/skia/skia.gyp:skia', '<(DEPTH)/third_party/icu/icu.gyp:icui18n', '<(DEPTH)/third_party/libpng/libpng.gyp:libpng', - '<(DEPTH)/third_party/libxml/libxml.gyp:libxml', '<(DEPTH)/third_party/zlib/zlib.gyp:zlib', '<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/third_party/npapi/npapi.gyp:npapi', |