summaryrefslogtreecommitdiffstats
path: root/chrome/utility
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-09 21:11:51 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-09 21:11:51 +0000
commit373c1069852a133d823ddb417f18beaa840664e8 (patch)
tree34571462d893810b94d4cc965b8a505653eb161b /chrome/utility
parentdb6831ad3a6ba65d881bedd504c92b219c8524da (diff)
downloadchromium_src-373c1069852a133d823ddb417f18beaa840664e8.zip
chromium_src-373c1069852a133d823ddb417f18beaa840664e8.tar.gz
chromium_src-373c1069852a133d823ddb417f18beaa840664e8.tar.bz2
Move UtilityProcessHost to content and move the message sending/dispatching to the clients. This allows the content layer to use the class.
BUG=76697 Review URL: http://codereview.chromium.org/6995095 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88586 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/utility')
-rw-r--r--chrome/utility/chrome_content_utility_client.cc (renamed from chrome/utility/utility_thread.cc)151
-rw-r--r--chrome/utility/chrome_content_utility_client.h67
-rw-r--r--chrome/utility/utility_main.cc64
-rw-r--r--chrome/utility/utility_thread.h117
4 files changed, 123 insertions, 276 deletions
diff --git a/chrome/utility/utility_thread.cc b/chrome/utility/chrome_content_utility_client.cc
index 3f13950..10c577d 100644
--- a/chrome/utility/utility_thread.cc
+++ b/chrome/utility/chrome_content_utility_client.cc
@@ -2,67 +2,66 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/utility/utility_thread.h"
-
-#include <stddef.h>
-#include <vector>
+#include "chrome/utility/chrome_content_utility_client.h"
#include "base/base64.h"
-#include "base/file_path.h"
+#include "base/command_line.h"
#include "base/json/json_reader.h"
-#include "base/logging.h"
-#include "base/memory/ref_counted.h"
-#include "base/values.h"
-#include "build/build_config.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_utility_messages.h"
+#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension_unpacker.h"
#include "chrome/common/extensions/update_manifest.h"
-#include "chrome/common/utility_messages.h"
#include "chrome/common/web_resource/web_resource_unpacker.h"
-#include "content/common/child_process.h"
-#include "content/common/indexed_db_key.h"
-#include "content/common/serialized_script_value.h"
-#include "ipc/ipc_message_macros.h"
+#include "content/utility/utility_thread.h"
#include "printing/backend/print_backend.h"
#include "printing/page_range.h"
#include "third_party/skia/include/core/SkBitmap.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKey.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptValue.h"
+#include "ui/base/ui_base_switches.h"
#include "ui/gfx/rect.h"
-#include "webkit/glue/idb_bindings.h"
#include "webkit/glue/image_decoder.h"
#if defined(OS_WIN)
#include "app/win/iat_patch_function.h"
+#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/win/scoped_handle.h"
+#include "content/common/content_switches.h"
+#include "content/common/sandbox_init_wrapper.h"
#include "printing/emf_win.h"
-#endif
+#endif // defined(OS_WIN)
-namespace {
+namespace chrome {
-template<typename SRC, typename DEST>
-void ConvertVector(const SRC& src, DEST* dest) {
- dest->reserve(src.size());
- for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i)
- dest->push_back(typename DEST::value_type(*i));
+ChromeContentUtilityClient::ChromeContentUtilityClient() {
}
-} // namespace
-
-
-UtilityThread::UtilityThread()
- : batch_mode_(false) {
- ChildProcess::current()->AddRefProcess();
+ChromeContentUtilityClient::~ChromeContentUtilityClient() {
}
-UtilityThread::~UtilityThread() {
+void ChromeContentUtilityClient::UtilityThreadStarted() {
+#if defined(OS_WIN)
+ // Load the pdf plugin before the sandbox is turned on. This is for Windows
+ // only because we need this DLL only on Windows.
+ FilePath pdf;
+ if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) &&
+ file_util::PathExists(pdf)) {
+ bool rv = !!LoadLibrary(pdf.value().c_str());
+ DCHECK(rv) << "Couldn't load PDF plugin";
+ }
+#endif
+
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ std::string lang = command_line->GetSwitchValueASCII(switches::kLang);
+ if (!lang.empty())
+ extension_l10n_util::SetProcessLocale(lang);
}
-bool UtilityThread::OnControlMessageReceived(const IPC::Message& msg) {
+bool ChromeContentUtilityClient::OnMessageReceived(
+ const IPC::Message& message) {
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(UtilityThread, msg)
+ IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message)
IPC_MESSAGE_HANDLER(UtilityMsg_UnpackExtension, OnUnpackExtension)
IPC_MESSAGE_HANDLER(UtilityMsg_UnpackWebResource, OnUnpackWebResource)
IPC_MESSAGE_HANDLER(UtilityMsg_ParseUpdateManifest, OnParseUpdateManifest)
@@ -70,13 +69,7 @@ bool UtilityThread::OnControlMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(UtilityMsg_DecodeImageBase64, OnDecodeImageBase64)
IPC_MESSAGE_HANDLER(UtilityMsg_RenderPDFPagesToMetafile,
OnRenderPDFPagesToMetafile)
- IPC_MESSAGE_HANDLER(UtilityMsg_IDBKeysFromValuesAndKeyPath,
- OnIDBKeysFromValuesAndKeyPath)
- IPC_MESSAGE_HANDLER(UtilityMsg_InjectIDBKey,
- OnInjectIDBKey)
IPC_MESSAGE_HANDLER(UtilityMsg_ParseJSON, OnParseJSON)
- IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted)
- IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished)
IPC_MESSAGE_HANDLER(UtilityMsg_GetPrinterCapsAndDefaults,
OnGetPrinterCapsAndDefaults)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -84,20 +77,26 @@ bool UtilityThread::OnControlMessageReceived(const IPC::Message& msg) {
return handled;
}
-void UtilityThread::OnUnpackExtension(const FilePath& extension_path) {
+bool ChromeContentUtilityClient::Send(IPC::Message* message) {
+ return UtilityThread::current()->Send(message);
+}
+
+void ChromeContentUtilityClient::OnUnpackExtension(
+ const FilePath& extension_path) {
ExtensionUnpacker unpacker(extension_path);
if (unpacker.Run() && unpacker.DumpImagesToFile() &&
unpacker.DumpMessageCatalogsToFile()) {
Send(new UtilityHostMsg_UnpackExtension_Succeeded(
- *unpacker.parsed_manifest()));
+ *unpacker.parsed_manifest()));
} else {
Send(new UtilityHostMsg_UnpackExtension_Failed(unpacker.error_message()));
}
- ReleaseProcessIfNeeded();
+ UtilityThread::current()->ReleaseProcessIfNeeded();
}
-void UtilityThread::OnUnpackWebResource(const std::string& resource_data) {
+void ChromeContentUtilityClient::OnUnpackWebResource(
+ const std::string& resource_data) {
// Parse json data.
// TODO(mrc): Add the possibility of a template that controls parsing, and
// the ability to download and verify images.
@@ -110,20 +109,20 @@ void UtilityThread::OnUnpackWebResource(const std::string& resource_data) {
unpacker.error_message()));
}
- ReleaseProcessIfNeeded();
+ UtilityThread::current()->ReleaseProcessIfNeeded();
}
-void UtilityThread::OnParseUpdateManifest(const std::string& xml) {
+void ChromeContentUtilityClient::OnParseUpdateManifest(const std::string& xml) {
UpdateManifest manifest;
if (!manifest.Parse(xml)) {
Send(new UtilityHostMsg_ParseUpdateManifest_Failed(manifest.errors()));
} else {
Send(new UtilityHostMsg_ParseUpdateManifest_Succeeded(manifest.results()));
}
- ReleaseProcessIfNeeded();
+ UtilityThread::current()->ReleaseProcessIfNeeded();
}
-void UtilityThread::OnDecodeImage(
+void ChromeContentUtilityClient::OnDecodeImage(
const std::vector<unsigned char>& encoded_data) {
webkit_glue::ImageDecoder decoder;
const SkBitmap& decoded_image = decoder.Decode(&encoded_data[0],
@@ -133,10 +132,10 @@ void UtilityThread::OnDecodeImage(
} else {
Send(new UtilityHostMsg_DecodeImage_Succeeded(decoded_image));
}
- ReleaseProcessIfNeeded();
+ UtilityThread::current()->ReleaseProcessIfNeeded();
}
-void UtilityThread::OnDecodeImageBase64(
+void ChromeContentUtilityClient::OnDecodeImageBase64(
const std::string& encoded_string) {
std::string decoded_string;
@@ -153,7 +152,7 @@ void UtilityThread::OnDecodeImageBase64(
OnDecodeImage(decoded_vector);
}
-void UtilityThread::OnRenderPDFPagesToMetafile(
+void ChromeContentUtilityClient::OnRenderPDFPagesToMetafile(
base::PlatformFile pdf_file,
const FilePath& metafile_path,
const gfx::Rect& render_area,
@@ -176,7 +175,7 @@ void UtilityThread::OnRenderPDFPagesToMetafile(
if (!succeeded) {
Send(new UtilityHostMsg_RenderPDFPagesToMetafile_Failed());
}
- ReleaseProcessIfNeeded();
+ UtilityThread::current()->ReleaseProcessIfNeeded();
}
#if defined(OS_WIN)
@@ -226,7 +225,7 @@ DWORD WINAPI UtilityProcess_GetFontDataPatch(
return rv;
}
-bool UtilityThread::RenderPDFToWinMetafile(
+bool ChromeContentUtilityClient::RenderPDFToWinMetafile(
base::PlatformFile pdf_file,
const FilePath& metafile_path,
const gfx::Rect& render_area,
@@ -317,35 +316,8 @@ bool UtilityThread::RenderPDFToWinMetafile(
}
#endif // defined(OS_WIN)
-void UtilityThread::OnIDBKeysFromValuesAndKeyPath(
- int id,
- const std::vector<SerializedScriptValue>& serialized_script_values,
- const string16& idb_key_path) {
- std::vector<WebKit::WebSerializedScriptValue> web_values;
- ConvertVector(serialized_script_values, &web_values);
- std::vector<WebKit::WebIDBKey> web_keys;
- bool error = webkit_glue::IDBKeysFromValuesAndKeyPath(
- web_values, idb_key_path, &web_keys);
- if (error) {
- Send(new UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Failed(id));
- return;
- }
- std::vector<IndexedDBKey> keys;
- ConvertVector(web_keys, &keys);
- Send(new UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Succeeded(id, keys));
- ReleaseProcessIfNeeded();
-}
-
-void UtilityThread::OnInjectIDBKey(const IndexedDBKey& key,
- const SerializedScriptValue& value,
- const string16& key_path) {
- SerializedScriptValue new_value(webkit_glue::InjectIDBKey(key, value,
- key_path));
- Send(new UtilityHostMsg_InjectIDBKey_Finished(new_value));
- ReleaseProcessIfNeeded();
-}
-void UtilityThread::OnParseJSON(const std::string& json) {
+void ChromeContentUtilityClient::OnParseJSON(const std::string& json) {
int error_code;
std::string error;
Value* value =
@@ -357,18 +329,10 @@ void UtilityThread::OnParseJSON(const std::string& json) {
} else {
Send(new UtilityHostMsg_ParseJSON_Failed(error));
}
- ReleaseProcessIfNeeded();
+ UtilityThread::current()->ReleaseProcessIfNeeded();
}
-void UtilityThread::OnBatchModeStarted() {
- batch_mode_ = true;
-}
-
-void UtilityThread::OnBatchModeFinished() {
- ChildProcess::current()->ReleaseProcess();
-}
-
-void UtilityThread::OnGetPrinterCapsAndDefaults(
+void ChromeContentUtilityClient::OnGetPrinterCapsAndDefaults(
const std::string& printer_name) {
scoped_refptr<printing::PrintBackend> print_backend =
printing::PrintBackend::CreateInstance(NULL);
@@ -379,10 +343,7 @@ void UtilityThread::OnGetPrinterCapsAndDefaults(
} else {
Send(new UtilityHostMsg_GetPrinterCapsAndDefaults_Failed(printer_name));
}
- ReleaseProcessIfNeeded();
+ UtilityThread::current()->ReleaseProcessIfNeeded();
}
-void UtilityThread::ReleaseProcessIfNeeded() {
- if (!batch_mode_)
- ChildProcess::current()->ReleaseProcess();
-}
+} // namespace chrome
diff --git a/chrome/utility/chrome_content_utility_client.h b/chrome/utility/chrome_content_utility_client.h
new file mode 100644
index 0000000..47d6158
--- /dev/null
+++ b/chrome/utility/chrome_content_utility_client.h
@@ -0,0 +1,67 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_UTILITY_CHROME_CONTENT_UTILITY_CLIENT_H_
+#define CHROME_UTILITY_CHROME_CONTENT_UTILITY_CLIENT_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/platform_file.h"
+#include "content/utility/content_utility_client.h"
+
+class FilePath;
+
+namespace gfx {
+class Rect;
+}
+
+namespace printing {
+struct PageRange;
+}
+
+namespace chrome {
+
+class ChromeContentUtilityClient : public content::ContentUtilityClient {
+ public:
+ ChromeContentUtilityClient();
+ ~ChromeContentUtilityClient();
+
+ virtual void UtilityThreadStarted() OVERRIDE;
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ private:
+ virtual bool Send(IPC::Message* message);
+
+ // IPC message handlers.
+ void OnUnpackExtension(const FilePath& extension_path);
+ void OnUnpackWebResource(const std::string& resource_data);
+ void OnParseUpdateManifest(const std::string& xml);
+ void OnDecodeImage(const std::vector<unsigned char>& encoded_data);
+ void OnDecodeImageBase64(const std::string& encoded_data);
+ void OnRenderPDFPagesToMetafile(
+ base::PlatformFile pdf_file,
+ const FilePath& metafile_path,
+ const gfx::Rect& render_area,
+ int render_dpi,
+ const std::vector<printing::PageRange>& page_ranges);
+ void OnParseJSON(const std::string& json);
+
+#if defined(OS_WIN)
+ // Helper method for Windows.
+ // |highest_rendered_page_number| is set to -1 on failure to render any page.
+ bool RenderPDFToWinMetafile(
+ base::PlatformFile pdf_file,
+ const FilePath& metafile_path,
+ const gfx::Rect& render_area,
+ int render_dpi,
+ const std::vector<printing::PageRange>& page_ranges,
+ int* highest_rendered_page_number);
+#endif // defined(OS_WIN)
+
+ void OnGetPrinterCapsAndDefaults(const std::string& printer_name);
+};
+
+} // namespace chrome
+
+#endif // CHROME_UTILITY_CHROME_CONTENT_UTILITY_CLIENT_H_
diff --git a/chrome/utility/utility_main.cc b/chrome/utility/utility_main.cc
deleted file mode 100644
index d4647f0..0000000
--- a/chrome/utility/utility_main.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/command_line.h"
-#include "base/message_loop.h"
-#include "base/system_monitor/system_monitor.h"
-#include "base/threading/platform_thread.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/extensions/extension_l10n_util.h"
-#include "chrome/utility/utility_thread.h"
-#include "content/common/child_process.h"
-#include "content/common/hi_res_timer_manager.h"
-#include "content/common/main_function_params.h"
-#include "ui/base/ui_base_switches.h"
-
-#if defined(OS_WIN)
-#include "base/file_util.h"
-#include "base/path_service.h"
-#include "chrome/common/chrome_switches.h"
-#include "content/common/sandbox_init_wrapper.h"
-#include "sandbox/src/sandbox.h"
-#endif // defined(OS_WIN)
-
-// Mainline routine for running as the utility process.
-int UtilityMain(const MainFunctionParams& parameters) {
- // The main message loop of the utility process.
- MessageLoop main_message_loop;
- base::PlatformThread::SetName("CrUtilityMain");
-
- base::SystemMonitor system_monitor;
- HighResolutionTimerManager hi_res_timer_manager;
-
- ChildProcess utility_process;
- utility_process.set_main_thread(new UtilityThread());
-#if defined(OS_WIN)
- // Load the pdf plugin before the sandbox is turned on. This is for Windows
- // only because we need this DLL only on Windows.
- FilePath pdf;
- if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) &&
- file_util::PathExists(pdf)) {
- bool rv = !!LoadLibrary(pdf.value().c_str());
- DCHECK(rv) << "Couldn't load PDF plugin";
- }
-
- bool no_sandbox = parameters.command_line_.HasSwitch(switches::kNoSandbox);
- if (!no_sandbox) {
- sandbox::TargetServices* target_services =
- parameters.sandbox_info_.TargetServices();
- if (!target_services)
- return false;
- target_services->LowerToken();
- }
-#endif
-
- CommandLine* command_line = CommandLine::ForCurrentProcess();
- std::string lang = command_line->GetSwitchValueASCII(switches::kLang);
- if (!lang.empty())
- extension_l10n_util::SetProcessLocale(lang);
-
- MessageLoop::current()->Run();
-
- return 0;
-}
diff --git a/chrome/utility/utility_thread.h b/chrome/utility/utility_thread.h
deleted file mode 100644
index ddafaaa..0000000
--- a/chrome/utility/utility_thread.h
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_UTILITY_UTILITY_THREAD_H_
-#define CHROME_UTILITY_UTILITY_THREAD_H_
-#pragma once
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/string16.h"
-#include "base/platform_file.h"
-#include "content/common/child_thread.h"
-
-class FilePath;
-class IndexedDBKey;
-class SerializedScriptValue;
-
-namespace gfx {
-class Rect;
-}
-
-namespace IPC {
-class Message;
-}
-
-namespace printing {
-struct PageRange;
-}
-
-// This class represents the background thread where the utility task runs.
-class UtilityThread : public ChildThread {
- public:
- UtilityThread();
- virtual ~UtilityThread();
-
- // Returns the one utility thread.
- static UtilityThread* current() {
- return static_cast<UtilityThread*>(ChildThread::current());
- }
-
- private:
- // IPC messages
- virtual bool OnControlMessageReceived(const IPC::Message& msg);
- void OnUnpackExtension(const FilePath& extension_path);
-
- // IPC messages for web resource service.
- void OnUnpackWebResource(const std::string& resource_data);
-
- // IPC for parsing an extensions auto-update manifest xml file.
- void OnParseUpdateManifest(const std::string& xml);
-
- // IPC for decoding an image.
- void OnDecodeImage(const std::vector<unsigned char>& encoded_data);
-
- // IPC for decoding an image which is base64 encoded.
- void OnDecodeImageBase64(const std::string& encoded_data);
-
- // IPC to render a PDF into a platform metafile.
- void OnRenderPDFPagesToMetafile(
- base::PlatformFile pdf_file,
- const FilePath& metafile_path,
- const gfx::Rect& render_area,
- int render_dpi,
- const std::vector<printing::PageRange>& page_ranges);
-
-#if defined(OS_WIN)
- // Helper method for Windows.
- // |highest_rendered_page_number| is set to -1 on failure to render any page.
- bool RenderPDFToWinMetafile(
- base::PlatformFile pdf_file,
- const FilePath& metafile_path,
- const gfx::Rect& render_area,
- int render_dpi,
- const std::vector<printing::PageRange>& page_ranges,
- int* highest_rendered_page_number);
-#endif // defined(OS_WIN)
-
- // IPC for extracting IDBKeys from SerializedScriptValues, used by IndexedDB.
- void OnIDBKeysFromValuesAndKeyPath(
- int id,
- const std::vector<SerializedScriptValue>& serialized_script_values,
- const string16& idb_key_path);
-
- // IPC for injecting an IndexedDB key into a SerializedScriptValue.
- void OnInjectIDBKey(const IndexedDBKey& key,
- const SerializedScriptValue& value,
- const string16& key_path);
-
- // IPC for parsing a string of JSON into a Value.
- void OnParseJSON(const std::string& json);
-
- // IPC to notify we'll be running in batch mode instead of quitting after
- // any of the IPCs above, we'll only quit during OnBatchModeFinished().
- void OnBatchModeStarted();
-
- // IPC to notify batch mode has finished and we should now quit.
- void OnBatchModeFinished();
-
- // IPC to get capabilities and defaults for the specified
- // printer. Used on Windows to isolate the service process from printer driver
- // crashes by executing this in a separate process. This does not run in a
- // sandbox.
- void OnGetPrinterCapsAndDefaults(const std::string& printer_name);
-
- // Releases the process if we are not (or no longer) in batch mode.
- void ReleaseProcessIfNeeded();
-
- // True when we're running in batch mode.
- bool batch_mode_;
-
- DISALLOW_COPY_AND_ASSIGN(UtilityThread);
-};
-
-#endif // CHROME_UTILITY_UTILITY_THREAD_H_