Commit 14649ecd authored by gab@chromium.org's avatar gab@chromium.org

Refactor ProcessSingleton to allow a Desktop process to activate Metro Chrome...

Refactor ProcessSingleton to allow a Desktop process to activate Metro Chrome instead of grabbing the singleton (while making sure it simply RDVs if there already is an existing Chrome).

Use a Windows event to let the Metro process notify the Desktop process once it grabbed the singleton (no more Sleep()).

The idea is the following:

0) Any process always tries to rendez-vous before anything else.
1) A Metro process can always try to grab the singleton.
2) A Desktop process might wait if:
  a) The metro activation event exists
  b) The metro activation event doesn't exist, but ShouldActivate() returns true
    - In which case it creates the metro activation event and activates Metro Chrome (which will notify this process via the event once it grabbed the singleton; at which point this process should rendez-vous with it).

All of this is done while holding a global mutex (only releasing it while waiting and re-acquiring it before continuing when notified).

The process singleton acquiring logic has also been moved from the constructor to Create().

BUG=155585, 159869
TEST=Process singleton works as before (and better in tricky corner cases -- see http://crbug.com/159869) on Win8.

Review URL: https://chromiumcodereview.appspot.com/11099053

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171105 0039d316-1c4b-4281-b951-d872f2087c98
parent 9ae542cd
...@@ -24,16 +24,11 @@ ...@@ -24,16 +24,11 @@
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#if defined(OS_POSIX)
#include "base/file_path.h"
#endif // defined(OS_POSIX)
#if defined(OS_LINUX) || defined(OS_OPENBSD) #if defined(OS_LINUX) || defined(OS_OPENBSD)
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#endif // defined(OS_LINUX) || defined(OS_OPENBSD) #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
class CommandLine; class CommandLine;
class FilePath;
// ProcessSingleton ---------------------------------------------------------- // ProcessSingleton ----------------------------------------------------------
// //
...@@ -70,7 +65,11 @@ class ProcessSingleton : public base::NonThreadSafe { ...@@ -70,7 +65,11 @@ class ProcessSingleton : public base::NonThreadSafe {
// Notify another process, if available. Otherwise sets ourselves as the // Notify another process, if available. Otherwise sets ourselves as the
// singleton instance and stores the provided callback for notification from // singleton instance and stores the provided callback for notification from
// future processes. Returns PROCESS_NONE if we became the singleton // future processes. Returns PROCESS_NONE if we became the singleton
// instance. // instance. Callers are guaranteed to either have notified an existing
// process or have grabbed the singleton (unless the profile is locked by an
// unreachable process).
// TODO(brettw): Make the implementation of this method non-platform-specific
// by making Linux re-use the Windows implementation.
NotifyResult NotifyOtherProcessOrCreate( NotifyResult NotifyOtherProcessOrCreate(
const NotificationCallback& notification_callback); const NotificationCallback& notification_callback);
...@@ -120,13 +119,9 @@ class ProcessSingleton : public base::NonThreadSafe { ...@@ -120,13 +119,9 @@ class ProcessSingleton : public base::NonThreadSafe {
protected: protected:
// Notify another process, if available. // Notify another process, if available.
// Returns true if another process was found and notified, false if we // Returns true if another process was found and notified, false if we should
// should continue with this process. // continue with the current process.
// Windows code roughly based on Mozilla. // On Windows, Create() has to be called before this.
//
// TODO(brettw): this will not handle all cases. If two processes start up too
// close to each other, the Create() might not yet have happened for the
// first one, so this function won't find it.
NotifyResult NotifyOtherProcess(); NotifyResult NotifyOtherProcess();
#if defined(OS_LINUX) || defined(OS_OPENBSD) #if defined(OS_LINUX) || defined(OS_OPENBSD)
...@@ -167,6 +162,7 @@ class ProcessSingleton : public base::NonThreadSafe { ...@@ -167,6 +162,7 @@ class ProcessSingleton : public base::NonThreadSafe {
HWND window_; // The HWND_MESSAGE window. HWND window_; // The HWND_MESSAGE window.
bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment. bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment.
HANDLE lock_file_; HANDLE lock_file_;
FilePath user_data_dir_;
#elif defined(OS_LINUX) || defined(OS_OPENBSD) #elif defined(OS_LINUX) || defined(OS_OPENBSD)
// Return true if the given pid is one of our child processes. // Return true if the given pid is one of our child processes.
// Assumes that the current pid is the root of all pids of the current // Assumes that the current pid is the root of all pids of the current
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment