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

Side by Side Diff: chrome/utility/chrome_content_utility_client.cc

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 years, 3 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 | « chrome/renderer/chrome_render_thread_observer.cc ('k') | chrome/utility/image_decoder_impl.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 "chrome/utility/chrome_content_utility_client.h" 5 #include "chrome/utility/chrome_content_utility_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/common/chrome_utility_messages.h" 15 #include "chrome/common/chrome_utility_messages.h"
16 #include "chrome/common/safe_browsing/zip_analyzer.h" 16 #include "chrome/common/safe_browsing/zip_analyzer.h"
17 #include "chrome/common/safe_browsing/zip_analyzer_results.h" 17 #include "chrome/common/safe_browsing/zip_analyzer_results.h"
18 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" 18 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h"
19 #include "chrome/utility/image_decoder_impl.h" 19 #include "chrome/utility/image_decoder_impl.h"
20 #include "chrome/utility/utility_message_handler.h" 20 #include "chrome/utility/utility_message_handler.h"
21 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" 21 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h"
22 #include "content/public/child/image_decoder_utils.h" 22 #include "content/public/child/image_decoder_utils.h"
23 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
24 #include "content/public/utility/utility_thread.h" 24 #include "content/public/utility/utility_thread.h"
25 #include "courgette/courgette.h" 25 #include "courgette/courgette.h"
26 #include "courgette/third_party/bsdiff/bsdiff.h" 26 #include "courgette/third_party/bsdiff/bsdiff.h"
27 #include "ipc/ipc_channel.h" 27 #include "ipc/ipc_channel.h"
28 #include "mojo/public/cpp/bindings/strong_binding.h"
28 #include "services/shell/public/cpp/interface_registry.h" 29 #include "services/shell/public/cpp/interface_registry.h"
29 #include "third_party/zlib/google/zip.h" 30 #include "third_party/zlib/google/zip.h"
30 #include "ui/gfx/geometry/size.h" 31 #include "ui/gfx/geometry/size.h"
31 32
32 #if !defined(OS_ANDROID) 33 #if !defined(OS_ANDROID)
33 #include "chrome/common/resource_usage_reporter.mojom.h" 34 #include "chrome/common/resource_usage_reporter.mojom.h"
34 #include "chrome/utility/profile_import_handler.h" 35 #include "chrome/utility/profile_import_handler.h"
35 #include "mojo/public/cpp/bindings/strong_binding.h" 36 #include "mojo/public/cpp/bindings/strong_binding.h"
36 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" 37 #include "net/proxy/mojo_proxy_resolver_factory_impl.h"
37 #include "net/proxy/proxy_resolver_v8.h" 38 #include "net/proxy/proxy_resolver_v8.h"
(...skipping 23 matching lines...) Expand all
61 bool Send(IPC::Message* message) { 62 bool Send(IPC::Message* message) {
62 return content::UtilityThread::Get()->Send(message); 63 return content::UtilityThread::Get()->Send(message);
63 } 64 }
64 65
65 void ReleaseProcessIfNeeded() { 66 void ReleaseProcessIfNeeded() {
66 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); 67 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
67 } 68 }
68 69
69 #if !defined(OS_ANDROID) 70 #if !defined(OS_ANDROID)
70 void CreateProxyResolverFactory( 71 void CreateProxyResolverFactory(
71 mojo::InterfaceRequest<net::interfaces::ProxyResolverFactory> request) { 72 net::interfaces::ProxyResolverFactoryRequest request) {
72 // MojoProxyResolverFactoryImpl is strongly bound to the Mojo message pipe it 73 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(),
73 // is connected to. When that message pipe is closed, either explicitly on the 74 std::move(request));
74 // other end (in the browser process), or by a connection error, this object
75 // will be destroyed.
76 new net::MojoProxyResolverFactoryImpl(std::move(request));
77 } 75 }
78 76
79 class ResourceUsageReporterImpl : public mojom::ResourceUsageReporter { 77 class ResourceUsageReporterImpl : public mojom::ResourceUsageReporter {
80 public: 78 public:
81 explicit ResourceUsageReporterImpl( 79 ResourceUsageReporterImpl() {}
82 mojo::InterfaceRequest<mojom::ResourceUsageReporter> req)
83 : binding_(this, std::move(req)) {}
84 ~ResourceUsageReporterImpl() override {} 80 ~ResourceUsageReporterImpl() override {}
85 81
86 private: 82 private:
87 void GetUsageData(const GetUsageDataCallback& callback) override { 83 void GetUsageData(const GetUsageDataCallback& callback) override {
88 mojom::ResourceUsageDataPtr data = mojom::ResourceUsageData::New(); 84 mojom::ResourceUsageDataPtr data = mojom::ResourceUsageData::New();
89 size_t total_heap_size = net::ProxyResolverV8::GetTotalHeapSize(); 85 size_t total_heap_size = net::ProxyResolverV8::GetTotalHeapSize();
90 if (total_heap_size) { 86 if (total_heap_size) {
91 data->reports_v8_stats = true; 87 data->reports_v8_stats = true;
92 data->v8_bytes_allocated = total_heap_size; 88 data->v8_bytes_allocated = total_heap_size;
93 data->v8_bytes_used = net::ProxyResolverV8::GetUsedHeapSize(); 89 data->v8_bytes_used = net::ProxyResolverV8::GetUsedHeapSize();
94 } 90 }
95 callback.Run(std::move(data)); 91 callback.Run(std::move(data));
96 } 92 }
97
98 mojo::StrongBinding<mojom::ResourceUsageReporter> binding_;
99 }; 93 };
100 94
101 void CreateResourceUsageReporter( 95 void CreateResourceUsageReporter(
102 mojo::InterfaceRequest<mojom::ResourceUsageReporter> request) { 96 mojo::InterfaceRequest<mojom::ResourceUsageReporter> request) {
103 new ResourceUsageReporterImpl(std::move(request)); 97 mojo::MakeStrongBinding(base::MakeUnique<ResourceUsageReporterImpl>(),
98 std::move(request));
104 } 99 }
105 #endif // !defined(OS_ANDROID) 100 #endif // !defined(OS_ANDROID)
106 101
107 void CreateImageDecoder(mojo::InterfaceRequest<mojom::ImageDecoder> request) { 102 void CreateImageDecoder(mojo::InterfaceRequest<mojom::ImageDecoder> request) {
108 content::UtilityThread::Get()->EnsureBlinkInitialized(); 103 content::UtilityThread::Get()->EnsureBlinkInitialized();
109 new ImageDecoderImpl(std::move(request)); 104 mojo::MakeStrongBinding(base::MakeUnique<ImageDecoderImpl>(),
105 std::move(request));
110 } 106 }
111 107
112 } // namespace 108 } // namespace
113 109
114 ChromeContentUtilityClient::ChromeContentUtilityClient() 110 ChromeContentUtilityClient::ChromeContentUtilityClient()
115 : filter_messages_(false) { 111 : filter_messages_(false) {
116 #if !defined(OS_ANDROID) 112 #if !defined(OS_ANDROID)
117 handlers_.push_back(new ProfileImportHandler()); 113 handlers_.push_back(new ProfileImportHandler());
118 #endif 114 #endif
119 115
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 safe_browsing::zip_analyzer::Results results; 307 safe_browsing::zip_analyzer::Results results;
312 safe_browsing::dmg::AnalyzeDMGFile( 308 safe_browsing::dmg::AnalyzeDMGFile(
313 IPC::PlatformFileForTransitToFile(dmg_file), &results); 309 IPC::PlatformFileForTransitToFile(dmg_file), &results);
314 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( 310 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished(
315 results)); 311 results));
316 ReleaseProcessIfNeeded(); 312 ReleaseProcessIfNeeded();
317 } 313 }
318 #endif // defined(OS_MACOSX) 314 #endif // defined(OS_MACOSX)
319 315
320 #endif // defined(FULL_SAFE_BROWSING) 316 #endif // defined(FULL_SAFE_BROWSING)
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_render_thread_observer.cc ('k') | chrome/utility/image_decoder_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698