Update wrapper implementations to use base types (issue #1336).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1775 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2014-07-15 17:19:43 +00:00
parent f9bf8dfa10
commit 646ae3310f
7 changed files with 105 additions and 90 deletions

View File

@ -37,6 +37,7 @@
#define CEF_INCLUDE_WRAPPER_CEF_MESSAGE_ROUTER_H_
#pragma once
#include "include/base/cef_ref_counted.h"
#include "include/cef_base.h"
#include "include/cef_browser.h"
#include "include/cef_process_message.h"
@ -211,7 +212,8 @@ struct CefMessageRouterConfig {
// Implements the browser side of query routing. The methods of this class may
// be called on any browser process thread unless otherwise indicated.
///
class CefMessageRouterBrowserSide : public CefBase {
class CefMessageRouterBrowserSide :
public base::RefCountedThreadSafe<CefMessageRouterBrowserSide> {
public:
///
// Callback associated with a single pending asynchronous query. Execute the
@ -360,16 +362,20 @@ class CefMessageRouterBrowserSide : public CefBase {
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) =0;
protected:
// Protect against accidental deletion of this object.
friend class base::RefCountedThreadSafe<CefMessageRouterBrowserSide>;
virtual ~CefMessageRouterBrowserSide() {}
};
///
// Implements the renderer side of query routing. The methods of this class must
// be called on the render process main thread.
///
class CefMessageRouterRendererSide : public CefBase {
class CefMessageRouterRendererSide :
public base::RefCountedThreadSafe<CefMessageRouterRendererSide> {
public:
virtual ~CefMessageRouterRendererSide() {}
///
// Create a new router with the specified configuration.
///
@ -412,6 +418,11 @@ class CefMessageRouterRendererSide : public CefBase {
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) =0;
protected:
// Protect against accidental deletion of this object.
friend class base::RefCountedThreadSafe<CefMessageRouterRendererSide>;
virtual ~CefMessageRouterRendererSide() {}
};
#endif // CEF_INCLUDE_WRAPPER_CEF_MESSAGE_ROUTER_H_

View File

@ -38,6 +38,7 @@
#pragma once
#include "include/base/cef_macros.h"
#include "include/base/cef_scoped_ptr.h"
#include "include/cef_base.h"
#include "include/cef_resource_handler.h"
#include "include/cef_response.h"
@ -89,7 +90,7 @@ class CefStreamResourceHandler : public CefResourceHandler {
bool read_on_file_thread_;
class Buffer;
Buffer* buffer_;
scoped_ptr<Buffer> buffer_;
#ifndef NDEBUG
// Used in debug builds to verify that |buffer_| isn't being accessed on
// multiple threads at the same time.

View File

@ -37,13 +37,15 @@
#define CEF_INCLUDE_WRAPPER_CEF_XML_OBJECT_H_
#pragma once
#include "include/base/cef_lock.h"
#include "include/base/cef_macros.h"
#include "include/cef_base.h"
#include "include/cef_xml_reader.h"
#include <map>
#include <vector>
#include "include/base/cef_lock.h"
#include "include/base/cef_macros.h"
#include "include/base/cef_ref_counted.h"
#include "include/cef_base.h"
#include "include/cef_xml_reader.h"
class CefStreamReader;
///
@ -69,7 +71,7 @@ class CefStreamReader;
// (c) Element nodes are represented by their outer XML string.
// </pre>
///
class CefXmlObject : public CefBase {
class CefXmlObject : public base::RefCountedThreadSafe<CefXmlObject> {
public:
typedef std::vector<CefRefPtr<CefXmlObject> > ObjectVector;
typedef std::map<CefString, CefString > AttributeMap;
@ -79,7 +81,6 @@ class CefXmlObject : public CefBase {
// at least one character long.
///
explicit CefXmlObject(const CefString& name);
virtual ~CefXmlObject();
///
// Load the contents of the specified XML stream into this object. The
@ -175,6 +176,10 @@ class CefXmlObject : public CefBase {
size_t FindChildren(const CefString& name, ObjectVector& children);
private:
// Protect against accidental deletion of this object.
friend class base::RefCountedThreadSafe<CefXmlObject>;
~CefXmlObject();
void SetParent(CefXmlObject* parent);
CefString name_;
@ -185,7 +190,6 @@ class CefXmlObject : public CefBase {
base::Lock lock_;
IMPLEMENT_REFCOUNTING(CefXmlObject);
DISALLOW_COPY_AND_ASSIGN(CefXmlObject);
};

View File

@ -37,10 +37,12 @@
#define CEF_INCLUDE_WRAPPER_CEF_ZIP_ARCHIVE_H_
#pragma once
#include <map>
#include "include/base/cef_lock.h"
#include "include/base/cef_macros.h"
#include "include/base/cef_ref_counted.h"
#include "include/cef_base.h"
#include <map>
class CefStreamReader;
@ -49,13 +51,12 @@ class CefStreamReader;
// not be used with large archive files because all data will be resident in
// memory at the same time. This implementation supports a restricted set of zip
// archive features:
// (1) Password-protected files are not supported.
// (2) All file names are stored and compared in lower case.
// (3) File ordering from the original zip archive is not maintained. This
// (1) All file names are stored and compared in lower case.
// (2) File ordering from the original zip archive is not maintained. This
// means that files from the same folder may not be located together in the
// file content map.
///
class CefZipArchive : public CefBase {
class CefZipArchive : public base::RefCountedThreadSafe<CefZipArchive> {
public:
///
// Class representing a file in the archive. Accessing the file data from
@ -66,25 +67,25 @@ class CefZipArchive : public CefBase {
///
// Returns the read-only data contained in the file.
///
virtual const unsigned char* GetData() =0;
virtual const unsigned char* GetData() const =0;
///
// Returns the size of the data in the file.
///
virtual size_t GetDataSize() =0;
virtual size_t GetDataSize() const =0;
///
// Returns a CefStreamReader object for streaming the contents of the file.
///
virtual CefRefPtr<CefStreamReader> GetStreamReader() =0;
virtual CefRefPtr<CefStreamReader> GetStreamReader() const =0;
};
typedef std::map<CefString, CefRefPtr<File> > FileMap;
///
// Create a new object.
///
CefZipArchive();
virtual ~CefZipArchive();
///
// Load the contents of the specified zip archive stream into this object.
@ -105,17 +106,17 @@ class CefZipArchive : public CefBase {
///
// Returns the number of files in the archive.
///
size_t GetFileCount();
size_t GetFileCount() const;
///
// Returns true if the specified file exists and has contents.
///
bool HasFile(const CefString& fileName);
bool HasFile(const CefString& fileName) const;
///
// Returns the specified file.
///
CefRefPtr<File> GetFile(const CefString& fileName);
CefRefPtr<File> GetFile(const CefString& fileName) const;
///
// Removes the specified file.
@ -125,14 +126,17 @@ class CefZipArchive : public CefBase {
///
// Returns the map of all files.
///
size_t GetFiles(FileMap& map);
size_t GetFiles(FileMap& map) const;
private:
// Protect against accidental deletion of this object.
friend class base::RefCountedThreadSafe<CefZipArchive>;
~CefZipArchive();
FileMap contents_;
base::Lock lock_;
mutable base::Lock lock_;
IMPLEMENT_REFCOUNTING(CefZipArchive);
DISALLOW_COPY_AND_ASSIGN(CefZipArchive);
};

View File

@ -598,7 +598,6 @@ class CefMessageRouterBrowserSideImpl : public CefMessageRouterBrowserSide {
typedef CefBrowserInfoMap<int64, QueryInfo*> BrowserQueryInfoMap;
BrowserQueryInfoMap browser_query_info_map_;
IMPLEMENT_REFCOUNTING(CefMessageRouterBrowserSideImpl);
DISALLOW_COPY_AND_ASSIGN(CefMessageRouterBrowserSideImpl);
};
@ -1124,7 +1123,6 @@ class CefMessageRouterRendererSideImpl : public CefMessageRouterRendererSide {
typedef std::map<int, CefRefPtr<CefV8Context> > ContextMap;
ContextMap context_map_;
IMPLEMENT_REFCOUNTING(CefMessageRouterRendererSideImpl);
DISALLOW_COPY_AND_ASSIGN(CefMessageRouterRendererSideImpl);
};

View File

@ -6,36 +6,29 @@
#include <algorithm>
#include "include/base/cef_bind.h"
#include "include/base/cef_logging.h"
#include "include/base/cef_macros.h"
#include "include/cef_callback.h"
#include "include/cef_request.h"
#include "include/cef_runnable.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_closure_task.h"
#include "include/wrapper/cef_helpers.h"
// Class that represents a readable/writable character buffer.
class CefStreamResourceHandler::Buffer {
public:
Buffer()
: buffer_(NULL),
size_(0),
: size_(0),
bytes_requested_(0),
bytes_written_(0),
bytes_read_(0) {
}
~Buffer() {
if (buffer_)
delete [] buffer_;
}
void Reset(int new_size) {
if (size_ < new_size) {
if (buffer_)
delete [] buffer_;
size_ = new_size;
buffer_ = new char[size_];
buffer_.reset(new char[size_]);
DCHECK(buffer_);
}
bytes_requested_ = new_size;
@ -55,7 +48,7 @@ class CefStreamResourceHandler::Buffer {
const int write_size =
std::min(bytes_to_read, bytes_written_ - bytes_read_);
if (write_size > 0) {
memcpy(data_out, buffer_ + bytes_read_, write_size);
memcpy(data_out, buffer_ .get() + bytes_read_, write_size);
bytes_read_ += write_size;
}
return write_size;
@ -67,7 +60,7 @@ class CefStreamResourceHandler::Buffer {
int bytes_read;
do {
bytes_read = static_cast<int>(
reader->Read(buffer_ + bytes_written_, 1,
reader->Read(buffer_.get() + bytes_written_, 1,
bytes_requested_ - bytes_written_));
bytes_written_ += bytes_read;
} while (bytes_read != 0 && bytes_written_ < bytes_requested_);
@ -76,7 +69,7 @@ class CefStreamResourceHandler::Buffer {
}
private:
char* buffer_;
scoped_ptr<char[]> buffer_;
int size_;
int bytes_requested_;
int bytes_written_;
@ -91,8 +84,7 @@ CefStreamResourceHandler::CefStreamResourceHandler(
: status_code_(200),
status_text_("OK"),
mime_type_(mime_type),
stream_(stream),
buffer_(NULL)
stream_(stream)
#ifndef NDEBUG
, buffer_owned_by_file_thread_(false)
#endif
@ -112,16 +104,13 @@ CefStreamResourceHandler::CefStreamResourceHandler(
status_text_(status_text),
mime_type_(mime_type),
header_map_(header_map),
stream_(stream),
buffer_(NULL) {
stream_(stream) {
DCHECK(!mime_type_.empty());
DCHECK(stream_.get());
read_on_file_thread_ = stream_->MayBlock();
}
CefStreamResourceHandler::~CefStreamResourceHandler() {
if (buffer_)
delete buffer_;
}
bool CefStreamResourceHandler::ProcessRequest(CefRefPtr<CefRequest> request,
@ -171,8 +160,8 @@ bool CefStreamResourceHandler::ReadResponse(void* data_out,
buffer_owned_by_file_thread_ = true;
#endif
CefPostTask(TID_FILE,
NewCefRunnableMethod(this, &CefStreamResourceHandler::ReadOnFileThread,
bytes_to_read, callback));
base::Bind(&CefStreamResourceHandler::ReadOnFileThread, this,
bytes_to_read, callback));
return true;
}
} else {
@ -203,7 +192,7 @@ void CefStreamResourceHandler::ReadOnFileThread(
#endif
if (!buffer_)
buffer_ = new Buffer();
buffer_.reset(new Buffer());
buffer_->Reset(bytes_to_read);
buffer_->ReadFrom(stream_);

View File

@ -5,10 +5,10 @@
#include "include/wrapper/cef_zip_archive.h"
#include <algorithm>
#include <vector>
#include "include/base/cef_logging.h"
#include "include/base/cef_macros.h"
#include "include/base/cef_scoped_ptr.h"
#include "include/cef_stream.h"
#include "include/cef_zip_reader.h"
#include "include/wrapper/cef_byte_read_handler.h"
@ -19,30 +19,48 @@
namespace {
// Convert |str| to lowercase in a Unicode-friendly manner.
CefString ToLower(const CefString& str) {
std::wstring wstr = str;
std::transform(wstr.begin(), wstr.end(), wstr.begin(), towlower);
return wstr;
}
class CefZipFile : public CefZipArchive::File {
public:
explicit CefZipFile(size_t size) : data_(size) {}
~CefZipFile() {}
CefZipFile() : data_size_(0) {}
// Returns the read-only data contained in the file.
virtual const unsigned char* GetData() { return &data_[0]; }
bool Initialize(size_t data_size) {
data_.reset(new unsigned char[data_size]);
if (data_) {
data_size_ = data_size;
return true;
} else {
DLOG(ERROR) << "Failed to allocate " << data_size << " bytes of memory";
data_size_ = 0;
return false;
}
}
// Returns the size of the data in the file.
virtual size_t GetDataSize() { return data_.size(); }
virtual const unsigned char* GetData() const OVERRIDE { return data_.get(); }
// Returns a CefStreamReader object for streaming the contents of the file.
virtual CefRefPtr<CefStreamReader> GetStreamReader() {
virtual size_t GetDataSize() const OVERRIDE { return data_size_; }
virtual CefRefPtr<CefStreamReader> GetStreamReader() const OVERRIDE {
CefRefPtr<CefReadHandler> handler(
new CefByteReadHandler(GetData(), GetDataSize(), this));
new CefByteReadHandler(data_.get(), data_size_,
const_cast<CefZipFile*>(this)));
return CefStreamReader::CreateForHandler(handler);
}
std::vector<unsigned char>* GetDataVector() { return &data_; }
unsigned char* data() { return data_.get(); }
private:
std::vector<unsigned char> data_;
size_t data_size_;
scoped_ptr<unsigned char[]> data_;
IMPLEMENT_REFCOUNTING(CefZipFile);
DISALLOW_COPY_AND_ASSIGN(CefZipFile);
};
} // namespace
@ -67,14 +85,12 @@ size_t CefZipArchive::Load(CefRefPtr<CefStreamReader> stream,
if (!reader->MoveToFirstFile())
return 0;
std::wstring name;
CefRefPtr<CefZipFile> contents;
FileMap::iterator it;
std::vector<unsigned char>* data;
size_t count = 0, size, offset;
size_t count = 0;
do {
size = static_cast<size_t>(reader->GetFileSize());
const size_t size = static_cast<size_t>(reader->GetFileSize());
if (size == 0) {
// Skip directories and empty files.
continue;
@ -83,8 +99,7 @@ size_t CefZipArchive::Load(CefRefPtr<CefStreamReader> stream,
if (!reader->OpenFile(password))
break;
name = reader->GetFileName();
std::transform(name.begin(), name.end(), name.begin(), towlower);
const CefString& name = ToLower(reader->GetFileName());
it = contents_.find(name);
if (it != contents_.end()) {
@ -94,13 +109,15 @@ size_t CefZipArchive::Load(CefRefPtr<CefStreamReader> stream,
continue;
}
contents = new CefZipFile(size);
data = contents->GetDataVector();
offset = 0;
CefRefPtr<CefZipFile> contents = new CefZipFile();
if (!contents->Initialize(size))
continue;
unsigned char* data = contents->data();
size_t offset = 0;
// Read the file contents.
do {
offset += reader->ReadFile(&(*data)[offset], size - offset);
offset += reader->ReadFile(data + offset, size - offset);
} while (offset < size && !reader->Eof());
DCHECK(offset == size);
@ -120,38 +137,29 @@ void CefZipArchive::Clear() {
contents_.clear();
}
size_t CefZipArchive::GetFileCount() {
size_t CefZipArchive::GetFileCount() const {
base::AutoLock lock_scope(lock_);
return contents_.size();
}
bool CefZipArchive::HasFile(const CefString& fileName) {
std::wstring str = fileName;
std::transform(str.begin(), str.end(), str.begin(), towlower);
bool CefZipArchive::HasFile(const CefString& fileName) const {
base::AutoLock lock_scope(lock_);
FileMap::const_iterator it = contents_.find(CefString(str));
FileMap::const_iterator it = contents_.find(ToLower(fileName));
return (it != contents_.end());
}
CefRefPtr<CefZipArchive::File> CefZipArchive::GetFile(
const CefString& fileName) {
std::wstring str = fileName;
std::transform(str.begin(), str.end(), str.begin(), towlower);
const CefString& fileName) const {
base::AutoLock lock_scope(lock_);
FileMap::const_iterator it = contents_.find(CefString(str));
FileMap::const_iterator it = contents_.find(ToLower(fileName));
if (it != contents_.end())
return it->second;
return NULL;
}
bool CefZipArchive::RemoveFile(const CefString& fileName) {
std::wstring str = fileName;
std::transform(str.begin(), str.end(), str.begin(), towlower);
base::AutoLock lock_scope(lock_);
FileMap::iterator it = contents_.find(CefString(str));
FileMap::iterator it = contents_.find(ToLower(fileName));
if (it != contents_.end()) {
contents_.erase(it);
return true;
@ -159,7 +167,7 @@ bool CefZipArchive::RemoveFile(const CefString& fileName) {
return false;
}
size_t CefZipArchive::GetFiles(FileMap& map) {
size_t CefZipArchive::GetFiles(FileMap& map) const {
base::AutoLock lock_scope(lock_);
map = contents_;
return contents_.size();