diff options
author | amit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 23:46:30 +0000 |
---|---|---|
committer | amit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 23:46:30 +0000 |
commit | 040b800f9a064e093255e1e5e2718b1cd51275a3 (patch) | |
tree | e45d8b11ebaf139529e521503fc3a08313d8f3cd /chrome_frame | |
parent | ec140301a87ecf1ba9e70e8031ee521c002b0f32 (diff) | |
download | chromium_src-040b800f9a064e093255e1e5e2718b1cd51275a3.zip chromium_src-040b800f9a064e093255e1e5e2718b1cd51275a3.tar.gz chromium_src-040b800f9a064e093255e1e5e2718b1cd51275a3.tar.bz2 |
Do not wrap the original callback if we can;t initialize sniffing cache
CreateStreamOnHGlobal may fail if the underlying GlobalAlloc fails. It has
a strange behavaior where if we pass in an HGlobal, it can create more
streams per process. So the fix is to:
1. not register us as a bind status callback if we cannot create a stream
for sniffing data and
2. When initializing the data sniffing stream pre-create a HGlobal
BUG=To be filed
TEST=none
Review URL: http://codereview.chromium.org/1983002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46525 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r-- | chrome_frame/test/urlmon_moniker_unittest.cc | 8 | ||||
-rw-r--r-- | chrome_frame/urlmon_bind_status_callback.cc | 26 | ||||
-rw-r--r-- | chrome_frame/urlmon_bind_status_callback.h | 2 |
3 files changed, 20 insertions, 16 deletions
diff --git a/chrome_frame/test/urlmon_moniker_unittest.cc b/chrome_frame/test/urlmon_moniker_unittest.cc index 7881490..5af4eb3 100644 --- a/chrome_frame/test/urlmon_moniker_unittest.cc +++ b/chrome_frame/test/urlmon_moniker_unittest.cc @@ -139,8 +139,8 @@ TEST_F(MonikerPatchTest, SniffDataMetaTag) { // Initialize 2 sniffers 1 with meta tag and 1 without. SniffData sniffer1, sniffer2; - EXPECT_TRUE(sniffer1.InitializeCache(std::wstring())); - EXPECT_TRUE(sniffer2.InitializeCache(std::wstring())); + EXPECT_HRESULT_SUCCEEDED(sniffer1.InitializeCache(std::wstring())); + EXPECT_HRESULT_SUCCEEDED(sniffer2.InitializeCache(std::wstring())); EXPECT_HRESULT_SUCCEEDED(sniffer1.ReadIntoCache(stream_with_meta, true)); EXPECT_HRESULT_SUCCEEDED(sniffer2.ReadIntoCache(stream_no_meta, true)); @@ -158,7 +158,7 @@ TEST_F(MonikerPatchTest, SniffDataPlayback1) { ScopedComPtr<IStream> stream_with_meta; SniffData sniffer; - EXPECT_TRUE(sniffer.InitializeCache(std::wstring())); + EXPECT_HRESULT_SUCCEEDED(sniffer.InitializeCache(std::wstring())); ASSERT_TRUE(ReadFileAsString(kSmallHtmlMetaTag, &small_html_meta_tag)); ASSERT_TRUE(StringToStream(small_html_meta_tag, stream_with_meta.Receive())); EXPECT_HRESULT_SUCCEEDED(sniffer.ReadIntoCache(stream_with_meta, true)); @@ -201,7 +201,7 @@ TEST_F(MonikerPatchTest, SniffDataPlayback2) { ScopedComPtr<IStream> stream_with_meta; SniffData sniffer; - EXPECT_TRUE(sniffer.InitializeCache(std::wstring())); + EXPECT_HRESULT_SUCCEEDED(sniffer.InitializeCache(std::wstring())); ASSERT_TRUE(ReadFileAsString(kSmallHtmlMetaTag, &small_html_meta_tag)); ASSERT_TRUE(StringToStream(small_html_meta_tag, stream_with_meta.Receive())); EXPECT_HRESULT_SUCCEEDED(sniffer.ReadIntoCache(stream_with_meta, true)); diff --git a/chrome_frame/urlmon_bind_status_callback.cc b/chrome_frame/urlmon_bind_status_callback.cc index 851edee..354ab3f 100644 --- a/chrome_frame/urlmon_bind_status_callback.cc +++ b/chrome_frame/urlmon_bind_status_callback.cc @@ -79,16 +79,17 @@ STDMETHODIMP CacheStream::Read(void* pv, ULONG cb, ULONG* read) { ///////////////////////////////////////////////////////////////////// -bool SniffData::InitializeCache(const std::wstring& url) { +HRESULT SniffData::InitializeCache(const std::wstring& url) { url_ = url; renderer_type_ = UNDETERMINED; - HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, cache_.Receive()); - if (FAILED(hr)) { - NOTREACHED(); - return false; - } - return true; + const int kInitialSize = 4 * 1024; // 4K + HGLOBAL mem = GlobalAlloc(0, kInitialSize); + DCHECK(mem) << "GlobalAlloc failed: " << GetLastError(); + + HRESULT hr = CreateStreamOnHGlobal(mem, TRUE, cache_.Receive()); + DLOG_IF(ERROR, FAILED(hr)) << "CreateStreamOnHGlobal failed: " << hr; + return hr; } HRESULT SniffData::ReadIntoCache(IStream* stream, bool force_determination) { @@ -185,7 +186,13 @@ HRESULT BSCBStorageBind::Initialize(IMoniker* moniker, IBindCtx* bind_ctx) { DLOG(INFO) << __FUNCTION__ << me() << StringPrintf(" tid=%i", PlatformThread::CurrentId()); - HRESULT hr = AttachToBind(bind_ctx); + std::wstring url = GetActualUrlFromMoniker(moniker, bind_ctx, + std::wstring()); + HRESULT hr = data_sniffer_.InitializeCache(url); + if (FAILED(hr)) + return hr; + + hr = AttachToBind(bind_ctx); if (FAILED(hr)) { NOTREACHED() << __FUNCTION__ << me() << "AttachToBind error: " << hr; return hr; @@ -196,9 +203,6 @@ HRESULT BSCBStorageBind::Initialize(IMoniker* moniker, IBindCtx* bind_ctx) { return E_FAIL; } - std::wstring url = GetActualUrlFromMoniker(moniker, bind_ctx, - std::wstring()); - data_sniffer_.InitializeCache(url); return hr; } diff --git a/chrome_frame/urlmon_bind_status_callback.h b/chrome_frame/urlmon_bind_status_callback.h index 0ecf51f..8b6fd3b 100644 --- a/chrome_frame/urlmon_bind_status_callback.h +++ b/chrome_frame/urlmon_bind_status_callback.h @@ -52,7 +52,7 @@ class SniffData { OTHER }; - bool InitializeCache(const std::wstring& url); + HRESULT InitializeCache(const std::wstring& url); HRESULT ReadIntoCache(IStream* stream, bool force_determination); HRESULT DrainCache(IBindStatusCallback* bscb, DWORD bscf, CLIPFORMAT clip_format); |