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

Side by Side Diff: base/win/metro.cc

Issue 10560015: Implement base::win::IsMetroProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
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 "base/win/metro.h" 5 #include "base/win/metro.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 8
9 namespace base { 9 namespace base {
10 namespace win { 10 namespace win {
11 11
12 const char kActivateApplication[] = "ActivateApplication"; 12 const char kActivateApplication[] = "ActivateApplication";
13 13
14 HMODULE GetMetroModule() { 14 HMODULE GetMetroModule() {
15 return GetModuleHandleA("metro_driver.dll"); 15 return GetModuleHandleA("metro_driver.dll");
16 } 16 }
17 17
18 bool InMetroMode() {
19 enum ImmersiveState {
20 kImmersiveUnknown,
21 kImmersiveTrue,
22 kImmersiveFalse
23 };
24 typedef BOOL (WINAPI* IsImmersiveProcessFunc)(HANDLE process);
25
26 // Since the immersive state of a process can never change, we look it
27 // up once and then cache it here.
28 static ImmersiveState state = kImmersiveUnknown;
29
30 if (state == kImmersiveUnknown) {
31 // We didn't look it up yet. Note that the code below here is idempotent,
32 // so it doesn't matter if it races to assignment on multiple threads.
33 HMODULE user32 = ::GetModuleHandleA("user32.dll");
34 DCHECK(user32 != NULL);
35
36 IsImmersiveProcessFunc is_immersive_process =
37 reinterpret_cast<IsImmersiveProcessFunc>(
38 ::GetProcAddress(user32, "IsImmersiveProcess"));
39
40 if (is_immersive_process != NULL) {
41 if (is_immersive_process(::GetCurrentProcess())) {
42 state = kImmersiveTrue;
ananta 2012/06/15 21:46:19 add a DCHECK(GetMetroModule() != NULL) ?
Sigurður Ásgeirsson 2012/06/18 13:54:15 Done.
43 } else {
44 state = kImmersiveFalse;
45 }
46 } else {
47 // No "IsImmersiveProcess" export on user32.dll, so we're pre-windows8
48 // and therefore not immersive.
49 state = kImmersiveFalse;
50 }
51 }
52 DCHECK_NE(kImmersiveUnknown, state);
53
54 return state == kImmersiveTrue;
55 }
56
18 wchar_t* LocalAllocAndCopyString(const string16& src) { 57 wchar_t* LocalAllocAndCopyString(const string16& src) {
19 size_t dest_size = (src.length() + 1) * sizeof(wchar_t); 58 size_t dest_size = (src.length() + 1) * sizeof(wchar_t);
20 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size)); 59 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size));
21 base::wcslcpy(dest, src.c_str(), dest_size); 60 base::wcslcpy(dest, src.c_str(), dest_size);
22 return dest; 61 return dest;
23 } 62 }
24 63
25 } // namespace win 64 } // namespace win
26 } // namespace base 65 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698