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

Unified Diff: base/win/metro.cc

Issue 10560015: Implement base::win::IsMetroProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename InMetroMode to IsMetroProcess. Cache and DCHECK in GetMetroModule. Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/win/metro.h ('k') | chrome/browser/bookmarks/bookmark_manager_extension_api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/metro.cc
diff --git a/base/win/metro.cc b/base/win/metro.cc
index 81e3bdaabbfef42e218f8011ed8d7b14deb35970..0eb8c21cb6e6203a3a2c01faba04f479c6e33149 100644
--- a/base/win/metro.cc
+++ b/base/win/metro.cc
@@ -12,7 +12,65 @@ namespace win {
const char kActivateApplication[] = "ActivateApplication";
HMODULE GetMetroModule() {
- return GetModuleHandleA("metro_driver.dll");
+ const HMODULE kNoMetroDriver = reinterpret_cast<HMODULE>(1);
Mark Mentovai 2012/06/18 15:40:22 Optional but highly recommended: I think that thi
Sigurður Ásgeirsson 2012/06/18 18:51:13 Sadly, as we discussed, VS does not implement thre
+ static HMODULE metro_module = NULL;
+
+ if (metro_module == NULL) {
+ HMODULE module = GetModuleHandleA("metro_driver.dll");
+
+ if (module == NULL) {
+ metro_module = kNoMetroDriver;
+ } else {
+ // We must be in a metro process if the metro_driver is loaded.
Mark Mentovai 2012/06/18 15:40:22 All four of your comments in this file say “we,” I
Sigurður Ásgeirsson 2012/06/18 18:51:13 Done.
+ DCHECK(IsMetroProcess());
+ metro_module = module;
+ }
+ }
+ DCHECK(metro_module != NULL);
+
+ if (metro_module == kNoMetroDriver)
+ return NULL;
+
+ return metro_module;
+}
+
+bool IsMetroProcess() {
Mark Mentovai 2012/06/18 15:40:22 I’d follow the same pattern for this function too,
Sigurður Ásgeirsson 2012/06/18 18:51:13 Same issue, sadly.
+ enum ImmersiveState {
+ kImmersiveUnknown,
+ kImmersiveTrue,
+ kImmersiveFalse
+ };
+ typedef BOOL (WINAPI* IsImmersiveProcessFunc)(HANDLE process);
+
+ // Since the immersive state of a process can never change, we look it
+ // up once and then cache it here.
+ static ImmersiveState state = kImmersiveUnknown;
+
+ if (state == kImmersiveUnknown) {
+ // We didn't look it up yet. Note that the code below here is idempotent,
+ // so it doesn't matter if it races to assignment on multiple threads.
+ HMODULE user32 = ::GetModuleHandleA("user32.dll");
+ DCHECK(user32 != NULL);
+
+ IsImmersiveProcessFunc is_immersive_process =
+ reinterpret_cast<IsImmersiveProcessFunc>(
+ ::GetProcAddress(user32, "IsImmersiveProcess"));
+
+ if (is_immersive_process != NULL) {
+ if (is_immersive_process(::GetCurrentProcess())) {
+ state = kImmersiveTrue;
+ } else {
+ state = kImmersiveFalse;
+ }
+ } else {
+ // No "IsImmersiveProcess" export on user32.dll, so we're pre-windows8
+ // and therefore not immersive.
+ state = kImmersiveFalse;
+ }
+ }
+ DCHECK_NE(kImmersiveUnknown, state);
+
+ return state == kImmersiveTrue;
}
wchar_t* LocalAllocAndCopyString(const string16& src) {
« no previous file with comments | « base/win/metro.h ('k') | chrome/browser/bookmarks/bookmark_manager_extension_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698