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

Side by Side Diff: chrome/browser/renderer_host/async_resource_handler.cc

Issue 391009: Don't do work in the SharedIOBuffer constructor; use an Init method instead. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | « base/shared_memory_posix.cc ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/async_resource_handler.h" 5 #include "chrome/browser/renderer_host/async_resource_handler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/process.h" 8 #include "base/process.h"
9 #include "base/shared_memory.h" 9 #include "base/shared_memory.h"
10 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
(...skipping 13 matching lines...) Expand all
24 const int kMaxReadBufSize = 524288; 24 const int kMaxReadBufSize = 524288;
25 25
26 } // namespace 26 } // namespace
27 27
28 // Our version of IOBuffer that uses shared memory. 28 // Our version of IOBuffer that uses shared memory.
29 class SharedIOBuffer : public net::IOBuffer { 29 class SharedIOBuffer : public net::IOBuffer {
30 public: 30 public:
31 explicit SharedIOBuffer(int buffer_size) 31 explicit SharedIOBuffer(int buffer_size)
32 : net::IOBuffer(), 32 : net::IOBuffer(),
33 ok_(false), 33 ok_(false),
34 buffer_size_(buffer_size) { 34 buffer_size_(buffer_size) {}
35 if (shared_memory_.Create(std::wstring(), false, false, buffer_size) && 35
36 shared_memory_.Map(buffer_size)) { 36 bool Init() {
37 if (shared_memory_.Create(std::wstring(), false, false, buffer_size_) &&
38 shared_memory_.Map(buffer_size_)) {
39 data_ = reinterpret_cast<char*>(shared_memory_.memory());
40 // TODO(hawk): Remove after debugging bug 16371.
41 CHECK(data_);
37 ok_ = true; 42 ok_ = true;
38 data_ = reinterpret_cast<char*>(shared_memory_.memory());
39 } 43 }
44 return ok_;
40 } 45 }
41 46
42 base::SharedMemory* shared_memory() { return &shared_memory_; } 47 base::SharedMemory* shared_memory() { return &shared_memory_; }
43 bool ok() { return ok_; } 48 bool ok() { return ok_; }
44 int buffer_size() { return buffer_size_; } 49 int buffer_size() { return buffer_size_; }
45 50
46 private: 51 private:
47 ~SharedIOBuffer() { 52 ~SharedIOBuffer() {
48 // TODO(willchan): Remove after debugging bug 16371. 53 // TODO(willchan): Remove after debugging bug 16371.
49 CHECK(g_spare_read_buffer != this); 54 CHECK(g_spare_read_buffer != this);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (g_spare_read_buffer) { 109 if (g_spare_read_buffer) {
105 DCHECK(!read_buffer_); 110 DCHECK(!read_buffer_);
106 read_buffer_.swap(&g_spare_read_buffer); 111 read_buffer_.swap(&g_spare_read_buffer);
107 // TODO(willchan): Remove after debugging bug 16371. 112 // TODO(willchan): Remove after debugging bug 16371.
108 CHECK(read_buffer_->data()); 113 CHECK(read_buffer_->data());
109 114
110 *buf = read_buffer_.get(); 115 *buf = read_buffer_.get();
111 *buf_size = read_buffer_->buffer_size(); 116 *buf_size = read_buffer_->buffer_size();
112 } else { 117 } else {
113 read_buffer_ = new SharedIOBuffer(next_buffer_size_); 118 read_buffer_ = new SharedIOBuffer(next_buffer_size_);
114 if (!read_buffer_->ok()) { 119 if (!read_buffer_->Init()) {
115 DLOG(ERROR) << "Couldn't allocate shared io buffer"; 120 DLOG(ERROR) << "Couldn't allocate shared io buffer";
121 read_buffer_ = NULL;
116 return false; 122 return false;
117 } 123 }
118 // TODO(willchan): Remove after debugging bug 16371. 124 // TODO(willchan): Remove after debugging bug 16371.
119 CHECK(read_buffer_->data()); 125 CHECK(read_buffer_->data());
120 *buf = read_buffer_.get(); 126 *buf = read_buffer_.get();
121 *buf_size = next_buffer_size_; 127 *buf_size = next_buffer_size_;
122 } 128 }
123 129
124 return true; 130 return true;
125 } 131 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 189
184 // static 190 // static
185 void AsyncResourceHandler::GlobalCleanup() { 191 void AsyncResourceHandler::GlobalCleanup() {
186 if (g_spare_read_buffer) { 192 if (g_spare_read_buffer) {
187 // Avoid the CHECK in SharedIOBuffer::~SharedIOBuffer(). 193 // Avoid the CHECK in SharedIOBuffer::~SharedIOBuffer().
188 SharedIOBuffer* tmp = g_spare_read_buffer; 194 SharedIOBuffer* tmp = g_spare_read_buffer;
189 g_spare_read_buffer = NULL; 195 g_spare_read_buffer = NULL;
190 tmp->Release(); 196 tmp->Release();
191 } 197 }
192 } 198 }
OLDNEW
« no previous file with comments | « base/shared_memory_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698