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

Side by Side Diff: mojo/services/html_viewer/html_viewer.cc

Issue 1016493002: Add a DiscardableMemoryShmemeAllocator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: jamesr comments + rebase to ToT Created 5 years, 9 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
« no previous file with comments | « mojo/services/html_viewer/discardable_memory_allocator_unittest.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "gin/public/isolate_holder.h" 11 #include "gin/public/isolate_holder.h"
12 #include "mojo/application/application_runner_chromium.h" 12 #include "mojo/application/application_runner_chromium.h"
13 #include "mojo/services/html_viewer/discardable_memory_allocator.h"
13 #include "mojo/services/html_viewer/html_document.h" 14 #include "mojo/services/html_viewer/html_document.h"
14 #include "mojo/services/html_viewer/mojo_blink_platform_impl.h" 15 #include "mojo/services/html_viewer/mojo_blink_platform_impl.h"
15 #include "mojo/services/html_viewer/webmediaplayer_factory.h" 16 #include "mojo/services/html_viewer/webmediaplayer_factory.h"
16 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 17 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
17 #include "third_party/WebKit/public/web/WebKit.h" 18 #include "third_party/WebKit/public/web/WebKit.h"
18 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 19 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
19 #include "third_party/mojo/src/mojo/public/c/system/main.h" 20 #include "third_party/mojo/src/mojo/public/c/system/main.h"
20 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h" 21 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h"
21 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate. h" 22 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate. h"
22 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" 23 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
(...skipping 29 matching lines...) Expand all
52 // Enable MediaRenderer in media pipeline instead of using the internal 53 // Enable MediaRenderer in media pipeline instead of using the internal
53 // media::Renderer implementation. 54 // media::Renderer implementation.
54 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer"; 55 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer";
55 56
56 // Disables support for (unprefixed) Encrypted Media Extensions. 57 // Disables support for (unprefixed) Encrypted Media Extensions.
57 const char kDisableEncryptedMedia[] = "disable-encrypted-media"; 58 const char kDisableEncryptedMedia[] = "disable-encrypted-media";
58 59
59 // Prevents creation of any output surface. 60 // Prevents creation of any output surface.
60 const char kIsHeadless[] = "is-headless"; 61 const char kIsHeadless[] = "is-headless";
61 62
63 size_t kDesiredMaxMemory = 20 * 1024 * 1024;
64
62 class HTMLViewer; 65 class HTMLViewer;
63 66
64 class HTMLViewerApplication : public mojo::Application { 67 class HTMLViewerApplication : public mojo::Application {
65 public: 68 public:
66 HTMLViewerApplication(InterfaceRequest<Application> request, 69 HTMLViewerApplication(InterfaceRequest<Application> request,
67 URLResponsePtr response, 70 URLResponsePtr response,
68 scoped_refptr<base::MessageLoopProxy> compositor_thread, 71 scoped_refptr<base::MessageLoopProxy> compositor_thread,
69 WebMediaPlayerFactory* web_media_player_factory, 72 WebMediaPlayerFactory* web_media_player_factory,
70 bool is_headless) 73 bool is_headless)
71 : url_(response->url), 74 : url_(response->url),
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 scoped_refptr<base::MessageLoopProxy> compositor_thread_; 157 scoped_refptr<base::MessageLoopProxy> compositor_thread_;
155 WebMediaPlayerFactory* web_media_player_factory_; 158 WebMediaPlayerFactory* web_media_player_factory_;
156 bool is_headless_; 159 bool is_headless_;
157 160
158 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); 161 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl);
159 }; 162 };
160 163
161 class HTMLViewer : public mojo::ApplicationDelegate, 164 class HTMLViewer : public mojo::ApplicationDelegate,
162 public mojo::InterfaceFactory<ContentHandler> { 165 public mojo::InterfaceFactory<ContentHandler> {
163 public: 166 public:
164 HTMLViewer() : compositor_thread_("compositor thread") {} 167 HTMLViewer()
168 : discardable_memory_allocator_(kDesiredMaxMemory),
169 compositor_thread_("compositor thread") {}
165 170
166 ~HTMLViewer() override { blink::shutdown(); } 171 ~HTMLViewer() override { blink::shutdown(); }
167 172
168 private: 173 private:
169 // Overridden from ApplicationDelegate: 174 // Overridden from ApplicationDelegate:
170 void Initialize(mojo::ApplicationImpl* app) override { 175 void Initialize(mojo::ApplicationImpl* app) override {
176 base::DiscardableMemoryAllocator::SetInstance(
177 &discardable_memory_allocator_);
178
171 blink_platform_.reset(new MojoBlinkPlatformImpl(app)); 179 blink_platform_.reset(new MojoBlinkPlatformImpl(app));
172 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) 180 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
173 // Note: this requires file system access. 181 // Note: this requires file system access.
174 gin::IsolateHolder::LoadV8Snapshot(); 182 gin::IsolateHolder::LoadV8Snapshot();
175 #endif 183 #endif
176 blink::initialize(blink_platform_.get()); 184 blink::initialize(blink_platform_.get());
177 base::i18n::InitializeICU(); 185 base::i18n::InitializeICU();
178 186
179 ui::RegisterPathProvider(); 187 ui::RegisterPathProvider();
180 188
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 235
228 // Overridden from InterfaceFactory<ContentHandler> 236 // Overridden from InterfaceFactory<ContentHandler>
229 void Create(ApplicationConnection* connection, 237 void Create(ApplicationConnection* connection,
230 mojo::InterfaceRequest<ContentHandler> request) override { 238 mojo::InterfaceRequest<ContentHandler> request) override {
231 BindToRequest( 239 BindToRequest(
232 new ContentHandlerImpl(compositor_thread_.message_loop_proxy(), 240 new ContentHandlerImpl(compositor_thread_.message_loop_proxy(),
233 web_media_player_factory_.get(), is_headless_), 241 web_media_player_factory_.get(), is_headless_),
234 &request); 242 &request);
235 } 243 }
236 244
245 // Skia requires that we have one of these. Unlike the one used in chrome,
246 // this doesn't use purgable shared memory. Instead, it tries to free the
247 // oldest unlocked chunks on allocation.
248 //
249 // TODO(erg): In the long run, delete this allocator and get the real shared
250 // memory based purging allocator working here.
251 DiscardableMemoryAllocator discardable_memory_allocator_;
252
237 scoped_ptr<MojoBlinkPlatformImpl> blink_platform_; 253 scoped_ptr<MojoBlinkPlatformImpl> blink_platform_;
238 base::Thread compositor_thread_; 254 base::Thread compositor_thread_;
239 scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_; 255 scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_;
240 // Set if the content will never be displayed. 256 // Set if the content will never be displayed.
241 bool is_headless_; 257 bool is_headless_;
242 258
243 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); 259 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
244 }; 260 };
245 261
246 } // namespace html_viewer 262 } // namespace html_viewer
247 263
248 MojoResult MojoMain(MojoHandle shell_handle) { 264 MojoResult MojoMain(MojoHandle shell_handle) {
249 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer); 265 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer);
250 return runner.Run(shell_handle); 266 return runner.Run(shell_handle);
251 } 267 }
OLDNEW
« no previous file with comments | « mojo/services/html_viewer/discardable_memory_allocator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698