Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(912)

Side by Side Diff: content/browser/fileapi/fileapi_message_filter.cc

Issue 22908008: Limit the total memory usage for Stream instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: creis's comments Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/fileapi/fileapi_message_filter.h ('k') | content/browser/streams/stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/fileapi/fileapi_message_filter.h" 5 #include "content/browser/fileapi/fileapi_message_filter.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 NULL /* write_observer */, 625 NULL /* write_observer */,
626 url); 626 url);
627 stream_urls_.insert(url.spec()); 627 stream_urls_.insert(url.spec());
628 } 628 }
629 629
630 void FileAPIMessageFilter::OnAppendBlobDataItemToStream( 630 void FileAPIMessageFilter::OnAppendBlobDataItemToStream(
631 const GURL& url, const BlobData::Item& item) { 631 const GURL& url, const BlobData::Item& item) {
632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
633 633
634 scoped_refptr<Stream> stream(GetStreamForURL(url)); 634 scoped_refptr<Stream> stream(GetStreamForURL(url));
635 if (!stream.get()) { 635 // Stream instances may be deleted on error. Just abort if there's no Stream
636 NOTREACHED(); 636 // instance for |url| in the registry.
637 if (!stream.get())
637 return; 638 return;
638 }
639 639
640 // Data for stream is delivered as TYPE_BYTES item. 640 // Data for stream is delivered as TYPE_BYTES item.
641 if (item.type() != BlobData::Item::TYPE_BYTES) { 641 if (item.type() != BlobData::Item::TYPE_BYTES) {
642 BadMessageReceived(); 642 BadMessageReceived();
643 return; 643 return;
644 } 644 }
645 stream->AddData(item.bytes(), item.length()); 645 stream->AddData(item.bytes(), item.length());
646 } 646 }
647 647
648 void FileAPIMessageFilter::OnAppendSharedMemoryToStream( 648 void FileAPIMessageFilter::OnAppendSharedMemoryToStream(
649 const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size) { 649 const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size) {
650 DCHECK(base::SharedMemory::IsHandleValid(handle)); 650 DCHECK(base::SharedMemory::IsHandleValid(handle));
651 if (!buffer_size) { 651 if (!buffer_size) {
652 BadMessageReceived(); 652 BadMessageReceived();
653 return; 653 return;
654 } 654 }
655 #if defined(OS_WIN) 655 #if defined(OS_WIN)
656 base::SharedMemory shared_memory(handle, true, PeerHandle()); 656 base::SharedMemory shared_memory(handle, true, PeerHandle());
657 #else 657 #else
658 base::SharedMemory shared_memory(handle, true); 658 base::SharedMemory shared_memory(handle, true);
659 #endif 659 #endif
660 if (!shared_memory.Map(buffer_size)) { 660 if (!shared_memory.Map(buffer_size)) {
661 OnRemoveStream(url); 661 OnRemoveStream(url);
662 return; 662 return;
663 } 663 }
664 664
665 scoped_refptr<Stream> stream(GetStreamForURL(url)); 665 scoped_refptr<Stream> stream(GetStreamForURL(url));
666 if (!stream.get()) { 666 if (!stream.get())
667 NOTREACHED();
668 return; 667 return;
669 }
670 668
671 stream->AddData(static_cast<char*>(shared_memory.memory()), buffer_size); 669 stream->AddData(static_cast<char*>(shared_memory.memory()), buffer_size);
672 } 670 }
673 671
674 void FileAPIMessageFilter::OnFinishBuildingStream(const GURL& url) { 672 void FileAPIMessageFilter::OnFinishBuildingStream(const GURL& url) {
675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
676 scoped_refptr<Stream> stream(GetStreamForURL(url)); 674 scoped_refptr<Stream> stream(GetStreamForURL(url));
677 if (stream.get()) 675 if (stream.get())
678 stream->Finalize(); 676 stream->Finalize();
679 else
680 NOTREACHED();
681 } 677 }
682 678
683 void FileAPIMessageFilter::OnCloneStream( 679 void FileAPIMessageFilter::OnCloneStream(
684 const GURL& url, const GURL& src_url) { 680 const GURL& url, const GURL& src_url) {
685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
686 if (!GetStreamForURL(src_url)) { 682 // Abort if there's no Stream instance for |src_url| (source Stream which
687 NOTREACHED(); 683 // we're going to make |url| point to) in the registry.
684 if (!GetStreamForURL(src_url))
688 return; 685 return;
689 }
690 686
691 stream_context_->registry()->CloneStream(url, src_url); 687 stream_context_->registry()->CloneStream(url, src_url);
692 stream_urls_.insert(url.spec()); 688 stream_urls_.insert(url.spec());
693 } 689 }
694 690
695 void FileAPIMessageFilter::OnRemoveStream(const GURL& url) { 691 void FileAPIMessageFilter::OnRemoveStream(const GURL& url) {
696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 692 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
697 693
698 if (!GetStreamForURL(url).get()) { 694 if (!GetStreamForURL(url).get())
699 NOTREACHED();
700 return; 695 return;
701 }
702 696
703 stream_context_->registry()->UnregisterStream(url); 697 stream_context_->registry()->UnregisterStream(url);
704 stream_urls_.erase(url.spec()); 698 stream_urls_.erase(url.spec());
705 } 699 }
706 700
707 void FileAPIMessageFilter::DidFinish(int request_id, 701 void FileAPIMessageFilter::DidFinish(int request_id,
708 base::PlatformFileError result) { 702 base::PlatformFileError result) {
709 if (result == base::PLATFORM_FILE_OK) 703 if (result == base::PLATFORM_FILE_OK)
710 Send(new FileSystemMsg_DidSucceed(request_id)); 704 Send(new FileSystemMsg_DidSucceed(request_id));
711 else 705 else
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 const FileSystemURL& url, int permissions, base::PlatformFileError* error) { 849 const FileSystemURL& url, int permissions, base::PlatformFileError* error) {
856 return CheckFileSystemPermissionsForProcess(context_, process_id_, url, 850 return CheckFileSystemPermissionsForProcess(context_, process_id_, url,
857 permissions, error); 851 permissions, error);
858 } 852 }
859 853
860 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) { 854 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) {
861 return stream_context_->registry()->GetStream(url); 855 return stream_context_->registry()->GetStream(url);
862 } 856 }
863 857
864 } // namespace content 858 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/fileapi_message_filter.h ('k') | content/browser/streams/stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698