diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-29 00:24:52 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-29 00:24:52 +0000 |
commit | 1279d3b1a2e859b801f10cb769b35f4926818531 (patch) | |
tree | 200c78f712972fe3074932d6309b5039a8f0f595 /win8 | |
parent | 5ccac3ba006f02cb5706661d69bafea3f7a5e2d6 (diff) | |
download | chromium_src-1279d3b1a2e859b801f10cb769b35f4926818531.zip chromium_src-1279d3b1a2e859b801f10cb769b35f4926818531.tar.gz chromium_src-1279d3b1a2e859b801f10cb769b35f4926818531.tar.bz2 |
Promotes metro related functions to MetroViewerProcessHost
Since all these functions need the MetroViewerProcessHost it makes
more sense to put them here.
BUG=none
TEST=none
R=ananta@chromium.org
Review URL: https://codereview.chromium.org/294043011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273418 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'win8')
-rw-r--r-- | win8/viewer/metro_viewer_exports.h | 29 | ||||
-rw-r--r-- | win8/viewer/metro_viewer_process_host.cc | 203 | ||||
-rw-r--r-- | win8/viewer/metro_viewer_process_host.h | 115 | ||||
-rw-r--r-- | win8/win8.gyp | 5 |
4 files changed, 344 insertions, 8 deletions
diff --git a/win8/viewer/metro_viewer_exports.h b/win8/viewer/metro_viewer_exports.h new file mode 100644 index 0000000..61ff7d5 --- /dev/null +++ b/win8/viewer/metro_viewer_exports.h @@ -0,0 +1,29 @@ +// Copyright 2014 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 METRO_VIEWER_METRO_VIEWER_H_ +#define METRO_VIEWER_METRO_VIEWER_H_ + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(METRO_VIEWER_IMPLEMENTATION) +#define METRO_VIEWER_EXPORT __declspec(dllexport) +#else +#define METRO_VIEWER_EXPORT __declspec(dllimport) +#endif // defined(METRO_VIEWER_IMPLEMENTATION) + +#else // defined(WIN32) +#if defined(METRO_VIEWER_IMPLEMENTATION) +#define METRO_VIEWER_EXPORT __attribute__((visibility("default"))) +#else +#define METRO_VIEWER_EXPORT +#endif +#endif + +#else // defined(COMPONENT_BUILD) +#define METRO_VIEWER_EXPORT +#endif + +#endif // METRO_VIEWER_METRO_VIEWER_H_ diff --git a/win8/viewer/metro_viewer_process_host.cc b/win8/viewer/metro_viewer_process_host.cc index 26fe38a..70b6b35 100644 --- a/win8/viewer/metro_viewer_process_host.cc +++ b/win8/viewer/metro_viewer_process_host.cc @@ -33,8 +33,12 @@ const int kViewerProcessConnectionTimeoutSecs = 60; namespace win8 { +// static +MetroViewerProcessHost* MetroViewerProcessHost::instance_ = NULL; + MetroViewerProcessHost::InternalMessageFilter::InternalMessageFilter( - MetroViewerProcessHost* owner) : owner_(owner) { + MetroViewerProcessHost* owner) + : owner_(owner) { } void MetroViewerProcessHost::InternalMessageFilter::OnChannelConnected( @@ -44,6 +48,8 @@ void MetroViewerProcessHost::InternalMessageFilter::OnChannelConnected( MetroViewerProcessHost::MetroViewerProcessHost( base::SingleThreadTaskRunner* ipc_task_runner) { + DCHECK(!instance_); + instance_ = this; channel_.reset(new IPC::ChannelProxy( kMetroViewerIPCChannelName, @@ -53,8 +59,10 @@ MetroViewerProcessHost::MetroViewerProcessHost( } MetroViewerProcessHost::~MetroViewerProcessHost() { - if (!channel_) + if (!channel_) { + instance_ = NULL; return; + } base::ProcessId viewer_process_id = GetViewerProcessId(); channel_->Close(); @@ -73,6 +81,7 @@ MetroViewerProcessHost::~MetroViewerProcessHost() { } channel_->RemoveFilter(message_filter_); } + instance_ = NULL; } base::ProcessId MetroViewerProcessHost::GetViewerProcessId() { @@ -129,9 +138,17 @@ bool MetroViewerProcessHost::OnMessageReceived( DCHECK(CalledOnValidThread()); bool handled = true; IPC_BEGIN_MESSAGE_MAP(MetroViewerProcessHost, message) - IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetTargetSurface, OnSetTargetSurface) + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileSaveAsDone, + OnFileSaveAsDone) + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileOpenDone, + OnFileOpenDone) + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone, + OnMultiFileOpenDone) IPC_MESSAGE_HANDLER(MetroViewerHostMsg_OpenURL, OnOpenURL) IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SearchRequest, OnHandleSearchRequest) + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SelectFolderDone, + OnSelectFolderDone) + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetTargetSurface, OnSetTargetSurface) IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowSizeChanged, OnWindowSizeChanged) IPC_MESSAGE_UNHANDLED(handled = false) @@ -140,9 +157,189 @@ bool MetroViewerProcessHost::OnMessageReceived( aura::RemoteWindowTreeHostWin::Instance()->OnMessageReceived(message); } +// static +void MetroViewerProcessHost::HandleActivateDesktop( + const base::FilePath& path, + bool ash_exit) { + if (instance_) { + instance_->Send( + new MetroViewerHostMsg_ActivateDesktop(path, ash_exit)); + } +} + +// static +void MetroViewerProcessHost::HandleMetroExit() { + if (instance_) + instance_->Send(new MetroViewerHostMsg_MetroExit()); +} + +// static +void MetroViewerProcessHost::HandleOpenFile( + const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + const OpenFileCompletion& on_success, + const FileSelectionCanceled& on_failure) { + if (instance_) { + instance_->HandleOpenFileImpl(title, default_path, filter, on_success, + on_failure); + } +} + +// static +void MetroViewerProcessHost::HandleOpenMultipleFiles( + const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + const OpenMultipleFilesCompletion& on_success, + const FileSelectionCanceled& on_failure) { + if (instance_) { + instance_->HandleOpenMultipleFilesImpl(title, default_path, filter, + on_success, on_failure); + } +} + +// static +void MetroViewerProcessHost::HandleSaveFile( + const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + int filter_index, + const base::string16& default_extension, + const SaveFileCompletion& on_success, + const FileSelectionCanceled& on_failure) { + if (instance_) { + instance_->HandleSaveFileImpl(title, default_path, filter, filter_index, + default_extension, on_success, on_failure); + } +} + +// static +void MetroViewerProcessHost::HandleSelectFolder( + const base::string16& title, + const SelectFolderCompletion& on_success, + const FileSelectionCanceled& on_failure) { + if (instance_) + instance_->HandleSelectFolderImpl(title, on_success, on_failure); +} + +void MetroViewerProcessHost::HandleOpenFileImpl( + const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + const OpenFileCompletion& on_success, + const FileSelectionCanceled& on_failure) { + // Can only have one of these operations in flight. + DCHECK(file_open_completion_callback_.is_null()); + DCHECK(failure_callback_.is_null()); + + file_open_completion_callback_ = on_success; + failure_callback_ = on_failure; + + Send(new MetroViewerHostMsg_DisplayFileOpen(title, filter, default_path, + false)); +} + +void MetroViewerProcessHost::HandleOpenMultipleFilesImpl( + const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + const OpenMultipleFilesCompletion& on_success, + const FileSelectionCanceled& on_failure) { + // Can only have one of these operations in flight. + DCHECK(multi_file_open_completion_callback_.is_null()); + DCHECK(failure_callback_.is_null()); + multi_file_open_completion_callback_ = on_success; + failure_callback_ = on_failure; + + Send(new MetroViewerHostMsg_DisplayFileOpen(title, filter, default_path, + true)); +} + +void MetroViewerProcessHost::HandleSaveFileImpl( + const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + int filter_index, + const base::string16& default_extension, + const SaveFileCompletion& on_success, + const FileSelectionCanceled& on_failure) { + MetroViewerHostMsg_SaveAsDialogParams params; + params.title = title; + params.default_extension = default_extension; + params.filter = filter; + params.filter_index = filter_index; + params.suggested_name = default_path; + + // Can only have one of these operations in flight. + DCHECK(file_saveas_completion_callback_.is_null()); + DCHECK(failure_callback_.is_null()); + file_saveas_completion_callback_ = on_success; + failure_callback_ = on_failure; + + Send(new MetroViewerHostMsg_DisplayFileSaveAs(params)); +} + +void MetroViewerProcessHost::HandleSelectFolderImpl( + const base::string16& title, + const SelectFolderCompletion& on_success, + const FileSelectionCanceled& on_failure) { + // Can only have one of these operations in flight. + DCHECK(select_folder_completion_callback_.is_null()); + DCHECK(failure_callback_.is_null()); + select_folder_completion_callback_ = on_success; + failure_callback_ = on_failure; + + Send(new MetroViewerHostMsg_DisplaySelectFolder(title)); +} + void MetroViewerProcessHost::NotifyChannelConnected() { if (channel_connected_event_) channel_connected_event_->Signal(); } +void MetroViewerProcessHost::OnFileSaveAsDone(bool success, + const base::FilePath& filename, + int filter_index) { + if (success) + file_saveas_completion_callback_.Run(filename, filter_index, NULL); + else + failure_callback_.Run(NULL); + file_saveas_completion_callback_.Reset(); + failure_callback_.Reset(); +} + + +void MetroViewerProcessHost::OnFileOpenDone(bool success, + const base::FilePath& filename) { + if (success) + file_open_completion_callback_.Run(base::FilePath(filename), 0, NULL); + else + failure_callback_.Run(NULL); + file_open_completion_callback_.Reset(); + failure_callback_.Reset(); +} + +void MetroViewerProcessHost::OnMultiFileOpenDone( + bool success, + const std::vector<base::FilePath>& files) { + if (success) + multi_file_open_completion_callback_.Run(files, NULL); + else + failure_callback_.Run(NULL); + multi_file_open_completion_callback_.Reset(); + failure_callback_.Reset(); +} + +void MetroViewerProcessHost::OnSelectFolderDone( + bool success, + const base::FilePath& folder) { + if (success) + select_folder_completion_callback_.Run(base::FilePath(folder), 0, NULL); + else + failure_callback_.Run(NULL); + select_folder_completion_callback_.Reset(); + failure_callback_.Reset(); +} + } // namespace win8 diff --git a/win8/viewer/metro_viewer_process_host.h b/win8/viewer/metro_viewer_process_host.h index f2e1b45..19e9627 100644 --- a/win8/viewer/metro_viewer_process_host.h +++ b/win8/viewer/metro_viewer_process_host.h @@ -6,6 +6,7 @@ #define WIN8_VIEWER_METRO_VIEWER_PROCESS_HOST_H_ #include "base/basictypes.h" +#include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "base/threading/non_thread_safe.h" @@ -14,6 +15,7 @@ #include "ipc/ipc_sender.h" #include "ipc/message_filter.h" #include "ui/gfx/native_widget_types.h" +#include "win8/viewer/metro_viewer_exports.h" namespace base { class SingleThreadTaskRunner; @@ -28,10 +30,24 @@ class Message; namespace win8 { // Abstract base class for various Metro viewer process host implementations. -class MetroViewerProcessHost : public IPC::Listener, - public IPC::Sender, - public base::NonThreadSafe { +class METRO_VIEWER_EXPORT MetroViewerProcessHost : public IPC::Listener, + public IPC::Sender, + public base::NonThreadSafe { public: + typedef base::Callback<void(const base::FilePath&, int, void*)> + OpenFileCompletion; + + typedef base::Callback<void(const std::vector<base::FilePath>&, void*)> + OpenMultipleFilesCompletion; + + typedef base::Callback<void(const base::FilePath&, int, void*)> + SaveFileCompletion; + + typedef base::Callback<void(const base::FilePath&, int, void*)> + SelectFolderCompletion; + + typedef base::Callback<void(void*)> FileSelectionCanceled; + // Initializes a viewer process host to connect to the Metro viewer process // over IPC. The given task runner correspond to a thread on which // IPC::Channel is created and used (e.g. IO thread). Instantly connects to @@ -54,14 +70,86 @@ class MetroViewerProcessHost : public IPC::Listener, bool LaunchViewerAndWaitForConnection( const base::string16& app_user_model_id); + // Handles the activate desktop command for Metro Chrome Ash. The |ash_exit| + // parameter indicates whether the Ash process would be shutdown after + // activating the desktop. + static void HandleActivateDesktop(const base::FilePath& shortcut, + bool ash_exit); + + // Handles the metro exit command. Notifies the metro viewer to shutdown + // gracefully. + static void HandleMetroExit(); + + // Handles the open file operation for Metro Chrome Ash. The on_success + // callback passed in is invoked when we receive the opened file name from + // the metro viewer. The on failure callback is invoked on failure. + static void HandleOpenFile(const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + const OpenFileCompletion& on_success, + const FileSelectionCanceled& on_failure); + + // Handles the open multiple file operation for Metro Chrome Ash. The + // on_success callback passed in is invoked when we receive the opened file + // names from the metro viewer. The on failure callback is invoked on failure. + static void HandleOpenMultipleFiles( + const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + const OpenMultipleFilesCompletion& on_success, + const FileSelectionCanceled& on_failure); + + // Handles the save file operation for Metro Chrome Ash. The on_success + // callback passed in is invoked when we receive the saved file name from + // the metro viewer. The on failure callback is invoked on failure. + static void HandleSaveFile(const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + int filter_index, + const base::string16& default_extension, + const SaveFileCompletion& on_success, + const FileSelectionCanceled& on_failure); + + // Handles the select folder for Metro Chrome Ash. The on_success + // callback passed in is invoked when we receive the folder name from the + // metro viewer. The on failure callback is invoked on failure. + static void HandleSelectFolder(const base::string16& title, + const SelectFolderCompletion& on_success, + const FileSelectionCanceled& on_failure); + + protected: // IPC::Sender implementation: virtual bool Send(IPC::Message* msg) OVERRIDE; - private: // IPC::Listener implementation: virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual void OnChannelError() OVERRIDE = 0; + private: + // The following are the implementation for the corresponding static methods + // above, see them for descriptions. + void HandleOpenFileImpl(const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + const OpenFileCompletion& on_success, + const FileSelectionCanceled& on_failure); + void HandleOpenMultipleFilesImpl( + const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + const OpenMultipleFilesCompletion& on_success, + const FileSelectionCanceled& on_failure); + void HandleSaveFileImpl(const base::string16& title, + const base::FilePath& default_path, + const base::string16& filter, + int filter_index, + const base::string16& default_extension, + const SaveFileCompletion& on_success, + const FileSelectionCanceled& on_failure); + void HandleSelectFolderImpl(const base::string16& title, + const SelectFolderCompletion& on_success, + const FileSelectionCanceled& on_failure); + // Called over IPC by the viewer process to tell this host that it should be // drawing to |target_surface|. virtual void OnSetTargetSurface(gfx::NativeViewId target_surface, @@ -81,6 +169,15 @@ class MetroViewerProcessHost : public IPC::Listener, void NotifyChannelConnected(); + // IPC message handing methods: + void OnFileSaveAsDone(bool success, + const base::FilePath& filename, + int filter_index); + void OnFileOpenDone(bool success, const base::FilePath& filename); + void OnMultiFileOpenDone(bool success, + const std::vector<base::FilePath>& files); + void OnSelectFolderDone(bool success, const base::FilePath& folder); + // Inner message filter used to handle connection event on the IPC channel // proxy's background thread. This prevents consumers of // MetroViewerProcessHost from having to pump messages on their own message @@ -101,6 +198,16 @@ class MetroViewerProcessHost : public IPC::Listener, scoped_ptr<base::WaitableEvent> channel_connected_event_; scoped_refptr<InternalMessageFilter> message_filter_; + static MetroViewerProcessHost* instance_; + + // Saved callbacks which inform the caller about the result of the open file/ + // save file/select operations. + OpenFileCompletion file_open_completion_callback_; + OpenMultipleFilesCompletion multi_file_open_completion_callback_; + SaveFileCompletion file_saveas_completion_callback_; + SelectFolderCompletion select_folder_completion_callback_; + FileSelectionCanceled failure_callback_; + DISALLOW_COPY_AND_ASSIGN(MetroViewerProcessHost); }; diff --git a/win8/win8.gyp b/win8/win8.gyp index e4f45c2..e1fa5de 100644 --- a/win8/win8.gyp +++ b/win8/win8.gyp @@ -22,7 +22,7 @@ }, { 'target_name': 'metro_viewer', - 'type': 'static_library', + 'type': '<(component)', 'dependencies': [ '../base/base.gyp:base', '../ipc/ipc.gyp:ipc', @@ -34,6 +34,9 @@ 'viewer/metro_viewer_process_host.cc', 'viewer/metro_viewer_process_host.h', ], + 'defines': [ + 'METRO_VIEWER_IMPLEMENTATION', + ], }, { 'target_name': 'test_support_win8', |