diff options
54 files changed, 246 insertions, 298 deletions
diff --git a/base/base.gyp b/base/base.gyp index 6a7cfd4..d952161 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -144,6 +144,7 @@ 'md5_unittest.cc', 'memory/linked_ptr_unittest.cc', 'memory/mru_cache_unittest.cc', + 'memory/ref_counted_memory_unittest.cc', 'memory/ref_counted_unittest.cc', 'memory/scoped_ptr_unittest.cc', 'memory/scoped_vector_unittest.cc', diff --git a/base/base64.cc b/base/base64.cc index 56a577d..62bd12d 100644 --- a/base/base64.cc +++ b/base/base64.cc @@ -8,7 +8,7 @@ namespace base { -bool Base64Encode(const std::string& input, std::string* output) { +bool Base64Encode(const StringPiece& input, std::string* output) { std::string temp; temp.resize(modp_b64_encode_len(input.size())); // makes room for null byte @@ -23,7 +23,7 @@ bool Base64Encode(const std::string& input, std::string* output) { return true; } -bool Base64Decode(const std::string& input, std::string* output) { +bool Base64Decode(const StringPiece& input, std::string* output) { std::string temp; temp.resize(modp_b64_decode_len(input.size())); diff --git a/base/base64.h b/base/base64.h index 294fb83..e966ea7 100644 --- a/base/base64.h +++ b/base/base64.h @@ -9,16 +9,17 @@ #include <string> #include "base/base_api.h" +#include "base/string_piece.h" namespace base { // Encodes the input string in base64. Returns true if successful and false // otherwise. The output string is only modified if successful. -BASE_API bool Base64Encode(const std::string& input, std::string* output); +BASE_API bool Base64Encode(const StringPiece& input, std::string* output); // Decodes the base64 input string. Returns true if successful and false // otherwise. The output string is only modified if successful. -BASE_API bool Base64Decode(const std::string& input, std::string* output); +BASE_API bool Base64Decode(const StringPiece& input, std::string* output); } // namespace base diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc index cc8c49c..d467055 100644 --- a/base/debug/trace_event.cc +++ b/base/debug/trace_event.cc @@ -12,6 +12,7 @@ #include "base/process_util.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" +#include "base/stl_util.h" #include "base/time.h" #define USE_UNRELIABLE_NOW @@ -170,9 +171,9 @@ TraceEvent::TraceEvent(unsigned long process_id, alloc_size += GetAllocLength(arg2_val.as_string()); if (alloc_size) { - parameter_copy_storage_ = new RefCountedBytes; - parameter_copy_storage_->data.resize(alloc_size); - char* ptr = reinterpret_cast<char*>(¶meter_copy_storage_->data[0]); + parameter_copy_storage_ = new base::RefCountedString; + parameter_copy_storage_->data().resize(alloc_size); + char* ptr = string_as_array(¶meter_copy_storage_->data()); const char* end = ptr + alloc_size; if (copy) { CopyTraceEventParameter(&ptr, &name_, end); diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h index 11b8318..d1c7418 100644 --- a/base/debug/trace_event.h +++ b/base/debug/trace_event.h @@ -278,10 +278,10 @@ INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \ } -class RefCountedBytes; - namespace base { +class RefCountedString; + namespace debug { // Categories allow enabling/disabling of streams of trace events @@ -438,7 +438,7 @@ class TraceEvent { const char* name_; const char* arg_names_[kTraceMaxNumArgs]; TraceValue arg_values_[kTraceMaxNumArgs]; - scoped_refptr<RefCountedBytes> parameter_copy_storage_; + scoped_refptr<base::RefCountedString> parameter_copy_storage_; }; diff --git a/base/memory/ref_counted_memory.cc b/base/memory/ref_counted_memory.cc index aa16031..7e034f9 100644 --- a/base/memory/ref_counted_memory.cc +++ b/base/memory/ref_counted_memory.cc @@ -4,6 +4,8 @@ #include "base/memory/ref_counted_memory.h" +#include "base/logging.h" + RefCountedMemory::RefCountedMemory() { } @@ -22,25 +24,49 @@ RefCountedBytes::RefCountedBytes() { } RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer) - : data(initializer) { + : data_(initializer) { } RefCountedBytes* RefCountedBytes::TakeVector( std::vector<unsigned char>* to_destroy) { RefCountedBytes* bytes = new RefCountedBytes; - bytes->data.swap(*to_destroy); + bytes->data_.swap(*to_destroy); return bytes; } const unsigned char* RefCountedBytes::front() const { // STL will assert if we do front() on an empty vector, but calling code // expects a NULL. - return size() ? &data.front() : NULL; + return size() ? &data_.front() : NULL; } size_t RefCountedBytes::size() const { - return data.size(); + return data_.size(); } RefCountedBytes::~RefCountedBytes() { } + +namespace base { + +RefCountedString::RefCountedString() {} + +RefCountedString::~RefCountedString() {} + +// static +RefCountedString* RefCountedString::TakeString(std::string* to_destroy) { + RefCountedString* self = new RefCountedString; + to_destroy->swap(self->data_); + return self; +} + +const unsigned char* RefCountedString::front() const { + return data_.empty() ? NULL : + reinterpret_cast<const unsigned char*>(data_.data()); +} + +size_t RefCountedString::size() const { + return data_.size(); +} + +} // namespace base diff --git a/base/memory/ref_counted_memory.h b/base/memory/ref_counted_memory.h index 1a0f51ee..7438d57 100644 --- a/base/memory/ref_counted_memory.h +++ b/base/memory/ref_counted_memory.h @@ -6,9 +6,11 @@ #define BASE_MEMORY_REF_COUNTED_MEMORY_H_ #pragma once +#include <string> #include <vector> #include "base/base_api.h" +#include "base/compiler_specific.h" #include "base/memory/ref_counted.h" // TODO(erg): The contents of this file should be in a namespace. This would @@ -40,11 +42,11 @@ class BASE_API RefCountedStaticMemory : public RefCountedMemory { RefCountedStaticMemory() : data_(NULL), length_(0) {} RefCountedStaticMemory(const unsigned char* data, size_t length) - : data_(data), length_(length) {} + : data_(length ? data : NULL), length_(length) {} - // Overriden from RefCountedMemory: - virtual const unsigned char* front() const; - virtual size_t size() const; + // Overridden from RefCountedMemory: + virtual const unsigned char* front() const OVERRIDE; + virtual size_t size() const OVERRIDE; private: const unsigned char* data_; @@ -67,18 +69,51 @@ class BASE_API RefCountedBytes : public RefCountedMemory { // vector.) static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy); - // Overriden from RefCountedMemory: - virtual const unsigned char* front() const; - virtual size_t size() const; + // Overridden from RefCountedMemory: + virtual const unsigned char* front() const OVERRIDE; + virtual size_t size() const OVERRIDE; - std::vector<unsigned char> data; + const std::vector<unsigned char>& data() const { return data_; } + std::vector<unsigned char>& data() { return data_; } - protected: + private: friend class base::RefCountedThreadSafe<RefCountedBytes>; virtual ~RefCountedBytes(); - private: + std::vector<unsigned char> data_; + DISALLOW_COPY_AND_ASSIGN(RefCountedBytes); }; +namespace base { + +// An implementation of RefCountedMemory, where the bytes are stored in an STL +// string. Use this if your data naturally arrives in that format. +class BASE_API RefCountedString : public RefCountedMemory { + public: + RefCountedString(); + + // Constructs a RefCountedString object by performing a swap. (To non + // destructively build a RefCountedString, use the default constructor and + // copy into object->data()). + static RefCountedString* TakeString(std::string* to_destroy); + + // Overridden from RefCountedMemory: + virtual const unsigned char* front() const OVERRIDE; + virtual size_t size() const OVERRIDE; + + const std::string& data() const { return data_; } + std::string& data() { return data_; } + + private: + friend class base::RefCountedThreadSafe<RefCountedString>; + virtual ~RefCountedString(); + + std::string data_; + + DISALLOW_COPY_AND_ASSIGN(RefCountedString); +}; + +} // namespace base + #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ diff --git a/base/memory/ref_counted_memory_unittest.cc b/base/memory/ref_counted_memory_unittest.cc new file mode 100644 index 0000000..1936040 --- /dev/null +++ b/base/memory/ref_counted_memory_unittest.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2011 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 "base/memory/ref_counted_memory.h" + +#include "testing/gtest/include/gtest/gtest.h" + +namespace base { + +TEST(RefCountedMemoryUnitTest, RefCountedStaticMemory) { + scoped_refptr<RefCountedMemory> mem = new RefCountedStaticMemory( + reinterpret_cast<const uint8*>("static mem00"), 10); + + EXPECT_EQ(10U, mem->size()); + EXPECT_EQ("static mem", + std::string(reinterpret_cast<const char*>(mem->front()), + mem->size())); +} + +TEST(RefCountedMemoryUnitTest, RefCountedBytes) { + std::vector<uint8> data; + data.push_back(45); + data.push_back(99); + scoped_refptr<RefCountedMemory> mem = RefCountedBytes::TakeVector(&data); + + EXPECT_EQ(0U, data.size()); + + EXPECT_EQ(2U, mem->size()); + EXPECT_EQ(45U, mem->front()[0]); + EXPECT_EQ(99U, mem->front()[1]); +} + +TEST(RefCountedMemoryUnitTest, RefCountedString) { + std::string s("destroy me"); + scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); + + EXPECT_EQ(0U, s.size()); + + EXPECT_EQ(10U, mem->size()); + EXPECT_EQ('d', mem->front()[0]); + EXPECT_EQ('e', mem->front()[1]); +} + +} // namespace base diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 95785ff..f8cfcbf 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -1421,10 +1421,8 @@ void AboutSource::StartDataRequest(const std::string& path, } void AboutSource::FinishDataRequest(const std::string& html, int request_id) { - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(html.size()); - std::copy(html.begin(), html.end(), html_bytes->data.begin()); - SendResponse(request_id, html_bytes); + std::string html_copy(html); + SendResponse(request_id, base::RefCountedString::TakeString(&html_copy)); } std::string AboutSource::GetMimeType(const std::string& path) const { diff --git a/chrome/browser/browser_signin.cc b/chrome/browser/browser_signin.cc index ec1a0fb..8f4bbd61 100644 --- a/chrome/browser/browser_signin.cc +++ b/chrome/browser/browser_signin.cc @@ -4,7 +4,6 @@ #include "chrome/browser/browser_signin.h" -#include <algorithm> #include <string> #include <vector> @@ -68,10 +67,7 @@ void BrowserSigninResourcesSource::StartDataRequest(const std::string& path, response = jstemplate_builder::GetI18nTemplateHtml(html, &dict); } - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(response.size()); - std::copy(response.begin(), response.end(), html_bytes->data.begin()); - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&response)); } class BrowserSigninHtml : public HtmlDialogUIDelegate, diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index c546adf..f7d2dea 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -9,6 +9,7 @@ #include "base/base64.h" #include "base/memory/ref_counted_memory.h" +#include "base/stl_util.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/stringprintf.h" @@ -1264,7 +1265,7 @@ void CaptureVisibleTabFunction::Observe(int type, // and call SendResponse(). void CaptureVisibleTabFunction::SendResultFromBitmap( const SkBitmap& screen_capture) { - scoped_refptr<RefCountedBytes> image_data(new RefCountedBytes); + std::vector<unsigned char> data; SkAutoLockPixels screen_capture_lock(screen_capture); bool encoded = false; std::string mime_type; @@ -1277,14 +1278,14 @@ void CaptureVisibleTabFunction::SendResultFromBitmap( screen_capture.height(), static_cast<int>(screen_capture.rowBytes()), image_quality_, - &image_data->data); + &data); mime_type = keys::kMimeTypeJpeg; break; case FORMAT_PNG: encoded = gfx::PNGCodec::EncodeBGRASkBitmap( screen_capture, true, // Discard transparency. - &image_data->data); + &data); mime_type = keys::kMimeTypePng; break; default: @@ -1298,11 +1299,8 @@ void CaptureVisibleTabFunction::SendResultFromBitmap( } std::string base64_result; - std::string stream_as_string; - stream_as_string.resize(image_data->data.size()); - memcpy(&stream_as_string[0], - reinterpret_cast<const char*>(&image_data->data[0]), - image_data->data.size()); + base::StringPiece stream_as_string( + reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); base::Base64Encode(stream_as_string, &base64_result); base64_result.insert(0, base::StringPrintf("data:%s;base64,", diff --git a/chrome/browser/favicon/favicon_handler_unittest.cc b/chrome/browser/favicon/favicon_handler_unittest.cc index c2cc69a..a76192d 100644 --- a/chrome/browser/favicon/favicon_handler_unittest.cc +++ b/chrome/browser/favicon/favicon_handler_unittest.cc @@ -329,7 +329,7 @@ TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { history_handler->favicon_data_.expired = false; history_handler->favicon_data_.icon_url = icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data); + FillBitmap(kFaviconSize, kFaviconSize, &data->data()); history_handler->favicon_data_.image_data = data; // Send history response. @@ -442,7 +442,7 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { history_handler->favicon_data_.expired = false; history_handler->favicon_data_.icon_url = icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data); + FillBitmap(kFaviconSize, kFaviconSize, &data->data()); history_handler->favicon_data_.image_data = data; // Send history response. @@ -529,7 +529,7 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) { history_handler->favicon_data_.expired = false; history_handler->favicon_data_.icon_url = icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data); + FillBitmap(kFaviconSize, kFaviconSize, &data->data()); history_handler->favicon_data_.image_data = data; // Send history response. @@ -671,7 +671,7 @@ TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { history_handler->favicon_data_.expired = true; history_handler->favicon_data_.icon_url = new_icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data); + FillBitmap(kFaviconSize, kFaviconSize, &data->data()); history_handler->favicon_data_.image_data = data; history_handler->InvokeCallback(); @@ -800,7 +800,7 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { handler->favicon_data_.icon_type = history::TOUCH_ICON; handler->favicon_data_.icon_url = latest_icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data); + FillBitmap(kFaviconSize, kFaviconSize, &data->data()); handler->favicon_data_.image_data = data; handler->InvokeCallback(); diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index 5da8424..0da92cc 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -1511,19 +1511,19 @@ void HistoryBackend::GetPageThumbnailDirectly( if (GetMostRecentRedirectsFrom(page_url, &redirects) && !redirects.empty()) { if ((url_id = db_->GetRowForURL(redirects.back(), NULL))) - success = thumbnail_db_->GetPageThumbnail(url_id, &(*data)->data); + success = thumbnail_db_->GetPageThumbnail(url_id, &(*data)->data()); } // If we don't have a thumbnail from redirects, try the URL directly. if (!success) { if ((url_id = db_->GetRowForURL(page_url, NULL))) - success = thumbnail_db_->GetPageThumbnail(url_id, &(*data)->data); + success = thumbnail_db_->GetPageThumbnail(url_id, &(*data)->data()); } // In this rare case, we start to mine the older redirect sessions // from the visit table to try to find a thumbnail. if (!success) { - success = GetThumbnailFromOlderRedirect(page_url, &(*data)->data); + success = GetThumbnailFromOlderRedirect(page_url, &(*data)->data()); } if (!success) @@ -1693,7 +1693,7 @@ void HistoryBackend::UpdateFaviconMappingAndFetchImpl( scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); favicon.known_icon = true; Time last_updated; - if (thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data->data, + if (thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data->data(), NULL)) { favicon.expired = (Time::Now() - last_updated) > TimeDelta::FromDays(kFaviconRefetchDays); @@ -1729,7 +1729,7 @@ void HistoryBackend::GetFaviconForURL( if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) && (icon_mappings.front().icon_type & icon_types) && thumbnail_db_->GetFavicon(icon_mappings.front().icon_id, &last_updated, - &data->data, &favicon.icon_url)) { + &data->data(), &favicon.icon_url)) { favicon.known_icon = true; favicon.expired = (Time::Now() - last_updated) > TimeDelta::FromDays(kFaviconRefetchDays); diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc index 1c6f67f..efd2f8d 100644 --- a/chrome/browser/history/top_sites.cc +++ b/chrome/browser/history/top_sites.cc @@ -605,8 +605,9 @@ bool TopSites::EncodeBitmap(const SkBitmap& bitmap, return false; } // As we're going to cache this data, make sure the vector is only as big as - // it needs to be. - (*bytes)->data = data; + // it needs to be, as JPEGCodec::Encode() over-allocates data.capacity(). + // (In a C++0x future, we can just call shrink_to_fit() in Encode()) + (*bytes)->data() = data; return true; } diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc index ee487c32..3ddbfca 100644 --- a/chrome/browser/history/top_sites_unittest.cc +++ b/chrome/browser/history/top_sites_unittest.cc @@ -108,7 +108,7 @@ class TopSitesQuerier { // thumbnail data, which is stored as jpgs. SkBitmap ExtractThumbnail(const RefCountedBytes& t1) { scoped_ptr<SkBitmap> image(gfx::JPEGCodec::Decode(t1.front(), - t1.data.size())); + t1.size())); return image.get() ? *image : SkBitmap(); } @@ -116,11 +116,11 @@ SkBitmap ExtractThumbnail(const RefCountedBytes& t1) { bool ThumbnailsAreEqual(RefCountedBytes* t1, RefCountedBytes* t2) { if (!t1 || !t2) return false; - if (t1->data.size() != t2->data.size()) + if (t1->size() != t2->size()) return false; - return std::equal(t1->data.begin(), - t1->data.end(), - t2->data.begin()); + return std::equal(t1->data().begin(), + t1->data().end(), + t2->data().begin()); } } // namespace diff --git a/chrome/browser/printing/cloud_print/cloud_print_setup_source.cc b/chrome/browser/printing/cloud_print/cloud_print_setup_source.cc index 4544ff80..06976db 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_setup_source.cc +++ b/chrome/browser/printing/cloud_print/cloud_print_setup_source.cc @@ -4,8 +4,6 @@ #include "chrome/browser/printing/cloud_print/cloud_print_setup_source.h" -#include <algorithm> - #include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "base/values.h" @@ -119,11 +117,8 @@ void CloudPrintSetupSource::StartDataRequest(const std::string& path_raw, .GetRawDataResource(IDR_CLOUD_PRINT_SETUP_FLOW_HTML)); response = html.as_string(); } - // Send the response. - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(response.size()); - std::copy(response.begin(), response.end(), html_bytes->data.begin()); - SendResponse(request_id, html_bytes); + + SendResponse(request_id, base::RefCountedString::TakeString(&response)); } std::string CloudPrintSetupSource::GetMimeType(const std::string& path) const { diff --git a/chrome/browser/printing/print_preview_message_handler.cc b/chrome/browser/printing/print_preview_message_handler.cc index 99be3f5..75aa54c 100644 --- a/chrome/browser/printing/print_preview_message_handler.cc +++ b/chrome/browser/printing/print_preview_message_handler.cc @@ -141,14 +141,15 @@ void PrintPreviewMessageHandler::OnPagesReadyForPreview( wrapper->print_view_manager()->OverrideTitle(tab_contents()); - char* preview_data = static_cast<char*>(shared_buf->memory()); + const unsigned char* preview_data = + static_cast<unsigned char*>(shared_buf->memory()); uint32 preview_data_size = params.data_size; + // TODO(joth): This seems like a good match for using RefCountedStaticMemory + // to avoid the memory copy, but the SetPrintPreviewData call chain below + // needs updating to accept the RefCountedMemory* base class. scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(preview_data_size); - std::vector<unsigned char>::iterator it = html_bytes->data.begin(); - for (uint32 i = 0; i < preview_data_size; ++i, ++it) - *it = *(preview_data + i); + html_bytes->data().assign(preview_data, preview_data + preview_data_size); print_preview_ui->SetPrintPreviewData(html_bytes.get()); print_preview_ui->OnPreviewDataIsAvailable( diff --git a/chrome/browser/ui/login/login_prompt_ui.cc b/chrome/browser/ui/login/login_prompt_ui.cc index d1d9592..3306ff2 100644 --- a/chrome/browser/ui/login/login_prompt_ui.cc +++ b/chrome/browser/ui/login/login_prompt_ui.cc @@ -46,11 +46,7 @@ class LoginHandlerSource : public ChromeURLDataManager::DataSource { IDR_HTTP_AUTH_HTML)); std::string response = jstemplate_builder::GetI18nTemplateHtml(html, &dict); - // Send the response. - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(response.size()); - std::copy(response.begin(), response.end(), html_bytes->data.begin()); - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&response)); } virtual std::string GetMimeType(const std::string& path) const { diff --git a/chrome/browser/ui/webui/active_downloads_ui.cc b/chrome/browser/ui/webui/active_downloads_ui.cc index 4047c25..59a6db7 100644 --- a/chrome/browser/ui/webui/active_downloads_ui.cc +++ b/chrome/browser/ui/webui/active_downloads_ui.cc @@ -129,14 +129,10 @@ void ActiveDownloadsUIHTMLSource::StartDataRequest(const std::string& path, static const base::StringPiece active_downloads_html( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_ACTIVE_DOWNLOADS_HTML)); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( + std::string full_html = jstemplate_builder::GetI18nTemplateHtml( active_downloads_html, &localized_strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } } // namespace diff --git a/chrome/browser/ui/webui/bug_report_ui.cc b/chrome/browser/ui/webui/bug_report_ui.cc index 62c3ec8..54a78a6 100644 --- a/chrome/browser/ui/webui/bug_report_ui.cc +++ b/chrome/browser/ui/webui/bug_report_ui.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/webui/bug_report_ui.h" -#include <algorithm> #include <vector> #include "base/callback.h" @@ -378,14 +377,10 @@ void BugReportUIHTMLSource::StartDataRequest(const std::string& path, SetFontAndTextDirection(&localized_strings); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( + std::string full_html = jstemplate_builder::GetI18nTemplateHtml( bug_report_html_, &localized_strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } diff --git a/chrome/browser/ui/webui/chrome_web_ui_data_source.cc b/chrome/browser/ui/webui/chrome_web_ui_data_source.cc index 4f74f51..e4ca9b1 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_data_source.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_data_source.cc @@ -54,12 +54,9 @@ void ChromeWebUIDataSource::StartDataRequest(const std::string& path, void ChromeWebUIDataSource::SendLocalizedStringsAsJSON(int request_id) { std::string template_data; - scoped_refptr<RefCountedBytes> response(new RefCountedBytes); SetFontAndTextDirection(&localized_strings_); jstemplate_builder::AppendJsonJS(&localized_strings_, &template_data); - response->data.resize(template_data.size()); - std::copy(template_data.begin(), template_data.end(),response->data.begin()); - SendResponse(request_id, response); + SendResponse(request_id, base::RefCountedString::TakeString(&template_data)); } void ChromeWebUIDataSource::SendFromResourceBundle(int request_id, int idr) { diff --git a/chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.cc b/chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.cc index ca03a93..4f98584 100644 --- a/chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.cc +++ b/chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.cc @@ -122,14 +122,10 @@ void ChooseMobileNetworkHTMLSource::StartDataRequest(const std::string& path, ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_CHOOSE_MOBILE_NETWORK_HTML)); - const std::string& full_html = jstemplate_builder::GetI18nTemplateHtml( - html, &strings); + std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, + &strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes()); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } // ChooseMobileNetworkHandler implementation. diff --git a/chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.cc b/chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.cc index 455fc30..63360fb 100644 --- a/chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.cc +++ b/chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.cc @@ -138,11 +138,7 @@ void EnterpriseEnrollmentDataSource::StartDataRequest(const std::string& path, jstemplate_builder::GetI18nTemplateHtml(html, localized_strings_.get()); } - // Send the response. - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes()); - html_bytes->data.resize(response.size()); - std::copy(response.begin(), response.end(), html_bytes->data.begin()); - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&response)); } std::string EnterpriseEnrollmentDataSource::GetMimeType( diff --git a/chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.cc b/chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.cc index a8fc7c7..e8bdd0b 100644 --- a/chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.cc +++ b/chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.cc @@ -116,14 +116,10 @@ class UIHTMLSource : public ChromeURLDataManager::DataSource { static const base::StringPiece imageburn_html( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_IMAGEBURNER_HTML)); - const std::string full_html = jstemplate_builder::GetTemplatesHtml( + std::string full_html = jstemplate_builder::GetTemplatesHtml( imageburn_html, &localized_strings, "more-info-link"); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } virtual std::string GetMimeType(const std::string&) const { diff --git a/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc b/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc index 58e42b2..62af6f0 100644 --- a/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc +++ b/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc @@ -227,14 +227,10 @@ void KeyboardOverlayUIHTMLSource::StartDataRequest(const std::string& path, static const base::StringPiece keyboard_overlay_html( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_KEYBOARD_OVERLAY_HTML)); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( + std::string full_html = jstemplate_builder::GetI18nTemplateHtml( keyboard_overlay_html, &localized_strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/ui/webui/chromeos/login/login_ui.cc b/chrome/browser/ui/webui/chromeos/login/login_ui.cc index 06723cf..0b83815 100644 --- a/chrome/browser/ui/webui/chromeos/login/login_ui.cc +++ b/chrome/browser/ui/webui/chromeos/login/login_ui.cc @@ -56,10 +56,7 @@ void LoginUIHTMLSource::StartDataRequest(const std::string& path, std::string full_html = html_operations_->GetFullHTML( login_html, localized_strings_.get()); - scoped_refptr<RefCountedBytes> html_bytes( - html_operations_->CreateHTMLBytes(full_html)); - SendResponse(request_id, - (html_bytes.get())); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } std::string LoginUIHTMLSource::GetMimeType(const std::string&) const { diff --git a/chrome/browser/ui/webui/chromeos/login/login_ui_helpers.cc b/chrome/browser/ui/webui/chromeos/login/login_ui_helpers.cc index 6ce4957..980414f 100644 --- a/chrome/browser/ui/webui/chromeos/login/login_ui_helpers.cc +++ b/chrome/browser/ui/webui/chromeos/login/login_ui_helpers.cc @@ -30,14 +30,4 @@ std::string HTMLOperationsInterface::GetFullHTML( localized_strings); } -RefCountedBytes* HTMLOperationsInterface::CreateHTMLBytes( - std::string full_html) { - RefCountedBytes* html_bytes = new RefCountedBytes(); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), - full_html.end(), - html_bytes->data.begin()); - return html_bytes; -} - } // namespace chromeos diff --git a/chrome/browser/ui/webui/chromeos/login/login_ui_helpers.h b/chrome/browser/ui/webui/chromeos/login/login_ui_helpers.h index f438e09..8817348 100644 --- a/chrome/browser/ui/webui/chromeos/login/login_ui_helpers.h +++ b/chrome/browser/ui/webui/chromeos/login/login_ui_helpers.h @@ -11,7 +11,7 @@ #include "base/string_piece.h" class FilePath; -class RefCountedBytes; +class RefCountedMemory; namespace base { class DictionaryValue; @@ -32,7 +32,6 @@ class HTMLOperationsInterface { virtual base::StringPiece GetLoginHTML(); virtual std::string GetFullHTML(base::StringPiece login_html, base::DictionaryValue* localized_strings); - virtual RefCountedBytes* CreateHTMLBytes(std::string full_html); private: DISALLOW_COPY_AND_ASSIGN(HTMLOperationsInterface); diff --git a/chrome/browser/ui/webui/chromeos/login/mock_login_ui_helpers.h b/chrome/browser/ui/webui/chromeos/login/mock_login_ui_helpers.h index 72e1be4..96cea78 100644 --- a/chrome/browser/ui/webui/chromeos/login/mock_login_ui_helpers.h +++ b/chrome/browser/ui/webui/chromeos/login/mock_login_ui_helpers.h @@ -47,8 +47,6 @@ class MockHTMLOperationsInterface MOCK_METHOD2(GetFullHTML, std::string(base::StringPiece login_html, DictionaryValue* localized_strings)); - MOCK_METHOD1(CreateHTMLBytes, - RefCountedBytes*(std::string full_html)); private: DISALLOW_COPY_AND_ASSIGN(MockHTMLOperationsInterface); diff --git a/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc b/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc index 8db052c..23163b7 100644 --- a/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc +++ b/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc @@ -113,11 +113,7 @@ void OobeUIHTMLSource::StartDataRequest(const std::string& path, html, localized_strings_.get()); } - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes()); - html_bytes->data.resize(response.size()); - std::copy(response.begin(), response.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&response)); } // CoreOobeHandler ------------------------------------------------------------ diff --git a/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc b/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc index 79946d7..30b8bef 100644 --- a/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc +++ b/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc @@ -430,14 +430,10 @@ void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path, ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_MOBILE_SETUP_PAGE_HTML)); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( - html, &strings); + std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, + &strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/ui/webui/chromeos/proxy_settings_ui.cc b/chrome/browser/ui/webui/chromeos/proxy_settings_ui.cc index da4e0bd..c06d6c3 100644 --- a/chrome/browser/ui/webui/chromeos/proxy_settings_ui.cc +++ b/chrome/browser/ui/webui/chromeos/proxy_settings_ui.cc @@ -53,14 +53,10 @@ void ProxySettingsHTMLSource::StartDataRequest(const std::string& path, static const base::StringPiece html( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_PROXY_SETTINGS_HTML)); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( + std::string full_html = jstemplate_builder::GetI18nTemplateHtml( html, localized_strings_.get()); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } } // namespace diff --git a/chrome/browser/ui/webui/chromeos/register_page_ui.cc b/chrome/browser/ui/webui/chromeos/register_page_ui.cc index aa13345..5e1a439 100644 --- a/chrome/browser/ui/webui/chromeos/register_page_ui.cc +++ b/chrome/browser/ui/webui/chromeos/register_page_ui.cc @@ -173,16 +173,10 @@ void RegisterPageUIHTMLSource::StartDataRequest(const std::string& path, return; } - static const base::StringPiece register_html( - ResourceBundle::GetSharedInstance().GetRawDataResource( + scoped_refptr<RefCountedMemory> html_bytes( + ResourceBundle::GetSharedInstance().LoadDataResourceBytes( IDR_HOST_REGISTRATION_PAGE_HTML)); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(register_html.size()); - std::copy(register_html.begin(), - register_html.end(), - html_bytes->data.begin()); - SendResponse(request_id, html_bytes); #else scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); diff --git a/chrome/browser/ui/webui/chromeos/sim_unlock_ui.cc b/chrome/browser/ui/webui/chromeos/sim_unlock_ui.cc index dfc5574..0dfd028 100644 --- a/chrome/browser/ui/webui/chromeos/sim_unlock_ui.cc +++ b/chrome/browser/ui/webui/chromeos/sim_unlock_ui.cc @@ -295,14 +295,10 @@ void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path, ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_SIM_UNLOCK_HTML)); - const std::string& full_html = jstemplate_builder::GetI18nTemplateHtml( - html, &strings); + std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, + &strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes()); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } // SimUnlockHandler ------------------------------------------------------------ diff --git a/chrome/browser/ui/webui/chromeos/system_info_ui.cc b/chrome/browser/ui/webui/chromeos/system_info_ui.cc index a72b32d..4128e5f 100644 --- a/chrome/browser/ui/webui/chromeos/system_info_ui.cc +++ b/chrome/browser/ui/webui/chromeos/system_info_ui.cc @@ -140,14 +140,10 @@ void SystemInfoUIHTMLSource::SyslogsComplete( static const base::StringPiece systeminfo_html( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_ABOUT_SYS_HTML)); - const std::string full_html = jstemplate_builder::GetTemplatesHtml( + std::string full_html = jstemplate_builder::GetTemplatesHtml( systeminfo_html, &strings, "t" /* template root node id */); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id_, html_bytes); + SendResponse(request_id_, base::RefCountedString::TakeString(&full_html)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/ui/webui/collected_cookies_ui_delegate.cc b/chrome/browser/ui/webui/collected_cookies_ui_delegate.cc index 51edd3b..ca18acb 100644 --- a/chrome/browser/ui/webui/collected_cookies_ui_delegate.cc +++ b/chrome/browser/ui/webui/collected_cookies_ui_delegate.cc @@ -121,14 +121,10 @@ void CollectedCookiesSource::StartDataRequest(const std::string& path, static const base::StringPiece html( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_COLLECTED_COOKIES_HTML)); - const std::string response = jstemplate_builder::GetI18nTemplateHtml( + std::string response = jstemplate_builder::GetI18nTemplateHtml( html, &localized_strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(response.size()); - std::copy(response.begin(), response.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&response)); } } // namespace diff --git a/chrome/browser/ui/webui/extension_icon_source.cc b/chrome/browser/ui/webui/extension_icon_source.cc index b38c273..78c7b27 100644 --- a/chrome/browser/ui/webui/extension_icon_source.cc +++ b/chrome/browser/ui/webui/extension_icon_source.cc @@ -31,12 +31,8 @@ namespace { scoped_refptr<RefCountedMemory> BitmapToMemory(SkBitmap* image) { - std::vector<unsigned char> output; - gfx::PNGCodec::EncodeBGRASkBitmap(*image, false, &output); - - scoped_refptr<RefCountedBytes> image_bytes(new RefCountedBytes); - image_bytes->data.resize(output.size()); - std::copy(output.begin(), output.end(), image_bytes->data.begin()); + RefCountedBytes* image_bytes = new RefCountedBytes; + gfx::PNGCodec::EncodeBGRASkBitmap(*image, false, &image_bytes->data()); return image_bytes; } diff --git a/chrome/browser/ui/webui/fileicon_source.cc b/chrome/browser/ui/webui/fileicon_source.cc index 94301af..cd5d936 100644 --- a/chrome/browser/ui/webui/fileicon_source.cc +++ b/chrome/browser/ui/webui/fileicon_source.cc @@ -45,7 +45,7 @@ void FileIconSource::StartDataRequest(const std::string& path, if (icon) { scoped_refptr<RefCountedBytes> icon_data(new RefCountedBytes); - gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data); + gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data()); SendResponse(request_id, icon_data); } else { @@ -72,7 +72,7 @@ void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle, if (icon) { scoped_refptr<RefCountedBytes> icon_data(new RefCountedBytes); - gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data); + gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data()); SendResponse(request_id, icon_data); } else { diff --git a/chrome/browser/ui/webui/gpu_internals_ui.cc b/chrome/browser/ui/webui/gpu_internals_ui.cc index ba902f9..36ae3cc 100644 --- a/chrome/browser/ui/webui/gpu_internals_ui.cc +++ b/chrome/browser/ui/webui/gpu_internals_ui.cc @@ -175,11 +175,7 @@ void GpuHTMLSource::StartDataRequest(const std::string& path, jstemplate_builder::AppendJsTemplateSourceHtml(&full_html); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } std::string GpuHTMLSource::GetMimeType(const std::string&) const { diff --git a/chrome/browser/ui/webui/history2_ui.cc b/chrome/browser/ui/webui/history2_ui.cc index ab9385c..4e5fc27 100644 --- a/chrome/browser/ui/webui/history2_ui.cc +++ b/chrome/browser/ui/webui/history2_ui.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/webui/history2_ui.h" -#include <algorithm> #include <set> #include "base/callback.h" @@ -101,14 +100,10 @@ void HistoryUIHTMLSource2::StartDataRequest(const std::string& path, static const base::StringPiece history_html( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_HISTORY2_HTML)); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( + std::string full_html = jstemplate_builder::GetI18nTemplateHtml( history_html, &localized_strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } std::string HistoryUIHTMLSource2::GetMimeType(const std::string&) const { diff --git a/chrome/browser/ui/webui/media/media_internals_ui.cc b/chrome/browser/ui/webui/media/media_internals_ui.cc index 6fc0229..b794ff9 100644 --- a/chrome/browser/ui/webui/media/media_internals_ui.cc +++ b/chrome/browser/ui/webui/media/media_internals_ui.cc @@ -57,11 +57,7 @@ void MediaInternalsHTMLSource::StartDataRequest(const std::string& path, jstemplate_builder::AppendJsonHtml(&localized_strings, &html); jstemplate_builder::AppendI18nTemplateProcessHtml(&html); - scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes()); - bytes->data.resize(html.size()); - std::copy(html.begin(), html.end(), bytes->data.begin()); - - SendResponse(request_id, bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&html)); } std::string MediaInternalsHTMLSource::GetMimeType( diff --git a/chrome/browser/ui/webui/net_internals_ui.cc b/chrome/browser/ui/webui/net_internals_ui.cc index a742d02..69a9261 100644 --- a/chrome/browser/ui/webui/net_internals_ui.cc +++ b/chrome/browser/ui/webui/net_internals_ui.cc @@ -483,19 +483,13 @@ void NetInternalsHTMLSource::StartDataRequest(const std::string& path, jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html); jstemplate_builder::AppendJsTemplateSourceHtml(&full_html); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); return; } - const std::string data_string("<p style='color:red'>Failed to read resource" + + std::string data_string("<p style='color:red'>Failed to read resource" + EscapeForHTML(filename) + "</p>"); - scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes); - bytes->data.resize(data_string.size()); - std::copy(data_string.begin(), data_string.end(), bytes->data.begin()); - SendResponse(request_id, bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&data_string)); } std::string NetInternalsHTMLSource::GetMimeType(const std::string&) const { diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc index 06b02c5..6fdb4cb 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc @@ -452,7 +452,7 @@ void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, return; } - scoped_refptr<RefCountedBytes> html_bytes( + scoped_refptr<RefCountedMemory> html_bytes( NTPResourceCacheFactory::GetForProfile(profile_)-> GetNewTabHTML(is_incognito)); diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc index bf0f990..5b970ea 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc @@ -172,7 +172,7 @@ NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { NTPResourceCache::~NTPResourceCache() {} -RefCountedBytes* NTPResourceCache::GetNewTabHTML(bool is_incognito) { +RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (is_incognito) { if (!new_tab_incognito_html_.get()) @@ -185,7 +185,7 @@ RefCountedBytes* NTPResourceCache::GetNewTabHTML(bool is_incognito) { : new_tab_html_.get(); } -RefCountedBytes* NTPResourceCache::GetNewTabCSS(bool is_incognito) { +RefCountedMemory* NTPResourceCache::GetNewTabCSS(bool is_incognito) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (is_incognito) { if (!new_tab_incognito_css_.get()) @@ -260,10 +260,7 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() { std::string full_html = jstemplate_builder::GetI18nTemplateHtml( incognito_tab_html, &localized_strings); - new_tab_incognito_html_ = new RefCountedBytes; - new_tab_incognito_html_->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), - new_tab_incognito_html_->data.begin()); + new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); } void NTPResourceCache::CreateNewTabHTML() { @@ -440,9 +437,7 @@ void NTPResourceCache::CreateNewTabHTML() { } } - new_tab_html_ = new RefCountedBytes; - new_tab_html_->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), new_tab_html_->data.begin()); + new_tab_html_ = base::RefCountedString::TakeString(&full_html); } void NTPResourceCache::CreateNewTabIncognitoCSS() { @@ -475,10 +470,7 @@ void NTPResourceCache::CreateNewTabIncognitoCSS() { std::string full_css = ReplaceStringPlaceholders( new_tab_theme_css, subst, NULL); - new_tab_incognito_css_ = new RefCountedBytes; - new_tab_incognito_css_->data.resize(full_css.size()); - std::copy(full_css.begin(), full_css.end(), - new_tab_incognito_css_->data.begin()); + new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css); } void NTPResourceCache::CreateNewTabCSS() { @@ -573,8 +565,5 @@ void NTPResourceCache::CreateNewTabCSS() { // Create the string from our template and the replacements. std::string css_string; css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); - new_tab_css_ = new RefCountedBytes; - new_tab_css_->data.resize(css_string.size()); - std::copy(css_string.begin(), css_string.end(), - new_tab_css_->data.begin()); + new_tab_css_ = base::RefCountedString::TakeString(&css_string); } diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.h b/chrome/browser/ui/webui/ntp/ntp_resource_cache.h index c4a10e0..67be6fc 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.h +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.h @@ -14,7 +14,7 @@ #include "content/common/notification_registrar.h" class Profile; -class RefCountedBytes; +class RefCountedMemory; // This class keeps a cache of NTP resources (HTML and CSS) so we don't have to // regenerate them all the time. @@ -24,8 +24,8 @@ class NTPResourceCache : public NotificationObserver, explicit NTPResourceCache(Profile* profile); virtual ~NTPResourceCache(); - RefCountedBytes* GetNewTabHTML(bool is_incognito); - RefCountedBytes* GetNewTabCSS(bool is_incognito); + RefCountedMemory* GetNewTabHTML(bool is_incognito); + RefCountedMemory* GetNewTabCSS(bool is_incognito); // NotificationObserver interface. virtual void Observe(int type, @@ -36,14 +36,14 @@ class NTPResourceCache : public NotificationObserver, Profile* profile_; void CreateNewTabIncognitoHTML(); - scoped_refptr<RefCountedBytes> new_tab_incognito_html_; + scoped_refptr<RefCountedMemory> new_tab_incognito_html_; void CreateNewTabHTML(); - scoped_refptr<RefCountedBytes> new_tab_html_; + scoped_refptr<RefCountedMemory> new_tab_html_; void CreateNewTabIncognitoCSS(); - scoped_refptr<RefCountedBytes> new_tab_incognito_css_; + scoped_refptr<RefCountedMemory> new_tab_incognito_css_; void CreateNewTabCSS(); - scoped_refptr<RefCountedBytes> new_tab_css_; + scoped_refptr<RefCountedMemory> new_tab_css_; NotificationRegistrar registrar_; PrefChangeRegistrar pref_change_registrar_; diff --git a/chrome/browser/ui/webui/options/options_ui.cc b/chrome/browser/ui/webui/options/options_ui.cc index 0ace5df..de75ec6 100644 --- a/chrome/browser/ui/webui/options/options_ui.cc +++ b/chrome/browser/ui/webui/options/options_ui.cc @@ -116,35 +116,22 @@ OptionsUIHTMLSource::~OptionsUIHTMLSource() {} void OptionsUIHTMLSource::StartDataRequest(const std::string& path, bool is_incognito, int request_id) { - scoped_refptr<RefCountedBytes> response_bytes(new RefCountedBytes); + scoped_refptr<RefCountedMemory> response_bytes; SetFontAndTextDirection(localized_strings_.get()); if (path == kLocalizedStringsFile) { // Return dynamically-generated strings from memory. - std::string template_data; - jstemplate_builder::AppendJsonJS(localized_strings_.get(), &template_data); - response_bytes->data.resize(template_data.size()); - std::copy(template_data.begin(), - template_data.end(), - response_bytes->data.begin()); + std::string strings_js; + jstemplate_builder::AppendJsonJS(localized_strings_.get(), &strings_js); + response_bytes = base::RefCountedString::TakeString(&strings_js); } else if (path == kOptionsBundleJsFile) { // Return (and cache) the options javascript code. - static const base::StringPiece options_javascript( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_OPTIONS_BUNDLE_JS)); - response_bytes->data.resize(options_javascript.size()); - std::copy(options_javascript.begin(), - options_javascript.end(), - response_bytes->data.begin()); + response_bytes = ResourceBundle::GetSharedInstance().LoadDataResourceBytes( + IDR_OPTIONS_BUNDLE_JS); } else { // Return (and cache) the main options html page as the default. - static const base::StringPiece options_html( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_OPTIONS_HTML)); - response_bytes->data.resize(options_html.size()); - std::copy(options_html.begin(), - options_html.end(), - response_bytes->data.begin()); + response_bytes = ResourceBundle::GetSharedInstance().LoadDataResourceBytes( + IDR_OPTIONS_HTML); } SendResponse(request_id, response_bytes); diff --git a/chrome/browser/ui/webui/print_preview_data_source.cc b/chrome/browser/ui/webui/print_preview_data_source.cc index 8d01bbd..04399b2 100644 --- a/chrome/browser/ui/webui/print_preview_data_source.cc +++ b/chrome/browser/ui/webui/print_preview_data_source.cc @@ -158,14 +158,10 @@ void PrintPreviewDataSource::StartDataRequest(const std::string& path, static const base::StringPiece print_html( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_PRINT_PREVIEW_HTML)); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( + std::string full_html = jstemplate_builder::GetI18nTemplateHtml( print_html, &localized_strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); return; } else if (preview_data_requested && data->front()) { // Print Preview data. diff --git a/chrome/browser/ui/webui/sessions_ui.cc b/chrome/browser/ui/webui/sessions_ui.cc index 7b2ed5c..9d3d6c1 100644 --- a/chrome/browser/ui/webui/sessions_ui.cc +++ b/chrome/browser/ui/webui/sessions_ui.cc @@ -4,6 +4,8 @@ #include "chrome/browser/ui/webui/sessions_ui.h" +#include <algorithm> + #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/session_model_associator.h" @@ -77,11 +79,7 @@ void SessionsUIHTMLSource::StartDataRequest(const std::string& path, &localized_strings); jstemplate_builder::AppendJsTemplateSourceHtml(&full_html); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/ui/webui/sync_internals_html_source.cc b/chrome/browser/ui/webui/sync_internals_html_source.cc index c5c2809..6e5333c 100644 --- a/chrome/browser/ui/webui/sync_internals_html_source.cc +++ b/chrome/browser/ui/webui/sync_internals_html_source.cc @@ -4,8 +4,6 @@ #include "chrome/browser/ui/webui/sync_internals_html_source.h" -#include <algorithm> - #include "base/memory/ref_counted.h" #include "base/memory/ref_counted_memory.h" #include "base/message_loop.h" @@ -37,10 +35,7 @@ void SyncInternalsHTMLSource::StartDataRequest(const std::string& path, jstemplate_builder::AppendJsonHtml(&localized_strings, &html); jstemplate_builder::AppendI18nTemplateProcessHtml(&html); - scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes()); - bytes->data.resize(html.size()); - std::copy(html.begin(), html.end(), bytes->data.begin()); - SendResponse(request_id, bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&html)); } std::string SyncInternalsHTMLSource::GetMimeType( diff --git a/chrome/browser/ui/webui/task_manager_ui.cc b/chrome/browser/ui/webui/task_manager_ui.cc index 5a4a316..ae33f06 100644 --- a/chrome/browser/ui/webui/task_manager_ui.cc +++ b/chrome/browser/ui/webui/task_manager_ui.cc @@ -85,14 +85,10 @@ void TaskManagerUIHTMLSource::StartDataRequest(const std::string& path, static const base::StringPiece task_manager_html( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_TASK_MANAGER_HTML)); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( + std::string full_html = jstemplate_builder::GetI18nTemplateHtml( task_manager_html, &localized_strings); - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); } } // namespace diff --git a/chrome/browser/ui/webui/textfields_ui.cc b/chrome/browser/ui/webui/textfields_ui.cc index 819048e5..c7385f6 100644 --- a/chrome/browser/ui/webui/textfields_ui.cc +++ b/chrome/browser/ui/webui/textfields_ui.cc @@ -29,14 +29,8 @@ TextfieldsUIHTMLSource::TextfieldsUIHTMLSource() void TextfieldsUIHTMLSource::StartDataRequest(const std::string& path, bool is_incognito, int request_id) { - const std::string full_html = ResourceBundle::GetSharedInstance() - .GetRawDataResource(IDR_TEXTFIELDS_HTML).as_string(); - - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, ResourceBundle::GetSharedInstance() + .LoadDataResourceBytes(IDR_TEXTFIELDS_HTML)); } std::string TextfieldsUIHTMLSource::GetMimeType( diff --git a/chrome/browser/ui/webui/theme_source.h b/chrome/browser/ui/webui/theme_source.h index c3d8207..ad49672 100644 --- a/chrome/browser/ui/webui/theme_source.h +++ b/chrome/browser/ui/webui/theme_source.h @@ -11,7 +11,7 @@ #include "chrome/browser/ui/webui/chrome_url_data_manager.h" class Profile; -class RefCountedBytes; +class RefCountedMemory; class ThemeSource : public ChromeURLDataManager::DataSource { public: @@ -40,7 +40,7 @@ class ThemeSource : public ChromeURLDataManager::DataSource { Profile* profile_; // We grab the CSS early so we don't have to go back to the UI thread later. - scoped_refptr<RefCountedBytes> css_bytes_; + scoped_refptr<RefCountedMemory> css_bytes_; DISALLOW_COPY_AND_ASSIGN(ThemeSource); }; diff --git a/chrome/browser/ui/webui/workers_ui.cc b/chrome/browser/ui/webui/workers_ui.cc index 52cd620..f2220a3 100644 --- a/chrome/browser/ui/webui/workers_ui.cc +++ b/chrome/browser/ui/webui/workers_ui.cc @@ -101,11 +101,7 @@ void WorkersUIHTMLSource::SendSharedWorkersData(int request_id) { std::string json_string; base::JSONWriter::Write(&workers_list, false, &json_string); - scoped_refptr<RefCountedBytes> json_bytes(new RefCountedBytes()); - json_bytes->data.resize(json_string.size()); - std::copy(json_string.begin(), json_string.end(), json_bytes->data.begin()); - - SendResponse(request_id, json_bytes); + SendResponse(request_id, base::RefCountedString::TakeString(&json_string)); } class WorkersDOMHandler : public WebUIMessageHandler { diff --git a/content/renderer/render_widget_browsertest.cc b/content/renderer/render_widget_browsertest.cc index 8483249..51b0735 100644 --- a/content/renderer/render_widget_browsertest.cc +++ b/content/renderer/render_widget_browsertest.cc @@ -137,7 +137,7 @@ void RenderWidgetTest::OutputBitmapToFile(const SkBitmap& bitmap, bitmap.height(), static_cast<int>(bitmap.rowBytes()), 90 /* quality */, - &bitmap_data->data)); + &bitmap_data->data())); ASSERT_LT(0, file_util::WriteFile( file_path, reinterpret_cast<const char*>(bitmap_data->front()), |